Skip to content

Commit 3543d95

Browse files
driesvintsvidelalvarotaylorotwell
authored
[1.x] Add devcontainer to install command (#218)
* adds devcontainer to install command (#203) * adds devcontainer to install command * formatting Co-authored-by: Taylor Otwell <[email protected]> * add env options Co-authored-by: Alvaro Videla <[email protected]> Co-authored-by: Taylor Otwell <[email protected]>
1 parent 3e1aa86 commit 3543d95

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/Console/InstallCommand.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class InstallCommand extends Command
1111
*
1212
* @var string
1313
*/
14-
protected $signature = 'sail:install {--with= : The services that should be included in the installation}';
14+
protected $signature = 'sail:install
15+
{--with= : The services that should be included in the installation}
16+
{--devcontainer : Create a .devcontainer configuration directory}';
1517

1618
/**
1719
* The console command description.
@@ -38,6 +40,10 @@ public function handle()
3840
$this->buildDockerCompose($services);
3941
$this->replaceEnvVariables($services);
4042

43+
if ($this->option('devcontainer')) {
44+
$this->installDevContainer();
45+
}
46+
4147
$this->info('Sail scaffolding installed successfully.');
4248
}
4349

@@ -136,4 +142,28 @@ protected function replaceEnvVariables(array $services)
136142

137143
file_put_contents($this->laravel->basePath('.env'), $environment);
138144
}
145+
146+
/**
147+
* Install the devcontainer.json configuration file.
148+
*
149+
* @return void
150+
*/
151+
protected function installDevContainer()
152+
{
153+
if (! is_dir($this->laravel->basePath('.devcontainer'))) {
154+
mkdir($this->laravel->basePath('.devcontainer'), 0755, true);
155+
}
156+
157+
file_put_contents(
158+
$this->laravel->basePath('.devcontainer/devcontainer.json'),
159+
file_get_contents(__DIR__.'/../../stubs/devcontainer.stub')
160+
);
161+
162+
$environment = file_get_contents($this->laravel->basePath('.env'));
163+
164+
$environment .= "\nWWWGROUP=1000";
165+
$environment .= "\nWWWUSER=1000\n";
166+
167+
file_put_contents($this->laravel->basePath('.env'), $environment);
168+
}
139169
}

stubs/devcontainer.stub

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// https://aka.ms/devcontainer.json
2+
{
3+
"name": "Existing Docker Compose (Extend)",
4+
"dockerComposeFile": [
5+
"../docker-compose.yml"
6+
],
7+
"service": "laravel.test",
8+
"workspaceFolder": "/var/www/html",
9+
"settings": {},
10+
"extensions": [
11+
// "mikestead.dotenv",
12+
// "amiralizadeh9480.laravel-extra-intellisense",
13+
// "ryannaddy.laravel-artisan",
14+
// "onecentlin.laravel5-snippets",
15+
// "onecentlin.laravel-blade"
16+
],
17+
"remoteUser": "sail",
18+
// "forwardPorts": [],
19+
// "runServices": [],
20+
// "postCreateCommand": "apt-get update && apt-get install -y curl",
21+
// "shutdownAction": "none",
22+
}

0 commit comments

Comments
 (0)