Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions .castor/context.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
])
;
}
Expand All @@ -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',
Expand Down
11 changes: 9 additions & 2 deletions .castor/docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function stop(
* @param array<string> $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'];
Expand All @@ -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();
}

/**
Expand Down Expand Up @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 2 additions & 0 deletions application/public/index.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?php

echo 'Hello world from PHP ', \PHP_MAJOR_VERSION, '.', \PHP_MINOR_VERSION, '.', \PHP_RELEASE_VERSION, " inside Docker! \n";

echo 'Environment: ', $_SERVER['APP_ENV'] ?? 'not set', "\n";
5 changes: 5 additions & 0 deletions infrastructure/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ x-templates:
context: services/php
target: worker
user: "${USER_ID}:${USER_ID}"
environment:
- APP_ENV
depends_on:
postgres:
condition: service_healthy
Expand Down Expand Up @@ -41,6 +43,8 @@ services:
cache_from:
- "type=registry,ref=${REGISTRY:-}/frontend:cache"
user: "${USER_ID}:${USER_ID}"
environment:
- APP_ENV
volumes:
- "../..:/var/www:cached"
- "../../.home:/home/app:cached"
Expand Down Expand Up @@ -71,6 +75,7 @@ services:
init: true
user: "${USER_ID}:${USER_ID}"
environment:
- APP_ENV
# The following list contains the common environment variables exposed by CI platforms
- GITHUB_ACTIONS
- CI # Travis CI, CircleCI, Cirrus CI, Gitlab CI, Appveyor, CodeShip, dsari
Expand Down