-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement interactive choice and Meilisearch
- Loading branch information
1 parent
3b27da8
commit ef2b3f9
Showing
12 changed files
with
250 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
namespace Laravel\Sail\Console; | ||
|
||
use Illuminate\Console\Command; | ||
|
||
class InstallCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'sail:install'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Install Laravel Sail\'s default Docker Compose file'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
$services = $this->choice('Which services would you like to install?', [ | ||
'mysql', | ||
'pgsql', | ||
'redis', | ||
'selenium', | ||
'mailhog', | ||
'meilisearch', | ||
], 0, null, true); | ||
|
||
$this->buildDockerCompose($services); | ||
$this->replaceEnvVariables($services); | ||
|
||
$this->info('Sail scaffolding installed successfully.'); | ||
} | ||
|
||
/** | ||
* Build the Docker Compose file. | ||
* | ||
* @param array $services | ||
* @return void | ||
*/ | ||
protected function buildDockerCompose(array $services) | ||
{ | ||
$depends = collect($services) | ||
->filter(function ($service) { | ||
return in_array($service, ['mysql', 'pgsql', 'redis', 'selenium']); | ||
})->map(function ($service) { | ||
return " - {$service}"; | ||
})->whenNotEmpty(function ($collection) { | ||
return $collection->prepend('depends_on:'); | ||
})->implode("\n"); | ||
|
||
$stubs = rtrim(collect($services)->map(function ($service) { | ||
return file_get_contents(__DIR__ . "/../../stubs/{$service}.stub"); | ||
})->implode('')); | ||
|
||
$volumes = collect($services) | ||
->filter(function ($service) { | ||
return in_array($service, ['mysql', 'pgsql', 'redis', 'meilisearch']); | ||
})->map(function ($service) { | ||
return " sail{$service}:\n driver: local"; | ||
})->whenNotEmpty(function ($collection) { | ||
return $collection->prepend('volumes:'); | ||
})->implode("\n"); | ||
|
||
$dockerCompose = file_get_contents(__DIR__ . '/../../stubs/docker-compose.stub'); | ||
|
||
$dockerCompose = str_replace('{{depends}}', $depends, $dockerCompose); | ||
$dockerCompose = str_replace('{{services}}', $stubs, $dockerCompose); | ||
$dockerCompose = str_replace('{{volumes}}', $volumes, $dockerCompose); | ||
|
||
file_put_contents($this->laravel->basePath('docker-compose.yml'), $dockerCompose); | ||
} | ||
|
||
/** | ||
* Replace the Host environment variables in the app's .env file. | ||
* | ||
* @param array $services | ||
* @return void | ||
*/ | ||
protected function replaceEnvVariables(array $services) | ||
{ | ||
$environment = file_get_contents($this->laravel->basePath('.env')); | ||
|
||
$host = in_array('pgsql', $services) ? 'pgsql' : 'mysql'; | ||
|
||
$environment = str_replace('DB_HOST=127.0.0.1', "DB_HOST=$host", $environment); | ||
$environment = str_replace('MEMCACHED_HOST=127.0.0.1', 'MEMCACHED_HOST=memcached', $environment); | ||
$environment = str_replace('REDIS_HOST=127.0.0.1', 'REDIS_HOST=redis', $environment); | ||
|
||
if (in_array('meilisearch', $services)) { | ||
$environment .= "\nSCOUT_DRIVER=meilisearch"; | ||
$environment .= "\nMEILISEARCH_HOST=http://meilisearch:7700\n"; | ||
} | ||
|
||
file_put_contents($this->laravel->basePath('.env'), $environment); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Laravel\Sail\Console; | ||
|
||
use Illuminate\Console\Command; | ||
|
||
class PublishCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'sail:publish'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Publish the Laravel Sail Docker files'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
$this->call('vendor:publish', ['--tag' => 'sail']); | ||
|
||
file_put_contents($this->laravel->basePath('docker-compose.yml'), str_replace( | ||
'./vendor/laravel/sail/runtimes/8.0', | ||
'./docker/8.0', | ||
file_get_contents($this->laravel->basePath('docker-compose.yml')) | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# For more information: https://laravel.com/docs/sail | ||
version: '3' | ||
services: | ||
laravel.test: | ||
build: | ||
context: ./vendor/laravel/sail/runtimes/8.0 | ||
dockerfile: Dockerfile | ||
args: | ||
WWWGROUP: '${WWWGROUP}' | ||
image: sail-8.0/app | ||
ports: | ||
- '${APP_PORT:-80}:80' | ||
environment: | ||
WWWUSER: '${WWWUSER}' | ||
LARAVEL_SAIL: 1 | ||
volumes: | ||
- '.:/var/www/html' | ||
networks: | ||
- sail | ||
{{depends}} | ||
{{services}} | ||
networks: | ||
sail: | ||
driver: bridge | ||
{{volumes}} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
mailhog: | ||
image: 'mailhog/mailhog:latest' | ||
ports: | ||
- '${FORWARD_MAILHOG_PORT:-1025}:1025' | ||
- '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025' | ||
networks: | ||
- sail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
meilisearch: | ||
image: 'getmeili/meilisearch:latest' | ||
ports: | ||
- '${FORWARD_MEILISEARCH_PORT:-7700}:7700' | ||
volumes: | ||
- 'sailmeilisearch:/data.ms' | ||
networks: | ||
- sail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
mysql: | ||
image: 'mysql:8.0' | ||
ports: | ||
- '${FORWARD_DB_PORT:-3306}:3306' | ||
environment: | ||
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}' | ||
MYSQL_DATABASE: '${DB_DATABASE}' | ||
MYSQL_USER: '${DB_USERNAME}' | ||
MYSQL_PASSWORD: '${DB_PASSWORD}' | ||
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' | ||
volumes: | ||
- 'sailmysql:/var/lib/mysql' | ||
networks: | ||
- sail | ||
healthcheck: | ||
test: ["CMD", "mysqladmin", "ping"] |
Oops, something went wrong.