Merge pull request 'fix: apply Docker 24 network workaround and smoke tests to production deploy' (#64) from dev into main
This commit was merged in pull request #64.
This commit is contained in:
@@ -20,9 +20,10 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.sha }}
|
||||
run: |
|
||||
if [ ! -d .git ]; then
|
||||
git clone --branch "${GITHUB_REF_NAME}" --depth=1 "http://gitea:3000/${GITHUB_REPOSITORY}.git" .
|
||||
fi
|
||||
|
||||
- name: Resolve image tags
|
||||
run: |
|
||||
|
||||
+115
-39
@@ -20,9 +20,10 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
run: |
|
||||
if [ ! -d .git ]; then
|
||||
git clone --depth=1 "http://gitea:3000/${GITHUB_REPOSITORY}.git" .
|
||||
fi
|
||||
|
||||
- name: Setup Python
|
||||
run: |
|
||||
@@ -60,17 +61,25 @@ jobs:
|
||||
rm -rf venv
|
||||
python3 -m venv venv
|
||||
. venv/bin/activate
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements.txt || pip install -r requirements.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements-dev.txt || pip install -r requirements-dev.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout || pip install pytest-timeout
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements.txt || \
|
||||
pip install -r requirements.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements-dev.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements-dev.txt || \
|
||||
pip install -r requirements-dev.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout || pip install pytest-timeout
|
||||
fi
|
||||
else
|
||||
echo "Installing fresh dependencies..."
|
||||
python3 -m venv venv
|
||||
. venv/bin/activate
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements.txt || pip install -r requirements.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements-dev.txt || pip install -r requirements-dev.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout || pip install pytest-timeout
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements.txt || \
|
||||
pip install -r requirements.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements-dev.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements-dev.txt || \
|
||||
pip install -r requirements-dev.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout || pip install pytest-timeout
|
||||
echo "Saving venv to cache $CACHE_KEY..."
|
||||
cp -a venv $CACHE_DIR/ || echo "Warning: cache save failed"
|
||||
fi
|
||||
@@ -92,9 +101,10 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
run: |
|
||||
if [ ! -d .git ]; then
|
||||
git clone --depth=1 "http://gitea:3000/${GITHUB_REPOSITORY}.git" .
|
||||
fi
|
||||
|
||||
- name: Setup Node.js
|
||||
run: |
|
||||
@@ -130,11 +140,11 @@ jobs:
|
||||
else
|
||||
echo "Cache corrupted, installing fresh..."
|
||||
rm -rf node_modules
|
||||
npm ci
|
||||
npm ci || { echo "mirror failed, trying default registry..."; npm config set registry https://registry.npmjs.org; npm ci; }
|
||||
fi
|
||||
else
|
||||
echo "Installing fresh dependencies..."
|
||||
npm ci
|
||||
npm ci || { echo "mirror failed, trying default registry..."; npm config set registry https://registry.npmjs.org; npm ci; }
|
||||
echo "Saving to cache $CACHE_KEY..."
|
||||
cp -a node_modules $CACHE_DIR/ || echo "Warning: cache save failed"
|
||||
fi
|
||||
@@ -149,13 +159,21 @@ jobs:
|
||||
|
||||
deploy-dev:
|
||||
name: Deploy to Dev
|
||||
runs-on: nas
|
||||
runs-on: ubuntu-latest
|
||||
needs: [backend-tests, 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
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
run: |
|
||||
if [ ! -d .git ]; then
|
||||
git clone --depth=1 "http://gitea:3000/${GITHUB_REPOSITORY}.git" .
|
||||
fi
|
||||
|
||||
- name: Warm mirror cache for base images
|
||||
run: |
|
||||
@@ -164,7 +182,6 @@ jobs:
|
||||
|
||||
prewarm_base_image() {
|
||||
image_ref="$1"
|
||||
# Skip if image already exists locally
|
||||
if docker image inspect "${image_ref}" >/dev/null 2>&1; then
|
||||
echo "Image ${image_ref} already exists locally, skipping pre-pull"
|
||||
return 0
|
||||
@@ -187,11 +204,6 @@ jobs:
|
||||
run: |
|
||||
set -e
|
||||
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
|
||||
echo "Build failed. Checking for network issues..."
|
||||
curl -I https://registry.npmmirror.com || echo "npmmirror unreachable"
|
||||
@@ -206,7 +218,7 @@ jobs:
|
||||
|
||||
- name: Deploy dev
|
||||
run: |
|
||||
set -euo pipefail
|
||||
set -u
|
||||
export DOCKER_API_VERSION=1.43
|
||||
|
||||
cd /volume1/docker/nas-dashboard
|
||||
@@ -219,12 +231,47 @@ jobs:
|
||||
docker network create nas-dashboard_internal
|
||||
fi
|
||||
|
||||
# Deploy with compose (without --build since we already built the image)
|
||||
docker compose -f docker-compose.dev.yml -p nas-dashboard-dev up -d --pull never
|
||||
# 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.
|
||||
docker compose -f docker-compose.dev.yml -p nas-dashboard-dev up -d --pull never 2>&1 || true
|
||||
|
||||
# Manually connect to networks after container is created
|
||||
docker network connect nas-dashboard_internal nas-dashboard-dev || true
|
||||
docker network connect gitea_gitea nas-dashboard-dev || true
|
||||
if ! docker container inspect nas-dashboard-dev >/dev/null 2>&1; then
|
||||
echo "Compose failed to create container, stripping networks from compose file..."
|
||||
python3 -c "
|
||||
import os
|
||||
lines = open('docker-compose.dev.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/ci.yml','w').writelines(out)
|
||||
"
|
||||
docker compose -f /tmp/ci.yml -p nas-dashboard-dev up -d --pull never
|
||||
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
|
||||
|
||||
# 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")'
|
||||
|
||||
- name: Wait for container to be healthy
|
||||
run: |
|
||||
@@ -238,7 +285,6 @@ jobs:
|
||||
echo "Waiting... ($i/30) Status: $STATUS"
|
||||
sleep 2
|
||||
done
|
||||
# Final check
|
||||
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"
|
||||
@@ -248,11 +294,41 @@ jobs:
|
||||
|
||||
- name: Run smoke tests
|
||||
run: |
|
||||
cd /volume1/repos/nas-tools
|
||||
bash scripts/smoke-test-dashboard.sh dev
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "❌ Smoke tests failed! Check logs above."
|
||||
docker logs nas-dashboard-dev --tail 100
|
||||
exit 1
|
||||
fi
|
||||
echo "✅ Smoke tests passed"
|
||||
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; }
|
||||
|
||||
# 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; }
|
||||
|
||||
# Test 3: API endpoints require auth
|
||||
echo "3. Testing API endpoints require auth..."
|
||||
docker exec nas-dashboard-dev python3 -c "
|
||||
import urllib.request, json
|
||||
try:
|
||||
resp = urllib.request.urlopen('http://localhost:4000/api/conversations/dates', timeout=5)
|
||||
data = resp.read().decode()
|
||||
assert 'Not authenticated' in data or 'detail' in data, f'unexpected: {data[:200]}'
|
||||
except urllib.error.HTTPError as e:
|
||||
assert e.code in (401, 403), f'expected 401/403, got {e.code}'
|
||||
" && echo "✅ API requires auth" || { echo "❌ Auth check failed"; exit 1; }
|
||||
|
||||
# Test 4: Double /api/ prefix bug (non-failing)
|
||||
echo "4. Testing for double /api/ prefix bug..."
|
||||
docker exec nas-dashboard-dev python3 -c "
|
||||
import urllib.request
|
||||
try:
|
||||
urllib.request.urlopen('http://localhost:4000/api/api/conversations/dates', timeout=5)
|
||||
print('WARNING: /api/api/ returned 200')
|
||||
except urllib.error.HTTPError as e:
|
||||
assert e.code == 404, f'expected 404, got {e.code}'
|
||||
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! ==="
|
||||
|
||||
+96
-25
@@ -19,9 +19,10 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
run: |
|
||||
if [ ! -d .git ]; then
|
||||
git clone --depth=1 "http://gitea:3000/${GITHUB_REPOSITORY}.git" .
|
||||
fi
|
||||
|
||||
- name: Setup Python
|
||||
run: |
|
||||
@@ -60,17 +61,25 @@ jobs:
|
||||
rm -rf venv
|
||||
python3 -m venv venv
|
||||
. venv/bin/activate
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements.txt || pip install -r requirements.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements-dev.txt || pip install -r requirements-dev.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout pytest-cov || pip install pytest-timeout pytest-cov
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements.txt || \
|
||||
pip install -r requirements.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements-dev.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements-dev.txt || \
|
||||
pip install -r requirements-dev.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout pytest-cov || pip install pytest-timeout pytest-cov
|
||||
fi
|
||||
else
|
||||
echo "Installing fresh dependencies..."
|
||||
python3 -m venv venv
|
||||
. venv/bin/activate
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements.txt || pip install -r requirements.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements-dev.txt || pip install -r requirements-dev.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout pytest-cov || pip install pytest-timeout pytest-cov
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements.txt || \
|
||||
pip install -r requirements.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements-dev.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements-dev.txt || \
|
||||
pip install -r requirements-dev.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout pytest-cov || pip install pytest-timeout pytest-cov
|
||||
echo "Saving venv to cache $CACHE_KEY..."
|
||||
cp -a venv $CACHE_DIR/ || echo "Warning: cache save failed"
|
||||
fi
|
||||
@@ -96,9 +105,10 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
run: |
|
||||
if [ ! -d .git ]; then
|
||||
git clone --depth=1 "http://gitea:3000/${GITHUB_REPOSITORY}.git" .
|
||||
fi
|
||||
|
||||
- name: Setup Node.js
|
||||
run: |
|
||||
@@ -135,11 +145,11 @@ jobs:
|
||||
else
|
||||
echo "Cache corrupted, installing fresh..."
|
||||
rm -rf node_modules
|
||||
npm ci
|
||||
npm ci || { echo "mirror failed, trying default registry..."; npm config set registry https://registry.npmjs.org; npm ci; }
|
||||
fi
|
||||
else
|
||||
echo "Installing fresh dependencies..."
|
||||
npm ci
|
||||
npm ci || { echo "mirror failed, trying default registry..."; npm config set registry https://registry.npmjs.org; npm ci; }
|
||||
echo "Saving to cache $CACHE_KEY..."
|
||||
cp -a node_modules $CACHE_DIR/ || echo "Warning: cache save failed"
|
||||
fi
|
||||
@@ -161,15 +171,18 @@ jobs:
|
||||
name: Deploy to Production
|
||||
runs-on: ubuntu-latest
|
||||
needs: [backend-tests, 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
|
||||
- /volume1/docker/nas-dashboard:/nas-dashboard
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
run: |
|
||||
if [ ! -d .git ]; then
|
||||
git clone --depth=1 "http://gitea:3000/${GITHUB_REPOSITORY}.git" .
|
||||
fi
|
||||
|
||||
- name: Warm mirror cache for base images
|
||||
run: |
|
||||
@@ -226,24 +239,82 @@ jobs:
|
||||
- name: Sync runtime compose file
|
||||
run: cp dashboard/docker-compose.yml /nas-dashboard/docker-compose.yml
|
||||
|
||||
- name: Deploy
|
||||
- name: Deploy and verify
|
||||
run: |
|
||||
set -e
|
||||
export DOCKER_API_VERSION=1.43
|
||||
docker compose -f /nas-dashboard/docker-compose.yml up -d --pull never
|
||||
|
||||
- name: Wait for container to be healthy
|
||||
run: |
|
||||
# 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.
|
||||
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)
|
||||
"
|
||||
docker compose -f /tmp/prod-ci.yml up -d --pull never
|
||||
fi
|
||||
|
||||
# Create the internal network if compose didn't create it
|
||||
docker network create internal 2>/dev/null || true
|
||||
|
||||
# Connect docker-socket-proxy to networks
|
||||
docker network connect internal docker-socket-proxy 2>/dev/null || true
|
||||
docker network connect nas-dashboard_internal docker-socket-proxy 2>/dev/null || true
|
||||
|
||||
# Connect dashboard to networks
|
||||
docker network connect internal nas-dashboard 2>/dev/null || true
|
||||
docker network connect nas-dashboard_internal nas-dashboard 2>/dev/null || true
|
||||
docker network connect gitea_gitea nas-dashboard 2>/dev/null || true
|
||||
|
||||
# Verify network connections
|
||||
echo "=== Network connections ==="
|
||||
docker inspect nas-dashboard --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, "Missing nas-dashboard_internal";print("All network connections established")'
|
||||
|
||||
# Wait for container to be healthy
|
||||
echo "Waiting for container to be healthy..."
|
||||
for i in {1..30}; do
|
||||
STATUS=$(docker inspect --format='{{.State.Health.Status}}' nas-dashboard 2>/dev/null || echo "starting")
|
||||
if [ "$STATUS" = "healthy" ]; then
|
||||
echo "✅ Container is healthy"
|
||||
exit 0
|
||||
break
|
||||
fi
|
||||
echo "Waiting... ($i/30) Status: $STATUS"
|
||||
sleep 2
|
||||
done
|
||||
echo "❌ Container failed to become healthy"
|
||||
docker logs nas-dashboard --tail 50
|
||||
exit 1
|
||||
STATUS=$(docker inspect --format='{{.State.Health.Status}}' nas-dashboard 2>/dev/null || echo "unknown")
|
||||
if [ "$STATUS" != "healthy" ]; then
|
||||
echo "❌ Container failed to become healthy: $STATUS"
|
||||
docker logs nas-dashboard --tail 50
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Run smoke tests via docker exec
|
||||
echo "=== Running smoke tests ==="
|
||||
docker exec nas-dashboard 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 --tail 50; exit 1; }
|
||||
docker exec nas-dashboard 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; }
|
||||
echo ""
|
||||
echo "=== All deployment checks passed! ==="
|
||||
|
||||
+35
-24
@@ -14,9 +14,10 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
run: |
|
||||
if [ ! -d .git ]; then
|
||||
git clone "http://gitea:3000/${GITHUB_REPOSITORY}.git" .
|
||||
fi
|
||||
continue-on-error: true
|
||||
|
||||
- name: Run gitleaks
|
||||
@@ -38,9 +39,10 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
run: |
|
||||
if [ ! -d .git ]; then
|
||||
git clone --depth=1 "http://gitea:3000/${GITHUB_REPOSITORY}.git" .
|
||||
fi
|
||||
|
||||
- name: Setup Python
|
||||
run: |
|
||||
@@ -72,27 +74,35 @@ jobs:
|
||||
cd dashboard/backend
|
||||
if [ "${{ steps.cache-python.outputs.cache-hit }}" = "true" ]; then
|
||||
echo "Restoring venv from cache $CACHE_KEY..."
|
||||
if cp -a $CACHE_DIR/venv . && [ -f venv/bin/activate ]; then
|
||||
if cp -a $CACHE_DIR/venv . && [ -f venv/bin/activate ]; then
|
||||
echo "Cache restored successfully"
|
||||
else
|
||||
echo "Cache corrupted, installing fresh..."
|
||||
else
|
||||
echo "Cache corrupted, installing fresh..."
|
||||
rm -rf venv
|
||||
python3 -m venv venv
|
||||
. venv/bin/activate
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements.txt || pip install -r requirements.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements-dev.txt || pip install -r requirements-dev.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout pytest-cov || pip install pytest-timeout pytest-cov
|
||||
fi
|
||||
else
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements.txt || \
|
||||
pip install -r requirements.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements-dev.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements-dev.txt || \
|
||||
pip install -r requirements-dev.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout pytest-cov || pip install pytest-timeout pytest-cov
|
||||
fi
|
||||
else
|
||||
echo "Installing fresh dependencies..."
|
||||
python3 -m venv venv
|
||||
. venv/bin/activate
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements.txt || pip install -r requirements.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements-dev.txt || pip install -r requirements-dev.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout pytest-cov || pip install pytest-timeout pytest-cov
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements.txt || \
|
||||
pip install -r requirements.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements-dev.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements-dev.txt || \
|
||||
pip install -r requirements-dev.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout pytest-cov || pip install pytest-timeout pytest-cov
|
||||
echo "Saving venv to cache $CACHE_KEY..."
|
||||
cp -a venv $CACHE_DIR/ || echo "Warning: cache save failed"
|
||||
fi
|
||||
cp -a venv $CACHE_DIR/ || echo "Warning: cache save failed"
|
||||
fi
|
||||
|
||||
- name: Run tests with coverage
|
||||
run: |
|
||||
@@ -133,9 +143,10 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
run: |
|
||||
if [ ! -d .git ]; then
|
||||
git clone --depth=1 "http://gitea:3000/${GITHUB_REPOSITORY}.git" .
|
||||
fi
|
||||
|
||||
- name: Setup Node.js
|
||||
run: |
|
||||
@@ -173,11 +184,11 @@ jobs:
|
||||
else
|
||||
echo "Cache corrupted, installing fresh..."
|
||||
rm -rf node_modules
|
||||
npm ci
|
||||
npm ci || { echo "mirror failed, trying default registry..."; npm config set registry https://registry.npmjs.org; npm ci; }
|
||||
fi
|
||||
else
|
||||
echo "Installing fresh dependencies..."
|
||||
npm ci
|
||||
npm ci || { echo "mirror failed, trying default registry..."; npm config set registry https://registry.npmjs.org; npm ci; }
|
||||
echo "Saving to cache $CACHE_KEY..."
|
||||
cp -a node_modules $CACHE_DIR/ || echo "Warning: cache save failed"
|
||||
fi
|
||||
|
||||
@@ -4,7 +4,7 @@ services:
|
||||
container_name: nas-dashboard-dev
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "127.0.0.1:4001:4000"
|
||||
- "4001:4000"
|
||||
environment:
|
||||
- DOCKER_HOST=tcp://docker-socket-proxy:2375
|
||||
- GITEA_URL=http://gitea:3000
|
||||
|
||||
Generated
+188
-1098
File diff suppressed because it is too large
Load Diff
@@ -13,11 +13,11 @@
|
||||
"devDependencies": {
|
||||
"@sveltejs/vite-plugin-svelte": "^6.2.0",
|
||||
"@testing-library/svelte": "^5.2.3",
|
||||
"@vitest/coverage-v8": "^2.1.8",
|
||||
"@vitest/coverage-v8": "^3.2.4",
|
||||
"jsdom": "^25.0.1",
|
||||
"svelte": "^5.0.0",
|
||||
"vite": "^6.3.0",
|
||||
"vitest": "^2.1.8",
|
||||
"vitest": "^3.2.4",
|
||||
"tailwindcss": "^4.0.0",
|
||||
"@tailwindcss/vite": "^4.0.0"
|
||||
},
|
||||
@@ -26,3 +26,4 @@
|
||||
"@xterm/addon-fit": "^0.10.0"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ describe('Login Component', () => {
|
||||
it('should have login button', () => {
|
||||
render(Login);
|
||||
|
||||
const loginButton = screen.getByRole('button', { name: /login/i }) ||
|
||||
screen.getByText(/login/i);
|
||||
const loginButton = screen.getByRole('button', { name: /sign in/i }) ||
|
||||
screen.getByText(/sign in/i);
|
||||
expect(loginButton).toBeTruthy();
|
||||
});
|
||||
|
||||
|
||||
@@ -75,6 +75,21 @@ global.MutationObserver = vi.fn(() => ({
|
||||
takeRecords: vi.fn(() => [])
|
||||
}));
|
||||
|
||||
// Mock Element.animate (used by Svelte transitions, not implemented in jsdom)
|
||||
Element.prototype.animate = vi.fn(() => ({
|
||||
finished: Promise.resolve(),
|
||||
cancel: vi.fn(),
|
||||
pause: vi.fn(),
|
||||
play: vi.fn(),
|
||||
reverse: vi.fn(),
|
||||
finish: vi.fn(),
|
||||
commitStyles: vi.fn(),
|
||||
persist: vi.fn(),
|
||||
addEventListener: vi.fn(),
|
||||
removeEventListener: vi.fn(),
|
||||
dispatchEvent: vi.fn(),
|
||||
}));
|
||||
|
||||
// Mock fetch
|
||||
global.fetch = vi.fn();
|
||||
|
||||
|
||||
@@ -373,6 +373,7 @@ describe('API Client - Error Handling', () => {
|
||||
});
|
||||
|
||||
it('should handle network errors', async () => {
|
||||
global.fetch.mockReset();
|
||||
global.fetch.mockRejectedValueOnce(new Error('Network error'));
|
||||
|
||||
await expect(get('/test/endpoint')).rejects.toThrow('Network error');
|
||||
|
||||
@@ -1,6 +1,31 @@
|
||||
import { defineConfig } from 'vitest/config';
|
||||
import { svelte } from '@sveltejs/vite-plugin-svelte';
|
||||
|
||||
const sveltePlugin = svelte({
|
||||
hot: !process.env.VITEST ? {
|
||||
preserveLocalState: true
|
||||
} : false,
|
||||
compilerOptions: {
|
||||
dev: true
|
||||
}
|
||||
});
|
||||
|
||||
// Vitest 3 bundles its own Vite which may not expose `server.config.server`,
|
||||
// causing the Svelte HMR plugin's configureServer to crash. Wrap it safely.
|
||||
if (process.env.VITEST) {
|
||||
const plugins = Array.isArray(sveltePlugin) ? sveltePlugin : [sveltePlugin];
|
||||
for (const p of plugins) {
|
||||
if (p.configureServer) {
|
||||
const orig = p.configureServer;
|
||||
p.configureServer = function(server) {
|
||||
try { return orig.call(this, server); } catch (e) {
|
||||
if (!(e instanceof TypeError)) throw e;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
svelte({
|
||||
@@ -16,6 +41,7 @@ export default defineConfig({
|
||||
globals: true,
|
||||
environment: 'jsdom',
|
||||
setupFiles: ['./tests/setup.js'],
|
||||
resetMocks: true,
|
||||
coverage: {
|
||||
provider: 'v8',
|
||||
reporter: ['text', 'html', 'lcov'],
|
||||
@@ -23,6 +49,7 @@ export default defineConfig({
|
||||
}
|
||||
},
|
||||
resolve: {
|
||||
conditions: ['browser'],
|
||||
alias: {
|
||||
'@': '/src'
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ fi
|
||||
|
||||
# Test 5: Container health
|
||||
echo "5. Checking container health..."
|
||||
HEALTH_STATUS=$(ssh nas "/volume1/@appstore/ContainerManager/usr/bin/docker inspect --format='{{.State.Health.Status}}' $CONTAINER" 2>/dev/null || echo "unknown")
|
||||
HEALTH_STATUS=$(docker inspect --format='{{.State.Health.Status}}' $CONTAINER 2>/dev/null || echo "unknown")
|
||||
if [ "$HEALTH_STATUS" = "healthy" ]; then
|
||||
echo "✅ Container is healthy"
|
||||
else
|
||||
@@ -68,7 +68,7 @@ fi
|
||||
|
||||
# Test 6: Check recent logs for errors
|
||||
echo "6. Checking for recent errors in logs..."
|
||||
ERROR_COUNT=$(ssh nas "/volume1/@appstore/ContainerManager/usr/bin/docker logs $CONTAINER --tail 50 2>&1 | grep -c 'ERROR' || echo 0")
|
||||
ERROR_COUNT=$(docker logs $CONTAINER --tail 50 2>&1 | grep -c 'ERROR' || echo 0)
|
||||
if [ "$ERROR_COUNT" -lt 5 ]; then
|
||||
echo "✅ No critical errors in recent logs ($ERROR_COUNT errors)"
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user