6 Commits

2 changed files with 106 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
name: Deploy to Staging
# Triggered on every push to main (after PR merge).
# Runs ONLY the deploy job — not tests — so the server
# always reflects the latest main without waiting for the
# full CI suite to finish. The existing ci.yml handles lint/tests.
on:
push:
branches: [main]
concurrency:
group: deploy-backend
cancel-in-progress: true
jobs:
deploy:
name: Deploy backend + frontend to staging
runs-on: self-hosted
steps:
- name: Pull latest code
run: |
cd /opt/encoach/encoach_backend_new_v2
git fetch origin
git reset --hard origin/main
echo "Now at: $(git log -1 --oneline)"
- name: Rebuild and restart containers
run: |
cd /opt/encoach/encoach_backend_new_v2
docker compose \
-f docker-compose.yml \
-f /opt/encoach/overrides/encoach.override.yml \
up -d --build --remove-orphans
echo "Containers after deploy:"
docker ps --format "table {{.Names}}\t{{.Status}}" | grep -E "encoach-v4|encoach-frontend"
- name: Smoke test
run: |
echo "Waiting 20s for Odoo to settle..."
sleep 20
STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8069/api/health)
echo "/api/health => HTTP $STATUS"
if [ "$STATUS" != "200" ]; then
echo "WARNING: /api/health returned $STATUS (Odoo may still be starting)"
fi
FE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3000/)
echo "frontend / => HTTP $FE"
test "$FE" = "200" || exit 1

View File

@@ -0,0 +1,57 @@
name: Deploy Frontend to Staging
# Triggered on every push to main.
# Syncs this repo's source into the backend monorepo's frontend/
# directory and rebuilds the encoach-frontend Docker container.
on:
push:
branches: [main]
concurrency:
group: deploy-frontend
cancel-in-progress: true
jobs:
deploy:
name: Deploy frontend to staging
runs-on: self-hosted
steps:
- name: Sync frontend source to backend repo
run: |
FRONTEND_SRC="/opt/encoach/encoach_frontend_new_v2"
FRONTEND_DEST="/opt/encoach/encoach_backend_new_v2/frontend"
# Keep a clean clone of this repo on the server
if [ -d "$FRONTEND_SRC/.git" ]; then
git -C "$FRONTEND_SRC" fetch origin
git -C "$FRONTEND_SRC" reset --hard origin/main
else
git clone http://localhost:3003/devops/encoach_frontend_new_v2.git "$FRONTEND_SRC"
fi
echo "Syncing to backend frontend/ dir..."
rsync -a --delete \
--exclude '.git' \
--exclude 'node_modules' \
--exclude 'dist' \
--exclude 'docs' \
"$FRONTEND_SRC/" "$FRONTEND_DEST/"
echo "Latest commit: $(git -C $FRONTEND_SRC log -1 --oneline)"
- name: Rebuild frontend container
run: |
cd /opt/encoach/encoach_backend_new_v2
docker compose \
-f docker-compose.yml \
-f /opt/encoach/overrides/encoach.override.yml \
up -d --build frontend
docker ps --format "table {{.Names}}\t{{.Status}}" | grep encoach-frontend
- name: Smoke test
run: |
sleep 5
STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3000/)
echo "frontend / => HTTP $STATUS"
test "$STATUS" = "200" || exit 1
echo "Deploy successful!"