Add trunk-based dev deployment with smoke tests
Deploy to Dev / Deploy & Smoke Test (push) Failing after 17s

- Gitea Action: push to main → SSH deploy to CT114 (lisilou-dev, 192.168.1.192)
  git pull → docker compose build → up -d → health wait → smoke tests
- scripts/smoke-test.sh: 6 curl assertions covering site load, nginx health,
  API health, config serving, booking POST, and nginx routing sanity
- Replaces the non-functional registry-based deploy workflow

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-07-07 22:50:30 -06:00
parent 28d60fca04
commit 9209fbdcfc
2 changed files with 98 additions and 55 deletions
+45 -55
View File
@@ -1,68 +1,58 @@
name: Build and Deploy name: Deploy to Dev
on: on:
push: push:
branches: branches: [main]
- main
pull_request:
branches:
- main
env:
REGISTRY: your-registry.com # Update with your registry
IMAGE_NAME: lisilou-portfolio
jobs: jobs:
build: deploy:
name: Deploy & Smoke Test
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout code - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Set up Docker Buildx - name: Install SSH client
uses: docker/setup-buildx-action@v3 run: which ssh || (apt-get update -qq && apt-get install -y -qq openssh-client)
- name: Log in to Container Registry - name: Setup SSH key
if: github.event_name != 'pull_request' run: |
uses: docker/login-action@v3 mkdir -p ~/.ssh
with: echo "${{ secrets.DEV_SSH_KEY }}" > ~/.ssh/deploy_key
registry: ${{ env.REGISTRY }} chmod 600 ~/.ssh/deploy_key
username: ${{ secrets.REGISTRY_USERNAME }} ssh-keyscan -H ${{ secrets.DEV_HOST }} >> ~/.ssh/known_hosts 2>/dev/null || true
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Extract metadata - name: Deploy
id: meta run: |
uses: docker/metadata-action@v5 ssh -i ~/.ssh/deploy_key \
with: -o StrictHostKeyChecking=no \
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} -o ConnectTimeout=10 \
tags: | ${{ secrets.DEV_USER }}@${{ secrets.DEV_HOST }} \
type=ref,event=branch 'set -e
type=sha,prefix= cd /opt/lisilou-portfolio
type=raw,value=latest,enable={{is_default_branch}} git pull origin main
docker compose build
docker compose up -d
echo "Deploy complete"'
- name: Build and push Docker image - name: Wait for health check
uses: docker/build-push-action@v5 run: |
with: echo "Waiting for services..."
context: . for i in $(seq 1 24); do
push: ${{ github.event_name != 'pull_request' }} if curl -sf --max-time 4 "http://${{ secrets.DEV_HOST }}:8080/health" > /dev/null 2>&1; then
tags: ${{ steps.meta.outputs.tags }} echo "Services are up (attempt $i)"
labels: ${{ steps.meta.outputs.labels }} exit 0
cache-from: type=gha fi
cache-to: type=gha,mode=max echo " Attempt $i/24 — sleeping 5s"
sleep 5
done
echo "Health check timed out after 2 minutes"
exit 1
deploy: - name: Smoke tests
needs: build run: bash scripts/smoke-test.sh "http://${{ secrets.DEV_HOST }}:8080"
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' - name: Cleanup SSH key
steps: if: always()
- name: Deploy to server run: rm -f ~/.ssh/deploy_key
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
script: |
cd /opt/lisilou-portfolio
docker compose pull
docker compose up -d
docker image prune -f
+53
View File
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
# Usage: bash scripts/smoke-test.sh http://192.168.1.192:8080
set -uo pipefail
BASE="${1:-http://localhost:8080}"
PASS=0
FAIL=0
ok() { echo "$1"; PASS=$((PASS+1)); }
fail() { echo "$1"; FAIL=$((FAIL+1)); }
http_status() { curl -s -o /dev/null -w "%{http_code}" --max-time 8 "$1"; }
http_body() { curl -s --max-time 8 "$1"; }
echo ""
echo "Smoke tests → $BASE"
echo "────────────────────────────────────────"
# 1. Portfolio site loads
s=$(http_status "$BASE/")
[ "$s" = "200" ] && ok "GET / → 200" || fail "GET / → 200 (got $s)"
# 2. Nginx health endpoint
s=$(http_status "$BASE/health")
[ "$s" = "200" ] && ok "GET /health → 200" || fail "GET /health → 200 (got $s)"
# 3. API health
b=$(http_body "$BASE/api/health")
[[ "$b" == *'"ok":true'* ]] && ok "GET /api/health → {ok:true}" || fail "GET /api/health → {ok:true} (got: $b)"
# 4. Config file served
s=$(http_status "$BASE/config/site.json")
[ "$s" = "200" ] && ok "GET /config/site.json → 200" || fail "GET /config/site.json → 200 (got $s)"
# 5. Booking POST creates record
b=$(curl -s --max-time 8 -X POST "$BASE/api/bookings" \
-H "Content-Type: application/json" \
-d '{"client_name":"Smoke Test","client_email":"smoke@test.lisilou","session_date":"2099-12-31","session_type":"individual","session_length":"mini","location":"studio"}')
[[ "$b" == *'"id"'* ]] && ok "POST /api/bookings → returns id" || fail "POST /api/bookings → returns id (got: $b)"
# 6. Nginx does not 500 on unknown /api/ path
s=$(http_status "$BASE/api/nonexistent-route")
[ "$s" != "500" ] && ok "GET /api/unknown → not 500 (got $s)" || fail "GET /api/unknown → 500 (nginx misconfigured)"
echo "────────────────────────────────────────"
if [ $FAIL -eq 0 ]; then
echo " All $PASS tests passed ✓"
else
echo " Passed: $PASS Failed: $FAIL"
fi
echo ""
[ $FAIL -eq 0 ]