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