fix: add compose retry and docker run fallback for deploy
The network stripping Python script had bugs causing dashboard service to be omitted. Replace with simpler approach: remove stale containers and retry compose, with docker run as final fallback. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+28
-32
@@ -253,41 +253,37 @@ jobs:
|
|||||||
docker compose -f /nas-dashboard/docker-compose.yml down 2>/dev/null || true
|
docker compose -f /nas-dashboard/docker-compose.yml down 2>/dev/null || true
|
||||||
echo "Old containers stopped"
|
echo "Old containers stopped"
|
||||||
|
|
||||||
# Docker 24 compose fails when it can't connect external networks
|
# --pull never prevents overwriting the image we just built
|
||||||
# during container creation. Try compose first; if the container
|
|
||||||
# isn't created, strip networks from compose file and retry.
|
|
||||||
docker compose -f /nas-dashboard/docker-compose.yml up -d --pull never 2>&1 || true
|
docker compose -f /nas-dashboard/docker-compose.yml up -d --pull never 2>&1 || true
|
||||||
|
|
||||||
if ! docker container inspect nas-dashboard >/dev/null 2>&1; then
|
if ! docker container inspect nas-dashboard >/dev/null 2>&1; then
|
||||||
echo "Compose failed to create container, stripping networks from compose file..."
|
echo "Compose failed, removing stale containers and retrying..."
|
||||||
python3 -c "
|
docker rm -f docker-socket-proxy nas-dashboard 2>/dev/null || true
|
||||||
import os
|
docker network create nas-dashboard_internal 2>/dev/null || true
|
||||||
lines = open('/nas-dashboard/docker-compose.yml').readlines()
|
docker compose -f /nas-dashboard/docker-compose.yml up -d --pull never 2>&1 || true
|
||||||
out = []
|
fi
|
||||||
skip_net = False
|
|
||||||
for l in lines:
|
if ! docker container inspect nas-dashboard >/dev/null 2>&1; then
|
||||||
stripped = l.strip()
|
echo "Compose still failed, deploying with docker run..."
|
||||||
if stripped == 'networks:' and not l[0].isspace():
|
docker rm -f docker-socket-proxy nas-dashboard 2>/dev/null || true
|
||||||
skip_net = True
|
docker run -d --name docker-socket-proxy \
|
||||||
continue
|
--restart unless-stopped \
|
||||||
if skip_net:
|
-e CONTAINERS=1 -e IMAGES=1 -e INFO=1 -e POST=1 \
|
||||||
if l[0].isspace():
|
-v /var/run/docker.sock:/var/run/docker.sock:ro \
|
||||||
continue
|
tecnativa/docker-socket-proxy
|
||||||
skip_net = False
|
docker run -d --name nas-dashboard \
|
||||||
if stripped == 'networks:' and l[:4].strip() == '':
|
--restart unless-stopped \
|
||||||
skip_net = True
|
-p 127.0.0.1:4000:4000 \
|
||||||
continue
|
-e DOCKER_HOST=tcp://docker-socket-proxy:2375 \
|
||||||
if skip_net:
|
-e GITEA_URL=http://gitea:3000 \
|
||||||
if l.startswith(' '):
|
-e VOLUME_ROOT=/volume1 \
|
||||||
continue
|
-e CORS_ORIGINS=https://nas.jimmygan.com \
|
||||||
skip_net = False
|
-e SECRET_KEY=${SECRET_KEY} \
|
||||||
out.append(l)
|
-e ADMIN_USER=jimmy \
|
||||||
open('/tmp/prod-ci.yml','w').writelines(out)
|
-v /volume1:/volume1 \
|
||||||
"
|
--add-host=host.docker.internal:host-gateway \
|
||||||
# Remove existing docker-socket-proxy if it conflicts (restart: unless-stopped
|
nas-dashboard:latest
|
||||||
# may have recreated it after docker compose down)
|
fi
|
||||||
docker rm -f docker-socket-proxy 2>/dev/null || true
|
|
||||||
docker compose -f /tmp/prod-ci.yml up -d --pull never
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create the internal network if compose didn't create it
|
# Create the internal network if compose didn't create it
|
||||||
|
|||||||
Reference in New Issue
Block a user