-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (71 loc) · 2.02 KB
/
ci.yaml
File metadata and controls
84 lines (71 loc) · 2.02 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: CI-CD Pipeline
on:
pull_request:
branches:
- develop
- main
push:
branches:
- develop
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Syntax Check
run: |
python -m py_compile main.py
- name: Docker Build Test
run: |
docker build -t test-image .
- name: Run Container Health Test
run: |
docker run -d -p 9000:8000 --name test-container test-image
sleep 8
curl --fail http://localhost:9000/health
deploy-staging:
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/develop'
steps:
- name: Deploy Staging to Azure VM
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.VM_IP }}
username: azureuser
key: ${{ secrets.SSH_KEY }}
script: |
cd staging
git pull origin develop
docker stop fastapi-staging || true
docker rm fastapi-staging || true
docker build -t fastapi-staging .
docker run -d -p 8001:8000 --name fastapi-staging fastapi-staging
deploy-prod:
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Deploy Production to Azure VM
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.VM_IP }}
username: azureuser
key: ${{ secrets.SSH_KEY }}
script: |
cd prod
git pull origin main
docker stop fastapi-prod || true
docker rm fastapi-prod || true
docker build -t fastapi-prod .
docker run -d -p 8000:8000 --name fastapi-prod fastapi-prod