- Enhance ci.yml: add collector-worker tests, Python 3 for ingest-api contract checker, lint/typecheck for all services, per-service Docker Buildx builds, and failure webhook notification job - Add deploy.yml: workflow_run trigger on CI pass; staging auto-deploy via SSH; production deploy gated by manual environment approval; success/failure notifications for both environments - Update docs/CI_PIPELINE.md: document full pipeline, required secrets, Gitea environment setup, manual deploy procedure, and failure handling Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
125 lines
4.4 KiB
YAML
125 lines
4.4 KiB
YAML
name: Deploy
|
|
|
|
on:
|
|
workflow_run:
|
|
workflows:
|
|
- CI
|
|
types:
|
|
- completed
|
|
branches:
|
|
- master
|
|
|
|
jobs:
|
|
deploy-staging:
|
|
name: Deploy to staging
|
|
runs-on: ubuntu-latest
|
|
environment: staging
|
|
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Setup SSH key
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
echo "${{ secrets.STAGING_SSH_KEY }}" > ~/.ssh/deploy_key
|
|
chmod 600 ~/.ssh/deploy_key
|
|
ssh-keyscan -p "${{ secrets.STAGING_PORT || '22' }}" "${{ secrets.STAGING_HOST }}" >> ~/.ssh/known_hosts
|
|
|
|
- name: Deploy to staging
|
|
env:
|
|
HOST: ${{ secrets.STAGING_HOST }}
|
|
PORT: ${{ secrets.STAGING_PORT || '22' }}
|
|
USER: ${{ secrets.STAGING_USER }}
|
|
run: |
|
|
ssh -i ~/.ssh/deploy_key -p "$PORT" "$USER@$HOST" bash -s << 'REMOTE'
|
|
set -e
|
|
cd /opt/bitreport/errors.bitreport.pt
|
|
git fetch origin master
|
|
git reset --hard origin/master
|
|
docker compose up -d --build ingest-api collector-worker admin-ui
|
|
docker compose ps
|
|
echo "Staging deploy complete: $(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
REMOTE
|
|
|
|
- name: Notify staging deploy success
|
|
if: success()
|
|
env:
|
|
WEBHOOK_URL: ${{ secrets.NOTIFY_WEBHOOK_URL }}
|
|
SHA: ${{ github.sha }}
|
|
REPO: ${{ github.repository }}
|
|
run: |
|
|
[ -n "$WEBHOOK_URL" ] && curl -fsSL -X POST "$WEBHOOK_URL" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"text\":\"✅ Staging deploy succeeded\\nRepo: *${REPO}*\\nCommit: \`${SHA}\`\"}" \
|
|
|| true
|
|
|
|
- name: Notify staging deploy failure
|
|
if: failure()
|
|
env:
|
|
WEBHOOK_URL: ${{ secrets.NOTIFY_WEBHOOK_URL }}
|
|
SHA: ${{ github.sha }}
|
|
REPO: ${{ github.repository }}
|
|
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
|
run: |
|
|
[ -n "$WEBHOOK_URL" ] && curl -fsSL -X POST "$WEBHOOK_URL" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"text\":\"❌ Staging deploy FAILED\\nRepo: *${REPO}*\\nCommit: \`${SHA}\`\\nRun: ${RUN_URL}\"}" \
|
|
|| true
|
|
|
|
deploy-production:
|
|
name: Deploy to production
|
|
runs-on: ubuntu-latest
|
|
environment: production
|
|
needs: deploy-staging
|
|
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Setup SSH key
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
echo "${{ secrets.PROD_SSH_KEY }}" > ~/.ssh/deploy_key
|
|
chmod 600 ~/.ssh/deploy_key
|
|
ssh-keyscan -p "${{ secrets.PROD_PORT || '22' }}" "${{ secrets.PROD_HOST }}" >> ~/.ssh/known_hosts
|
|
|
|
- name: Deploy to production
|
|
env:
|
|
HOST: ${{ secrets.PROD_HOST }}
|
|
PORT: ${{ secrets.PROD_PORT || '22' }}
|
|
USER: ${{ secrets.PROD_USER }}
|
|
run: |
|
|
ssh -i ~/.ssh/deploy_key -p "$PORT" "$USER@$HOST" bash -s << 'REMOTE'
|
|
set -e
|
|
cd /opt/bitreport/errors.bitreport.pt
|
|
git fetch origin master
|
|
git reset --hard origin/master
|
|
docker compose up -d --build ingest-api collector-worker admin-ui
|
|
docker compose ps
|
|
echo "Production deploy complete: $(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
REMOTE
|
|
|
|
- name: Notify production deploy success
|
|
if: success()
|
|
env:
|
|
WEBHOOK_URL: ${{ secrets.NOTIFY_WEBHOOK_URL }}
|
|
SHA: ${{ github.sha }}
|
|
REPO: ${{ github.repository }}
|
|
run: |
|
|
[ -n "$WEBHOOK_URL" ] && curl -fsSL -X POST "$WEBHOOK_URL" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"text\":\"🚀 Production deploy succeeded\\nRepo: *${REPO}*\\nCommit: \`${SHA}\`\"}" \
|
|
|| true
|
|
|
|
- name: Notify production deploy failure
|
|
if: failure()
|
|
env:
|
|
WEBHOOK_URL: ${{ secrets.NOTIFY_WEBHOOK_URL }}
|
|
SHA: ${{ github.sha }}
|
|
REPO: ${{ github.repository }}
|
|
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
|
run: |
|
|
[ -n "$WEBHOOK_URL" ] && curl -fsSL -X POST "$WEBHOOK_URL" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"text\":\"🔥 Production deploy FAILED\\nRepo: *${REPO}*\\nCommit: \`${SHA}\`\\nRun: ${RUN_URL}\"}" \
|
|
|| true
|