diff --git a/.castor/context.php b/.castor/context.php index 22ae5dc7..eb4ab730 100644 --- a/.castor/context.php +++ b/.castor/context.php @@ -64,10 +64,8 @@ function create_test_context(): Context $c = create_default_context(); return $c - ->withData([ - 'docker_compose_run_environment' => [ - 'APP_ENV' => 'test', - ], + ->withEnvironment([ + 'APP_ENV' => 'test', ]) ; } @@ -78,10 +76,8 @@ function create_ci_context(): Context $c = create_test_context(); return $c - ->withData([ - // override the default context here - ]) ->withData( + // override the default context here [ 'docker_compose_files' => [ 'docker-compose.yml', diff --git a/.castor/docker.php b/.castor/docker.php index 7a5f9753..b1d940c0 100644 --- a/.castor/docker.php +++ b/.castor/docker.php @@ -158,7 +158,7 @@ function stop( * @param array $params */ #[AsTask(description: 'Opens a shell (bash) or proxy any command to the builder container', aliases: ['builder'])] -function builder(#[AsRawTokens] array $params = []): void +function builder(#[AsRawTokens] array $params = []): int { if (0 === \count($params)) { $params = ['bash']; @@ -168,7 +168,8 @@ function builder(#[AsRawTokens] array $params = []): void ->toInteractive() ->withEnvironment($_ENV + $_SERVER) ; - docker_compose_run(implode(' ', $params), c: $c); + + return (int) docker_compose_run(implode(' ', $params), c: $c)->getExitCode(); } /** @@ -388,6 +389,12 @@ function docker_compose(array $subCommand, ?Context $c = null, array $profiles = 'REGISTRY' => $c['registry'] ?? '', ]); + if ($c['APP_ENV'] ?? false) { + $c = $c->withEnvironment([ + 'APP_ENV' => $c['APP_ENV'] ?? '', + ]); + } + $command = [ 'docker', 'compose', diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 206eba97..fce49daa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,9 +83,17 @@ jobs: { docker_compose_run('echo "Hello World"'); } + + #[AsTask()] + function app_env() + { + docker_compose_run('php public/index.php'); + } EOPHP castor test | grep "Hello World" + CASTOR_CONTEXT=default castor app-env | grep 'Environment: not set'" + CASTOR_CONTEXT=test castor app-env | grep 'Environment: test'" - name: "Test communication with DB" run: | diff --git a/application/public/index.php b/application/public/index.php index 3e184019..a881ce1c 100644 --- a/application/public/index.php +++ b/application/public/index.php @@ -1,3 +1,5 @@