Skip to content

Commit 19d31cf

Browse files
committed
Refuse a deploy whose compose project or port is not the environment's
Checked after checkout with `docker compose config`: production only starts once main carries the parametrized docker-compose.yml.
1 parent f226d54 commit 19d31cf

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎deploy/dispatch.sh‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ main() {
2323
cd "$dir"
2424
git fetch -q --prune origin "$branch"
2525
git checkout -q -B "$branch" "origin/$branch"
26+
# Never let one environment take over another one's containers and
27+
# volumes (e.g. an older docker-compose.yml with a fixed project name).
28+
local expected="jscm 3333" actual
29+
[[ "$target" == production ]] && expected="jscm-prod 3334"
30+
actual="$(docker compose config --format json 2>/dev/null | python3 -c 'import json, sys; c = json.load(sys.stdin); print(c["name"], c["services"]["app"]["ports"][0]["published"])' || true)"
31+
if [[ "$actual" != "$expected" ]]; then
32+
echo "!! compose project/port is '${actual:-?}', expected '$expected': refusing to deploy $target" >&2
33+
exit 4
34+
fi
2635
exec ./deploy/deploy.sh "$branch"
2736
;;
2837
preview)

0 commit comments

Comments
 (0)