add CI/CD pipeline with blue-green deployment

GitLab CI runs pytest + ruff on master/MRs, then auto-deploys via SSH.
Blue-green strategy using Docker Compose profiles with an nginx router
on port 5000 for zero-downtime switching between slots.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Deeman
2026-02-13 14:39:15 +01:00
parent 3dbdd17ddb
commit fa09fc81c9
6 changed files with 257 additions and 0 deletions

32
.gitlab-ci.yml Normal file
View File

@@ -0,0 +1,32 @@
stages:
- test
- deploy
test:
stage: test
image: python:3.12-slim
before_script:
- pip install uv
script:
- cd padelnomics && uv sync
- uv run pytest tests/ -x -q
- uv run ruff check src/ tests/
rules:
- if: $CI_COMMIT_BRANCH == "master"
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
deploy:
stage: deploy
image: alpine:latest
needs: [test]
rules:
- if: $CI_COMMIT_BRANCH == "master"
before_script:
- apk add --no-cache openssh-client
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
script:
- ssh "$DEPLOY_USER@$DEPLOY_HOST" "cd /opt/padelnomics && git pull origin master && ./deploy.sh"