Something went wrong. Try again.
Something went wrong. Try again.
symfony-docker castor.php
5.2 kB · 163 lines
PHP
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164<?php
use Castor\Attribute\AsTask;use Symfony\Component\Process\ExecutableFinder;
use function Castor\context;use function Castor\guard_min_version;use function Castor\import;use function Castor\io;use function Castor\notify;use function Castor\open;use function Castor\run;use function Castor\variable;use function docker\about;use function docker\build;use function docker\docker_compose_run;use function docker\up;
// use function docker\workers_start;// use function docker\workers_stop;
guard_min_version('1.5.0');
import(__DIR__ . '/.castor');
/** * @return array{project_name: string, root_domain: string, extra_domains: string[], php_version: string, registry: ?string} */function create_default_variables(): array{ $projectName = 'app'; $tld = 'test';
return [ 'project_name' => $projectName, 'root_domain' => "{$projectName}.{$tld}", 'extra_domains' => [ "www.{$projectName}.{$tld}", ], 'php_version' => '8.5', 'registry' => null, ];}
#[AsTask(description: 'Builds and starts the infrastructure, then install the application (composer, yarn, ...)')]function start(): void{ io()->title('Starting the stack');
// devenv writes /etc/hosts and the router certificates; see devenv.nix. // Both ask for sudo, which needs the real terminal: behind Castor's usual // pseudo-terminal the password would echo back as it is typed, and behind // devenv's own interface the prompt would not show at all. Without one - // CI has neither devenv nor a terminal - the router falls back to the // self-signed certificate that build() generates. if (null !== new ExecutableFinder()->find('devenv') && stream_isatty(STDOUT)) { run( ['devenv', '--no-tui', 'tasks', 'run', 'devenv:hostctl:setup', 'devenv:mkcert:setup'], context: context()->withTty(), ); }
// workers_stop(); build(); install(); up(profiles: ['default']); // We can't start worker now, they are not installed migrate(); // workers_start();
notify('The stack is now up and running.'); io()->success('The stack is now up and running.');
about();}
#[AsTask(description: 'Opens Grafana in your browser', namespace: '', aliases: ['grafana'])]function grafana(): void{ open(sprintf('https://grafana.%s', variable('root_domain')));}
#[AsTask(description: 'Installs the application (composer, yarn, ...)', namespace: 'app', aliases: ['install'])]function install(): void{ io()->title('Installing the application');
$basePath = sprintf('%s/application', variable('root_dir'));
if (is_file("{$basePath}/composer.json")) { io()->section('Installing PHP dependencies'); docker_compose_run(['composer', 'install', '-n', '--prefer-dist', '--optimize-autoloader']); } if (is_file("{$basePath}/yarn.lock")) { io()->section('Installing Node.js dependencies'); docker_compose_run(['yarn', 'install', '--immutable']); } elseif (is_file("{$basePath}/package.json")) { io()->section('Installing Node.js dependencies');
if (is_file("{$basePath}/package-lock.json")) { docker_compose_run(['npm', 'ci']); } else { docker_compose_run(['npm', 'install']); } } if (is_file("{$basePath}/importmap.php")) { io()->section('Installing importmap'); docker_compose_run(['bin/console', 'importmap:install']); }
qa\install();}
#[AsTask(description: 'Update dependencies')]function update(bool $withTools = false): void{ io()->title('Updating dependencies...');
// docker_compose_run(['composer', 'update', '-o']);
if ($withTools) { qa\update(); }}
#[AsTask(description: 'Clears the application cache', namespace: 'app', aliases: ['cache-clear'])]function cache_clear(bool $warm = true): void{ // io()->title('Clearing the application cache');
// docker_compose_run(['rm', '-rf', 'var/cache/']);
// if ($warm) { // cache_warmup(); // }}
#[AsTask(description: 'Warms the application cache', namespace: 'app', aliases: ['cache-warmup'])]function cache_warmup(): void{ // io()->title('Warming the application cache');
// docker_compose_run(['bin/console', 'cache:warmup'], c: context()->withAllowFailure());}
#[AsTask(description: 'Migrates database schema', namespace: 'app:db', aliases: ['migrate'])]function migrate(): void{ // io()->title('Migrating the database schema');
// docker_compose_run(['bin/console', 'doctrine:database:create', '--if-not-exists']); // docker_compose_run(['bin/console', 'doctrine:migration:migrate', '-n', '--allow-no-migration', '--all-or-nothing']);}
#[AsTask(description: 'Loads fixtures', namespace: 'app:db', aliases: ['fixtures'])]function fixtures(): void{ // io()->title('Loads fixtures');
// Uncomment one of them... // docker_compose_run(['bin/console', 'doctrine:fixture:load', '-n']); // docker_compose_run(['bin/console', 'foundry:load-fixtures', '-n']); // docker_compose_run(['bin/console', 'sylius:fixture:load', '-n']);}