fix: strip networks from compose file for Docker 24 compat
Deploy Dashboard (Dev) / Backend Tests (push) Successful in 14m49s
Deploy Dashboard (Dev) / Frontend Tests (push) Successful in 43s
Deploy Dashboard (Dev) / Deploy to Dev (push) Failing after 6m11s

Docker Compose v2.20.1 fails to create containers that need external
networks. Try compose directly; if container isn't created, generate a
stripped copy of the compose file without network config and retry.
Connect networks manually in both paths.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Gan, Jimmy
2026-05-17 20:09:14 +08:00
parent c7073377ca
commit 0ac3a896af
+28 -41
View File
@@ -180,7 +180,6 @@ jobs:
prewarm_base_image() { prewarm_base_image() {
image_ref="$1" image_ref="$1"
# Skip if image already exists locally
if docker image inspect "${image_ref}" >/dev/null 2>&1; then if docker image inspect "${image_ref}" >/dev/null 2>&1; then
echo "Image ${image_ref} already exists locally, skipping pre-pull" echo "Image ${image_ref} already exists locally, skipping pre-pull"
return 0 return 0
@@ -203,11 +202,6 @@ jobs:
run: | run: |
set -e set -e
export DOCKER_API_VERSION=1.43 export DOCKER_API_VERSION=1.43
# DOCKER_BUILDKIT=0 is required for Synology ContainerManager's Docker daemon,
# which does not support BuildKit syntax. Remove when Synology updates to a
# Docker Engine version with full BuildKit support (currently 24.x, needs 23+).
# --cache-to type=inline is a no-op while BuildKit is disabled; it activates
# automatically when DOCKER_BUILDKIT=0 is removed.
if ! DOCKER_BUILDKIT=0 docker build --cache-from nas-dashboard-dev:latest -t nas-dashboard-dev:latest dashboard/; then if ! DOCKER_BUILDKIT=0 docker build --cache-from nas-dashboard-dev:latest -t nas-dashboard-dev:latest dashboard/; then
echo "Build failed. Checking for network issues..." echo "Build failed. Checking for network issues..."
curl -I https://registry.npmmirror.com || echo "npmmirror unreachable" curl -I https://registry.npmmirror.com || echo "npmmirror unreachable"
@@ -237,42 +231,36 @@ jobs:
# Docker 24 compose fails when it can't connect external networks # Docker 24 compose fails when it can't connect external networks
# during container creation. Try compose first; if the container # during container creation. Try compose first; if the container
# isn't created, strip networks from the resolved config via # isn't created, strip networks from compose file and retry.
# docker compose config output (processed with Python json).
docker compose -f docker-compose.dev.yml -p nas-dashboard-dev up -d --pull never 2>&1 || true docker compose -f docker-compose.dev.yml -p nas-dashboard-dev up -d --pull never 2>&1 || true
if ! docker inspect nas-dashboard-dev >/dev/null 2>&1; then if ! docker container inspect nas-dashboard-dev >/dev/null 2>&1; then
echo "Compose failed to create container, stripping networks from config..." echo "Compose failed to create container, stripping networks from compose file..."
docker compose -f docker-compose.dev.yml config --format json 2>/dev/null | python3 -c " python3 -c "
import json, sys import os
cfg = json.load(sys.stdin) lines = open('docker-compose.dev.yml').readlines()
cfg['services']['dashboard-dev']['networks'] = {} out = []
cfg['networks'] = {} skip_net = False
with open('/tmp/no-network.yml', 'w') as f: for l in lines:
for k, v in cfg.items(): stripped = l.strip()
if k == 'services': if stripped == 'networks:' and not l[0].isspace():
f.write('services:\n') skip_net = True
for svc, svc_cfg in v.items(): continue
f.write(f' {svc}:\n') if skip_net:
for sk, sv in svc_cfg.items(): if l[0].isspace():
if sk == 'networks': continue
continue skip_net = False
elif isinstance(sv, dict): if stripped == 'networks:' and l[:4].strip() == '':
f.write(f' {sk}:\n') skip_net = True
for dk, dv in sv.items(): continue
f.write(f' {dk}: {json.dumps(dv) if not isinstance(dv, str) else dv}\n') if skip_net:
elif isinstance(sv, list): if l.startswith(' '):
f.write(f' {sk}:\n') continue
for e in sv: skip_net = False
f.write(f' {json.dumps(e) if not isinstance(e, str) else e}\n') out.append(l)
else: open('/tmp/ci.yml','w').writelines(out)
f.write(f' {sk}: {json.dumps(sv) if not isinstance(sv, str) else sv}\n') "
elif k == 'networks': docker compose -f /tmp/ci.yml -p nas-dashboard-dev up -d --pull never
continue
else:
f.write(f'{k}: {json.dumps(v) if not isinstance(v, str) else v}\n')
"
docker compose -f /tmp/no-network.yml -p nas-dashboard-dev up -d --pull never
fi fi
# Connect networks after container is created (idempotent) # Connect networks after container is created (idempotent)
@@ -295,7 +283,6 @@ with open('/tmp/no-network.yml', 'w') as f:
echo "Waiting... ($i/30) Status: $STATUS" echo "Waiting... ($i/30) Status: $STATUS"
sleep 2 sleep 2
done done
# Final check
STATUS=$(docker inspect --format='{{.State.Health.Status}}' nas-dashboard-dev 2>/dev/null || echo "unknown") STATUS=$(docker inspect --format='{{.State.Health.Status}}' nas-dashboard-dev 2>/dev/null || echo "unknown")
if [ "$STATUS" != "healthy" ]; then if [ "$STATUS" != "healthy" ]; then
echo "❌ Container failed to become healthy: $STATUS" echo "❌ Container failed to become healthy: $STATUS"