-
Notifications
You must be signed in to change notification settings - Fork 0
88 lines (73 loc) · 2.64 KB
/
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
name: 'Continuous Delivery'
on:
push:
branches:
- main
- release/*
- feature/*
jobs:
deploy:
runs-on: ubuntu-latest
env:
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
SERVICE_ACCOUNT_KEY: ${{ secrets.GCP_SA_KEY }}
GCS_BUCKET: ${{ secrets.GCS_BUCKET }}
APP_NAME: 'flight-delay-api'
REGION: 'us-central1'
outputs:
url: ${{ steps.deploy.outputs.url }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Print environment variables (debugging)
run: |
echo "PROJECT_ID=${{ env.PROJECT_ID }}"
echo "SERVICE_ACCOUNT_KEY=${{ env.SERVICE_ACCOUNT_KEY }}" | head -c 20
echo "GCS_BUCKET=${{ env.GCS_BUCKET }}"
- name: Set up Google Cloud SDK
uses: google-github-actions/[email protected]
with:
service_account_key: ${{ env.SERVICE_ACCOUNT_KEY }}
project_id: ${{ env.PROJECT_ID }}
export_default_credentials: true
- name: Configure Docker to use the gcloud command-line tool as a credential helper
run: gcloud auth configure-docker
- name: Build Docker image
run: |
docker build -t gcr.io/${{ env.PROJECT_ID }}/${{ env.APP_NAME }} . --platform linux/amd64
- name: Push Docker image
run: |
docker push gcr.io/${{ env.PROJECT_ID }}/${{ env.APP_NAME }}
- name: Deploy to Cloud Run
id: deploy
run: |
echo "Deploying to Cloud Run"
URL=$(gcloud run deploy ${{ env.APP_NAME }} \
--image gcr.io/${{ env.PROJECT_ID }}/${{ env.APP_NAME }} \
--platform managed \
--region ${{ env.REGION }} \
--allow-unauthenticated \
--set-env-vars GCS_BUCKET=${{ secrets.GCS_BUCKET }}\
--format 'value(status.url)')
echo "url=$URL" >> $GITHUB_OUTPUT
echo "Deployed to $URL"
- name: Set STRESS_URL for Makefile
run: echo "STRESS_URL=${{steps.deploy.outputs.url}}" >> $GITHUB_ENV
stress-test:
runs-on: ubuntu-latest
needs: deploy
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-test.txt
- name: Print STRESS_URL (debugging)
run: echo "STRESS_URL=${{ needs.deploy.outputs.url }}"
- name: Run stress test
env:
STRESS_URL: ${{ needs.deploy.outputs.url }}
run: |
make stress-test STRESS_URL=${{ env.STRESS_URL}}