101 lines
3.6 KiB
YAML
101 lines
3.6 KiB
YAML
name: Test & Deploy Waitlist
|
|
run-name: ${{ gitea.ref_name }} → Production
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
|
|
jobs:
|
|
# ── 1. Run tests in an isolated Python container ──────────────────
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: python:3.12-slim
|
|
|
|
steps:
|
|
- name: Install git
|
|
run: apt-get update && apt-get install -y --no-install-recommends git
|
|
|
|
- name: Checkout Code
|
|
run: |
|
|
git clone --depth 1 --branch "${GITHUB_REF_NAME}" \
|
|
"http://10.0.0.119:3000/${GITHUB_REPOSITORY}.git" . || \
|
|
git clone --depth 1 "http://10.0.0.119:3000/${GITHUB_REPOSITORY}.git" . && \
|
|
git checkout "${GITHUB_SHA}"
|
|
|
|
- name: Install Dependencies
|
|
run: pip install --no-cache-dir -r requirements.txt
|
|
|
|
- name: Install Test Dependencies
|
|
run: pip install --no-cache-dir pytest pytest-asyncio httpx aiosqlite ruff
|
|
|
|
- name: Run Linter
|
|
run: ruff check app/ tests/
|
|
|
|
- name: Run Tests
|
|
run: pytest tests/ -v --tb=short
|
|
|
|
# ── 2. Deploy to production via SSH ─────────────────────────────────
|
|
deploy:
|
|
needs: test
|
|
runs-on: ubuntu-latest
|
|
if: gitea.event_name == 'push'
|
|
|
|
steps:
|
|
- name: Deploy via SSH
|
|
uses: appleboy/ssh-action@v1.0.0
|
|
with:
|
|
host: ${{ secrets.SSH_HOST }}
|
|
username: ${{ secrets.SSH_USER }}
|
|
key: ${{ secrets.SSH_KEY }}
|
|
script: |
|
|
set -e
|
|
DEPLOY_DIR="/opt/adiuvai-waitlist"
|
|
WAITLIST_DIR="$DEPLOY_DIR/waitlist"
|
|
REPO_URL="https://git.muticolturano.com/${{ gitea.repository }}.git"
|
|
TAG="${{ gitea.ref_name }}"
|
|
|
|
# ── Pull latest code ──
|
|
cd /tmp && rm -rf adiuvai-waitlist-deploy
|
|
git clone --depth 1 --branch "${TAG}" "${REPO_URL}" adiuvai-waitlist-deploy
|
|
|
|
# ── Sync source (preserve .env) ──
|
|
mkdir -p "$WAITLIST_DIR"
|
|
cp -rf /tmp/adiuvai-waitlist-deploy/app/ \
|
|
/tmp/adiuvai-waitlist-deploy/alembic/ \
|
|
/tmp/adiuvai-waitlist-deploy/alembic.ini \
|
|
/tmp/adiuvai-waitlist-deploy/Dockerfile \
|
|
/tmp/adiuvai-waitlist-deploy/requirements.txt \
|
|
"$WAITLIST_DIR/"
|
|
rm -rf /tmp/adiuvai-waitlist-deploy
|
|
|
|
# ── Verify .env ──
|
|
if [ ! -f "$DEPLOY_DIR/.env" ]; then
|
|
echo "❌ $DEPLOY_DIR/.env not found. Create it before deploying."
|
|
exit 1
|
|
fi
|
|
|
|
# ── Build & restart waitlist container ──
|
|
cd "$DEPLOY_DIR"
|
|
docker compose build waitlist
|
|
docker compose up -d --no-deps --force-recreate waitlist
|
|
|
|
# ── Migrations (runs inside the container) ──
|
|
docker compose exec -T waitlist alembic upgrade head
|
|
|
|
# ── Health check (curl with correct Host header for Caddy) ──
|
|
echo "Waiting for app to start..."
|
|
for i in 1 2 3 4 5; do
|
|
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -H "Host: adiuvai.com" http://localhost:80/health)
|
|
if [ "$HTTP_CODE" -eq 200 ]; then
|
|
echo "✅ Waitlist service is healthy (HTTP ${HTTP_CODE})"
|
|
exit 0
|
|
fi
|
|
echo " Attempt $i: HTTP ${HTTP_CODE}, retrying..."
|
|
sleep 3
|
|
done
|
|
echo "❌ Health check failed after 5 attempts"
|
|
docker compose logs waitlist --tail=50
|
|
exit 1
|