Skip to content

Commit d28a0f8

Browse files
committed
Validate the base template
1 parent 985e163 commit d28a0f8

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

src/Console/Concerns/InteractsWithDockerComposeServices.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,21 @@ protected function buildDockerCompose(array $services)
3939
$composePath = base_path('docker-compose.yml');
4040
$appService = 'laravel.test';
4141

42-
$compose = file_exists($composePath)
43-
? Yaml::parseFile($composePath)
44-
: Yaml::parse(str_replace(
45-
'APP_SERVICE',
46-
$appService,
47-
file_get_contents(Sail::baseTemplate())
48-
));
42+
if (file_exists($composePath)) {
43+
$compose = Yaml::parseFile($composePath);
44+
} else {
45+
$template = str_replace(
46+
'{{APP}}:',
47+
$appService.':',
48+
file_get_contents(Sail::baseTemplate()),
49+
$count
50+
);
51+
if ($count === 0) {
52+
$this->error('Missing app service in the base template. Make sure you have it with the {{APP}} placeholder.');
53+
exit(1);
54+
}
55+
$compose = Yaml::parse($template);
56+
}
4957

5058
// Prepare the installation of the "mariadb-client" package if the MariaDB service is used...
5159
if (in_array('mariadb', $services)) {
@@ -166,7 +174,7 @@ protected function installDevContainer()
166174
file_put_contents(
167175
$this->laravel->basePath('.devcontainer/devcontainer.json'),
168176
str_replace(
169-
'APP_SERVICE',
177+
'{{APP}}',
170178
'laravel.test',
171179
file_get_contents(__DIR__.'/../../../stubs/devcontainer.stub') ?: ''
172180
)

src/Services.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function __construct()
174174
}
175175

176176
/**
177-
* Set the base Docker Compose template containing a php service named as 'APP_SERVICE'
177+
* Set the base Docker Compose template containing a php service named as '{{APP}}'
178178
*
179179
* @param string $stub Path to the base Docker Compose stub
180180
* @return $this
@@ -324,7 +324,7 @@ public function isPersistent(string $service): bool
324324
}
325325

326326
/**
327-
* Check if a service is required by APP_SERVICE
327+
* Check if a service is required by {{APP}} service
328328
*
329329
* @param string $service
330330
* @return bool

stubs/devcontainer.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"dockerComposeFile": [
55
"../docker-compose.yml"
66
],
7-
"service": "APP_SERVICE",
7+
"service": "{{APP}}",
88
"workspaceFolder": "/var/www/html",
99
"customizations": {
1010
"vscode": {

stubs/docker-compose.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# For more information: https://laravel.com/docs/sail
22
services:
3-
APP_SERVICE:
3+
{{APP}}:
44
build:
55
context: ./vendor/laravel/sail/runtimes/{{PHP_VERSION}}
66
dockerfile: Dockerfile

0 commit comments

Comments
 (0)