From ba5119f913e58db2a555444e8a1a7851bc757c5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Thu, 11 Jan 2024 17:51:27 +0100 Subject: [PATCH] Fix compatibility layer with castor v0.11.0 --- .castor/infra.php | 6 +++--- .castor/utils.php | 16 ++++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.castor/infra.php b/.castor/infra.php index 5580cf1..0f8196a 100644 --- a/.castor/infra.php +++ b/.castor/infra.php @@ -10,7 +10,7 @@ use function Castor\capture; use function Castor\finder; use function Castor\fs; -use function Castor\get_context; +use function Castor\context; use function Castor\io; use function Castor\run; use function Castor\variable; @@ -53,7 +53,7 @@ function stop(): void #[AsTask(description: 'Opens a shell (bash) into a builder container', aliases: ['builder'])] function builder(): void { - $c = get_context() + $c = context() ->withTimeout(null) ->withTty() ->withEnvironment($_ENV + $_SERVER) @@ -66,7 +66,7 @@ function builder(): void #[AsTask(description: 'Displays infrastructure logs', aliases: ['logs'])] function logs(): void { - docker_compose(['logs', '-f', '--tail', '150'], c: get_context()->withTty()); + docker_compose(['logs', '-f', '--tail', '150'], c: context()->withTty()); } #[AsTask(description: 'Lists containers status', aliases: ['ps'])] diff --git a/.castor/utils.php b/.castor/utils.php index b5b4005..2343e20 100644 --- a/.castor/utils.php +++ b/.castor/utils.php @@ -7,7 +7,7 @@ use function Castor\cache; use function Castor\capture; -use function Castor\get_context; +use function Castor\context; use function Castor\io; use function Castor\log; use function Castor\run; @@ -70,8 +70,12 @@ function create_default_context(): Context $data['docker_compose_files'][] = 'docker-compose.override.yml'; } - $data['composer_cache_dir'] = cache('composer_cache_dir', function () { - $composerCacheDir = capture(['composer', 'global', 'config', 'cache-dir', '-q'], onFailure: ''); + // We need an empty context to run command, since the default context has + // not been set in castor, since we ARE creating it right now + $emptyContext = new Context(); + + $data['composer_cache_dir'] = cache('composer_cache_dir', function () use ($emptyContext): string { + $composerCacheDir = capture(['composer', 'global', 'config', 'cache-dir', '-q'], onFailure: '', context: $emptyContext); // If PHP is broken, the output will not be a valid path but an error message if (!is_dir($composerCacheDir)) { $composerCacheDir = sys_get_temp_dir() . '/castor/composer'; @@ -109,7 +113,7 @@ function docker_exit_code( string $workDir = null, bool $withBuilder = true, ): int { - $c = ($c ?? get_context())->withAllowFailure(); + $c = ($c ?? context())->withAllowFailure(); $process = docker_compose_run( runCommand: $runCommand, @@ -163,7 +167,7 @@ function docker_compose_run( */ function docker_compose(array $subCommand, Context $c = null, bool $withBuilder = false): Process { - $c ??= get_context(); + $c ??= context(); $domains = [variable('root_domain'), ...variable('extra_domains')]; $domains = '`' . implode('`) || Host(`', $domains) . '`'; @@ -204,7 +208,7 @@ function docker_compose(array $subCommand, Context $c = null, bool $withBuilder // so this func allow them to run these tools on their host function run_in_docker_or_locally_for_mac(string $command, Context $c = null): void { - $c ??= get_context(); + $c ??= context(); if (variable('macos')) { run($command, context: $c->withPath(variable('root_dir')));