Skip to content

Commit

Permalink
adds devcontainer to install command (#203)
Browse files Browse the repository at this point in the history
* adds devcontainer to install command

* formatting

Co-authored-by: Taylor Otwell <taylorotwell@gmail.com>
  • Loading branch information
videlalvaro and taylorotwell authored Jul 29, 2021
1 parent 6bee7a3 commit 30896b5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class InstallCommand extends Command
*
* @var string
*/
protected $signature = 'sail:install {--with= : The services that should be included in the installation}';
protected $signature = 'sail:install
{--with= : The services that should be included in the installation}
{--devcontainer : Create a .devcontainer configuration directory}';

/**
* The console command description.
Expand All @@ -38,6 +40,10 @@ public function handle()
$this->buildDockerCompose($services);
$this->replaceEnvVariables($services);

if ($this->option('devcontainer')) {
$this->installDevContainer();
}

$this->info('Sail scaffolding installed successfully.');
}

Expand Down Expand Up @@ -136,4 +142,21 @@ protected function replaceEnvVariables(array $services)

file_put_contents($this->laravel->basePath('.env'), $environment);
}

/**
* Install the devcontainer.json configuration file.
*
* @return void
*/
protected function installDevContainer()
{
if (! is_dir($this->laravel->basePath('.devcontainer'))) {
mkdir($this->laravel->basePath('.devcontainer'), 0755, true);
}

file_put_contents(
$this->laravel->basePath('.devcontainer/devcontainer.json'),
file_get_contents(__DIR__.'/../../stubs/devcontainer.stub')
);
}
}
22 changes: 22 additions & 0 deletions stubs/devcontainer.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// https://aka.ms/devcontainer.json
{
"name": "Existing Docker Compose (Extend)",
"dockerComposeFile": [
"../docker-compose.yml"
],
"service": "laravel.test",
"workspaceFolder": "/var/www/html",
"settings": {},
"extensions": [
// "mikestead.dotenv",
// "amiralizadeh9480.laravel-extra-intellisense",
// "ryannaddy.laravel-artisan",
// "onecentlin.laravel5-snippets",
// "onecentlin.laravel-blade"
],
"remoteUser": "sail",
// "forwardPorts": [],
// "runServices": [],
// "postCreateCommand": "apt-get update && apt-get install -y curl",
// "shutdownAction": "none",
}

0 comments on commit 30896b5

Please sign in to comment.