-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (77 loc) · 2.57 KB
/
ci-cd.yml
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
85
86
87
88
89
90
91
92
93
94
95
96
97
name: CI/CD
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
ALGORITHM: ${{ secrets.ALGORITHM }}
ACCESS_TOKEN_EXPIRE_MINUTES: ${{ secrets.ACCESS_TOKEN_EXPIRE_MINUTES }}
ENVIRONMENT: ${{ secrets.ENVIRONMENT }}
INSTANCE_CONNECTION_NAME: ${{ secrets.INSTANCE_CONNECTION_NAME }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASS: ${{ secrets.DB_PASS }}
DB_NAME: ${{ secrets.DB_NAME }}
WORKDAY_CUT_OFF_TIME: ${{ secrets.WORKDAY_CUT_OFF_TIME }}
MINIMUM_WORKING_HOURS: ${{ secrets.MINIMUM_WORKING_HOURS }}
HOLIDAYS_API_URL: ${{ secrets.HOLIDAYS_API_URL }}
HOLIDAYS_API_KEY: ${{ secrets.HOLIDAYS_API_KEY }}
COUNTRY: ${{ secrets.COUNTRY }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Cache pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run tests
run: python -m pytest
deploy:
needs: test
runs-on: ubuntu-latest
permissions:
contents: "read"
id-token: "write"
env:
IMAGE_NAME: gcr.io/${{secrets.PROJECT_ID}}/attendance-system-backend
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{secrets.WORKLOAD_IDENTITY_PROVIDER_LOCATION}}
service_account: ${{secrets.SERVICE_ACCOUNT}}
- name: Configure Docker
run: gcloud auth configure-docker --quiet
- name: Build Docker image
run: docker build . -t $IMAGE_NAME --cache-from $IMAGE_NAME
- name: Push Docker image
run: docker push $IMAGE_NAME
- id: deploy
name: Deploy Docker image
uses: "google-github-actions/deploy-cloudrun@v2"
with:
image: ${{ env.IMAGE_NAME }}
region: asia-east1
service: attendance-system-backend
flags: --port=8000
- name: Test URL
run: curl "${{ steps.deploy.outputs.url }}"