-
Notifications
You must be signed in to change notification settings - Fork 86
60 lines (54 loc) · 2 KB
/
Copy pathcd.yml
File metadata and controls
60 lines (54 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
name: CD Pipeline
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
on:
workflow_run:
workflows: ["CI Workflow"]
types:
- completed
branches:
- main
jobs:
deploy:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
permissions:
contents: read
environment: production
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Install SSH key
uses: shimataro/ssh-key-action@v3
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
if_key_exists: replace
- name: Deploy to server
run: |
ssh -p ${{ secrets.SERVER_PORT }} -o StrictHostKeyChecking=yes -o ConnectTimeout=30 ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} << 'DEPLOY'
set -e
cd ${{ secrets.PROJECT_PATH }} || { echo "Project path not found"; exit 1; }
echo "Pulling latest changes..."
git pull origin main
echo "Rebuilding and restarting containers..."
docker compose -f devops/docker-compose.quantara.yaml up -d --build --remove-orphans
echo "Applying database migrations..."
docker compose -f devops/docker-compose.quantara.yaml exec -T backend alembic -c web_app/alembic.ini upgrade head
echo "Waiting for services to be healthy..."
for i in $(seq 1 30); do
if curl -sf http://localhost:8000/health > /dev/null 2>&1; then
echo "Backend is healthy after $((i * 2))s"
exit 0
fi
sleep 2
done
echo "ERROR: Backend failed health check after 60s!"
docker compose -f devops/docker-compose.quantara.yaml logs --tail=50
exit 1
DEPLOY
- name: Notify deployment failure
if: failure()
run: |
echo "Deployment failed! Check server logs."