fix: strip networks from compose file for Docker 24 compat
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:
@@ -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():
|
|
||||||
f.write(f' {svc}:\n')
|
|
||||||
for sk, sv in svc_cfg.items():
|
|
||||||
if sk == 'networks':
|
|
||||||
continue
|
continue
|
||||||
elif isinstance(sv, dict):
|
if skip_net:
|
||||||
f.write(f' {sk}:\n')
|
if l[0].isspace():
|
||||||
for dk, dv in sv.items():
|
|
||||||
f.write(f' {dk}: {json.dumps(dv) if not isinstance(dv, str) else dv}\n')
|
|
||||||
elif isinstance(sv, list):
|
|
||||||
f.write(f' {sk}:\n')
|
|
||||||
for e in sv:
|
|
||||||
f.write(f' {json.dumps(e) if not isinstance(e, str) else e}\n')
|
|
||||||
else:
|
|
||||||
f.write(f' {sk}: {json.dumps(sv) if not isinstance(sv, str) else sv}\n')
|
|
||||||
elif k == 'networks':
|
|
||||||
continue
|
continue
|
||||||
else:
|
skip_net = False
|
||||||
f.write(f'{k}: {json.dumps(v) if not isinstance(v, str) else v}\n')
|
if stripped == 'networks:' and l[:4].strip() == '':
|
||||||
"
|
skip_net = True
|
||||||
docker compose -f /tmp/no-network.yml -p nas-dashboard-dev up -d --pull never
|
continue
|
||||||
|
if skip_net:
|
||||||
|
if l.startswith(' '):
|
||||||
|
continue
|
||||||
|
skip_net = False
|
||||||
|
out.append(l)
|
||||||
|
open('/tmp/ci.yml','w').writelines(out)
|
||||||
|
"
|
||||||
|
docker compose -f /tmp/ci.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"
|
||||||
|
|||||||
Reference in New Issue
Block a user