fix(ci): change deploy job to vps runner, route Docker commands via ssh nasts
This commit is contained in:
@@ -190,15 +190,10 @@ jobs:
|
||||
|
||||
deploy-dev:
|
||||
name: Deploy to Dev
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: vps
|
||||
needs: [build-image-dev, frontend-tests]
|
||||
env:
|
||||
SECRET_KEY: test-secret-key-for-ci-environment-32chars-minimum
|
||||
container:
|
||||
volumes:
|
||||
- /var/packages/ContainerManager/target/usr/bin/docker:/usr/bin/docker
|
||||
- /var/packages/ContainerManager/target/usr/bin/docker-compose:/usr/lib/docker/cli-plugins/docker-compose
|
||||
- /volume1/docker/nas-dashboard:/volume1/docker/nas-dashboard
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
run: |
|
||||
@@ -219,41 +214,44 @@ jobs:
|
||||
GITEA_DB_PASSWORD: ${{ secrets.GITEA_DB_PASSWORD }}
|
||||
run: |
|
||||
set -u
|
||||
export DOCKER_API_VERSION=1.43
|
||||
DOCKER="ssh nasts /volume1/@appstore/ContainerManager/usr/bin/docker"
|
||||
COMPOSE="ssh nasts /volume1/@appstore/ContainerManager/usr/bin/docker-compose"
|
||||
NAS_VOL="/volume1/docker/nas-dashboard"
|
||||
|
||||
cd /volume1/docker/nas-dashboard
|
||||
# Sync compose file to NAS
|
||||
ssh nasts "mkdir -p $NAS_VOL"
|
||||
scp dashboard/docker-compose.dev.yml "nasts:$NAS_VOL/docker-compose.dev.yml"
|
||||
|
||||
# Stop existing container if running
|
||||
docker compose -f docker-compose.dev.yml -p nas-dashboard-dev down || true
|
||||
$COMPOSE -f docker-compose.dev.yml -p nas-dashboard-dev down 2>/dev/null || true
|
||||
|
||||
# Ensure network exists (create only if it doesn't exist)
|
||||
if ! docker network inspect nas-dashboard_internal >/dev/null 2>&1; then
|
||||
docker network create nas-dashboard_internal
|
||||
if ! $DOCKER network inspect nas-dashboard_internal >/dev/null 2>&1; then
|
||||
$DOCKER network create nas-dashboard_internal
|
||||
fi
|
||||
|
||||
# Use environment variables directly in compose or via command injection
|
||||
# For development, we can inject env vars into the compose run
|
||||
GITEA_TOKEN=$GITEA_TOKEN SECRET_KEY=$SECRET_KEY \
|
||||
docker compose -f docker-compose.dev.yml -p nas-dashboard-dev up -d --pull never 2>&1 || true
|
||||
# Deploy
|
||||
ssh nasts "cd $NAS_VOL && GITEA_TOKEN=$GITEA_TOKEN SECRET_KEY=$SECRET_KEY /volume1/@appstore/ContainerManager/usr/bin/docker-compose -f docker-compose.dev.yml -p nas-dashboard-dev up -d --pull never" 2>&1 || true
|
||||
|
||||
if ! docker container 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..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Connect networks after container is created (idempotent)
|
||||
docker network connect nas-dashboard_internal nas-dashboard-dev 2>/dev/null || true
|
||||
docker network connect gitea_gitea nas-dashboard-dev 2>/dev/null || true
|
||||
$DOCKER network connect nas-dashboard_internal nas-dashboard-dev 2>/dev/null || true
|
||||
$DOCKER network connect gitea_gitea nas-dashboard-dev 2>/dev/null || true
|
||||
|
||||
# Verify both connections
|
||||
echo "=== Network connections ==="
|
||||
docker inspect nas-dashboard-dev --format '{{json .NetworkSettings.Networks}}' | python3 -c 'import json,sys;nets=json.load(sys.stdin);[print(f" Connected to {n}") for n in nets];assert "nas-dashboard_internal" in nets and "gitea_gitea" in nets, "Missing required network";print("All network connections established")'
|
||||
$DOCKER inspect nas-dashboard-dev --format '{{json .NetworkSettings.Networks}}' | python3 -c 'import json,sys;nets=json.load(sys.stdin);[print(f" Connected to {n}") for n in nets];assert "nas-dashboard_internal" in nets and "gitea_gitea" in nets, "Missing required network";print("All network connections established")'
|
||||
|
||||
- name: Wait for container to be healthy
|
||||
run: |
|
||||
DOCKER="ssh nasts /volume1/@appstore/ContainerManager/usr/bin/docker"
|
||||
echo "Waiting for container to be healthy..."
|
||||
for i in {1..30}; do
|
||||
STATUS=$(docker inspect --format='{{.State.Health.Status}}' nas-dashboard-dev 2>/dev/null || echo "starting")
|
||||
STATUS=$($DOCKER inspect --format='{{.State.Health.Status}}' nas-dashboard-dev 2>/dev/null || echo "starting")
|
||||
if [ "$STATUS" = "healthy" ]; then
|
||||
echo "✅ Container is healthy"
|
||||
break
|
||||
@@ -261,28 +259,29 @@ jobs:
|
||||
echo "Waiting... ($i/30) Status: $STATUS"
|
||||
sleep 2
|
||||
done
|
||||
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
|
||||
echo "❌ Container failed to become healthy: $STATUS"
|
||||
docker logs nas-dashboard-dev --tail 50
|
||||
$DOCKER logs nas-dashboard-dev --tail 50
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Run smoke tests
|
||||
run: |
|
||||
DOCKER="ssh nasts /volume1/@appstore/ContainerManager/usr/bin/docker"
|
||||
echo "=== Running smoke tests via docker exec ==="
|
||||
|
||||
# Test 1: Health check
|
||||
echo "1. Testing health endpoint..."
|
||||
docker exec nas-dashboard-dev python3 -c "import urllib.request,json; d=json.loads(urllib.request.urlopen('http://localhost:4000/api/health',timeout=5).read()); assert d['status']=='ok', f'unexpected: {d}'" && echo "✅ Health check passed" || { echo "❌ Health check failed"; docker logs nas-dashboard-dev --tail 50; exit 1; }
|
||||
$DOCKER exec nas-dashboard-dev python3 -c "import urllib.request,json; d=json.loads(urllib.request.urlopen('http://localhost:4000/api/health',timeout=5).read()); assert d['status']=='ok', f'unexpected: {d}'" && echo "✅ Health check passed" || { echo "❌ Health check failed"; $DOCKER logs nas-dashboard-dev --tail 50; exit 1; }
|
||||
|
||||
# Test 2: Frontend loads
|
||||
echo "2. Testing frontend loads..."
|
||||
docker exec nas-dashboard-dev python3 -c "import urllib.request; html=urllib.request.urlopen('http://localhost:4000/',timeout=5).read().decode(); assert 'NAS Dashboard' in html, f'missing NAS Dashboard'" && echo "✅ Frontend loads" || { echo "❌ Frontend failed to load"; exit 1; }
|
||||
$DOCKER exec nas-dashboard-dev python3 -c "import urllib.request; html=urllib.request.urlopen('http://localhost:4000/',timeout=5).read().decode(); assert 'NAS Dashboard' in html, f'missing NAS Dashboard'" && echo "✅ Frontend loads" || { echo "❌ Frontend failed to load"; exit 1; }
|
||||
|
||||
# Test 3: API endpoints require auth
|
||||
echo "3. Testing API endpoints require auth..."
|
||||
docker exec nas-dashboard-dev python3 -c "
|
||||
$DOCKER exec nas-dashboard-dev python3 -c "
|
||||
import urllib.request, json
|
||||
try:
|
||||
resp = urllib.request.urlopen('http://localhost:4000/api/conversations/dates', timeout=5)
|
||||
@@ -294,7 +293,7 @@ jobs:
|
||||
|
||||
# Test 4: Double /api/ prefix bug (non-failing)
|
||||
echo "4. Testing for double /api/ prefix bug..."
|
||||
docker exec nas-dashboard-dev python3 -c "
|
||||
$DOCKER exec nas-dashboard-dev python3 -c "
|
||||
import urllib.request
|
||||
try:
|
||||
urllib.request.urlopen('http://localhost:4000/api/api/conversations/dates', timeout=5)
|
||||
@@ -304,7 +303,5 @@ jobs:
|
||||
print('OK: /api/api/ returned 404')
|
||||
" && echo "✅ No double /api/ prefix bug" || echo "⚠️ Double API prefix warning"
|
||||
|
||||
# Test 5: Container health already verified in previous step
|
||||
|
||||
echo ""
|
||||
echo "=== All smoke tests passed! ==="
|
||||
|
||||
Reference in New Issue
Block a user