Skip to content

Commit 87b6cbc

Browse files
committed
Make docker-compose load specific env files per environment
Because of a change in docker-compose, which always read and parses the .env file in the root, the .env file was parsed incorrectly. Since we don't even need docker-compose to load the .env file, we override that in the cli command by specifying an env file.
1 parent 0c8bf02 commit 87b6cbc

File tree

7 files changed

+22
-17
lines changed

7 files changed

+22
-17
lines changed

Diff for: Makefile

+8-9
Original file line numberDiff line numberDiff line change
@@ -128,23 +128,22 @@ shell:
128128

129129
test:
130130
- ENV='tst' ./bin/stop # Just in case some container is left over stopped, as is the case after PHPStorm runs tests
131-
ENV='tst' ./bin/run
132131
- $(MAKE) cs-fix
133132
ENV='tst' ./bin/run php vendor/bin/phpunit
134-
ENV='tst' ./bin/stop
133+
- ENV='tst' ./bin/stop
135134
$(MAKE) test-acc
136135
$(MAKE) test-dep
137136

138137
test-acc:
139138
- ENV='tst' ./bin/stop # Just in case some container is left over stopped, as is the case after PHPStorm runs tests
140139
ENV='tst' ./bin/run make db-setup-guest
141-
ENV='tst' docker-compose -f build/container/tst/docker-compose.yml up -d -t 0
140+
ENV='tst' docker-compose --env-file=build/container/${ENV}/docker.env -f build/container/tst/docker-compose.yml up -d -t 0
142141
php vendor/bin/codecept run -g acceptance
143-
ENV='tst' ./bin/stop
142+
- ENV='tst' ./bin/stop
144143

145144
test-acc-ci:
146145
- ENV='prd' ./bin/stop # Just in case some container is left over stopped, as is the case after PHPStorm runs tests
147-
ENV='prd' docker-compose -f build/container/prd/docker-compose.yml up -d -t 0
146+
ENV='prd' docker-compose --env-file=build/container/${ENV}/docker.env -f build/container/prd/docker-compose.yml up -d -t 0
148147
php vendor/bin/codecept run -g acceptance
149148
ENV='prd' ./bin/stop
150149

@@ -203,11 +202,11 @@ test_cov-publish:
203202

204203
up:
205204
if [ ! -f ${DB_PATH} ]; then $(MAKE) db-setup; fi
206-
$(eval UP=ENV=dev docker-compose -f build/container/dev/docker-compose.yml up -t 0)
207-
$(eval DOWN=ENV=dev docker-compose -f build/container/dev/docker-compose.yml down -t 0)
205+
$(eval UP=ENV=dev docker-compose --env-file=build/container/${ENV}/docker.env -f build/container/dev/docker-compose.yml up -t 0)
206+
$(eval DOWN=ENV=dev docker-compose --env-file=build/container/${ENV}/docker.env -f build/container/dev/docker-compose.yml down -t 0)
208207
- bash -c "trap '${DOWN}' EXIT; ${UP}"
209208

210209
up-prd:
211-
$(eval UP=ENV=prd docker-compose -f build/container/prd/docker-compose.yml up -t 0)
212-
$(eval DOWN=ENV=prd docker-compose -f build/container/prd/docker-compose.yml down -t 0)
210+
$(eval UP=ENV=prd docker-compose --env-file=build/container/${ENV}/docker.env -f build/container/prd/docker-compose.yml up -t 0)
211+
$(eval DOWN=ENV=prd docker-compose --env-file=build/container/${ENV}/docker.env -f build/container/prd/docker-compose.yml down -t 0)
213212
- bash -c "trap '${DOWN}' EXIT; ${UP}"

Diff for: bin/run

+5-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ $detached = '';
2424

2525
$containerName = 'app.sfn.' . $env;
2626
$yamlFile = "$rootDir/build/container/$env/docker-compose.yml";
27-
$downCommand = "docker-compose -f $yamlFile down -t 0"; // we use the "-t 0" so that we don't have a timeout of 10s, needs version >= 1.22
27+
$envFile = "$rootDir/build/container/$env/docker.env";
28+
$downCommand = "docker-compose --env-file=$envFile -f $yamlFile down -t 0"; // we use the "-t 0" so that we don't have a timeout of 10s, needs version >= 1.22
2829

2930
if (empty($argumentList) && isContainerRunning($containerName)) {
3031
exit($returnVal);
@@ -33,13 +34,13 @@ if (empty($argumentList) && isContainerRunning($containerName)) {
3334
if (empty($argumentList)) {
3435
// If no command is given to execute, just keep the container running in the background for 1h
3536
$detached = '-d';
36-
$guestCommand = "sleep 3600";
37+
$guestCommand = "sleep 3600";
3738
} else {
38-
$guestCommand = implode(' ', $argumentList);
39+
$guestCommand = implode(' ', $argumentList);
3940
}
4041

4142
// We wrap the $guestCommand in /bin/sh so that we get the full output if it breaks, ie with a segfault
42-
$hostCommand = "docker-compose -f $yamlFile run $detached -u $(id -u):$(id -g) --name $containerName app /bin/sh -c '$guestCommand'";
43+
$hostCommand = "docker-compose --env-file=$envFile -f $yamlFile run $detached -u $(id -u):$(id -g) --name $containerName app /bin/sh -c '$guestCommand'";
4344

4445
if (!$detached) {
4546
// We wrap the host command in bash trap so that we can trap a signal and destroy the stopped containers

Diff for: bin/stop

+9-4
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,21 @@ $debug = false;
1111

1212
$env = getenv('ENV') ?: 'dev';
1313
$rootDir = __DIR__ . '/..';
14-
$returnVal = 0;
14+
$downReturnVal = 0;
15+
$removeReturnVal = 0;
1516

1617
$containerName = 'app.sfn.' . $env;
1718
$yamlFile = "$rootDir/build/container/$env/docker-compose.yml";
19+
$envFile = "$rootDir/build/container/$env/docker.env";
1820

19-
$downCommand = "docker-compose -f $yamlFile down -t 0"; // we use the "-t 0" so that we don't have a timeout of 10s, needs version >= 1.22
21+
$downCommand = "docker-compose --env-file=$envFile -f $yamlFile down -t 0"; // we use the "-t 0" so that we don't have a timeout of 10s, needs version >= 1.22
22+
$removeCommand = "docker container rm $containerName -f";
2023

2124
if (isContainerExists($containerName)) {
2225
if ($debug) echo "[DEBUG-STOP] $downCommand \n";
23-
system($downCommand, $returnVal);
26+
system($downCommand, $downReturnVal);
27+
if ($debug) echo "[DEBUG-STOP] $downCommand \n";
28+
system($removeCommand, $removeReturnVal);
2429
}
2530

26-
exit($returnVal);
31+
exit($downReturnVal + $removeReturnVal);

Diff for: build/container/ci/docker.env

Whitespace-only changes.

Diff for: build/container/dev/docker.env

Whitespace-only changes.

Diff for: build/container/prd/docker.env

Whitespace-only changes.

Diff for: build/container/tst/docker.env

Whitespace-only changes.

0 commit comments

Comments
 (0)