Initial commit: waitlist microservice
This commit is contained in:
97
.gitea/workflows/deploy.yaml
Normal file
97
.gitea/workflows/deploy.yaml
Normal file
@@ -0,0 +1,97 @@
|
||||
name: Test & Deploy Waitlist
|
||||
run-name: ${{ gitea.ref_name }} → Docker LXC
|
||||
|
||||
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
|
||||
|
||||
- name: Run Linter
|
||||
run: ruff check app/ tests/
|
||||
|
||||
- name: Run Tests
|
||||
run: pytest tests/ -v --tb=short
|
||||
|
||||
# ── 2. Deploy to Docker LXC 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"
|
||||
REPO_URL="http://10.0.0.119:3000/${{ 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) ──
|
||||
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/docker-compose.yml \
|
||||
/tmp/adiuvai-waitlist-deploy/requirements.txt \
|
||||
"$DEPLOY_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 (app only — keep DB running) ──
|
||||
cd "$DEPLOY_DIR"
|
||||
docker compose up -d --build --no-deps db # ensure DB is running
|
||||
docker compose build app # rebuild app image
|
||||
docker compose up -d --no-deps app # restart only app container
|
||||
|
||||
# ── Migrations ──
|
||||
docker compose exec -T app alembic upgrade head
|
||||
|
||||
# ── Health check ──
|
||||
echo "Waiting for app..."
|
||||
sleep 5
|
||||
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8001/health)
|
||||
if [ "$HTTP_CODE" -eq 200 ]; then
|
||||
echo "✅ Waitlist service is healthy (HTTP ${HTTP_CODE})"
|
||||
else
|
||||
echo "❌ Health check failed (HTTP ${HTTP_CODE})"
|
||||
docker compose logs app --tail=50
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user