-
Notifications
You must be signed in to change notification settings - Fork 0
93 lines (81 loc) · 2.87 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
89
90
91
92
93
name: 'Continuous Delivery'
on:
pull_request: #TODO: For testing
branches:
- "main"
jobs:
build:
runs-on: ubuntu-latest
steps:
# Checkout code
- name: Checkout code
uses: actions/checkout@v3
# Authenticate to Google Cloud
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}'
# Install dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt -r requirements-dev.txt -r requirements-test.txt
# Run training script to have the model available
- name: Run training script
run: |
export PYTHONPATH=$PYTHONPATH:$(pwd)
python ./challenge/training.py
# Build and push Docker image
- name: Build and push Docker image
env:
CONTAINER_IMAGE_URL: ${{ secrets.CONTAINER_IMAGE_URL }}
GCLOUD_REGION: ${{ secrets.GCLOUD_REGION }}
run: |
gcloud auth configure-docker us-docker.pkg.dev
docker build -t $CONTAINER_IMAGE_URL:latest .
docker push $CONTAINER_IMAGE_URL:latest
deploy:
needs: build
runs-on: ubuntu-latest
steps:
# Checkout code
- name: Checkout code
uses: actions/checkout@v3
# Authenticate to Google Cloud
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}'
# Deploy container to Cloud Run and capture URL
- name: Deploy container to Cloud Run
env:
CONTAINER_IMAGE_URL: ${{ secrets.CONTAINER_IMAGE_URL }}
GCLOUD_REGION: ${{ secrets.GCLOUD_REGION }}
GCLOUD_PROJECT_ID: ${{ secrets.GCLOUD_PROJECT_ID }}
id: deploy
run: |
echo "Deployment running."
URL=$(gcloud run deploy latam-challenge \
--image=$CONTAINER_IMAGE_URL:latest \
--platform=managed \
--allow-unauthenticated \
--region=$GCLOUD_REGION \
--port=8000 \
--project=$GCLOUD_PROJECT_ID \
--format="value(status.url)")
echo "::set-output name=url::$URL"
echo "Image URL: $URL"
# Install dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt -r requirements-test.txt
# Set STRESS_URL environment variable for later use
- name: Set STRESS_URL as env variable to use later the Makefile
run: echo "STRESS_URL=${{ steps.deploy.outputs.url }}" >> $GITHUB_ENV
# Run stress tests
- name: Run stress tests
run: |
make stress-test STRESS_URL=${{ env.STRESS_URL }}