-
Notifications
You must be signed in to change notification settings - Fork 0
119 lines (96 loc) · 3.47 KB
/
deploy-infrastructure.yaml
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
name: Deploy infrastructure
on:
workflow_dispatch:
env:
# Appended to all the infrastructure components
RANDOM_SUFFIX: '568de2'
jobs:
deploy-infra:
name: 'Deploy infrastructure'
runs-on: 'ubuntu-latest'
defaults:
run:
working-directory: 'infrastructure'
outputs:
data_mock_trigger: '${{ steps.get_outputs.outputs.trigger_topic }}'
data_mock_payload: '${{ steps.get_outputs.outputs.payload_topic }}'
steps:
- uses: 'actions/checkout@v3'
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1'
with:
create_credentials_file: 'true'
credentials_json: '${{ secrets.GOOGLE_CLOUD }}'
- name: 'Set up Terraform'
uses: 'hashicorp/setup-terraform@v2'
with:
terraform_wrapper: false
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v1'
with:
version: '>= 363.0.0'
- name: 'Set up variables'
run: |
set -euo pipefail
PROJECT_NUMBER=$(gcloud projects describe $GCLOUD_PROJECT --format json | jq -r '.projectNumber')
echo "project_id = \"$GCLOUD_PROJECT\"" >> terraform.tfvars
echo "project_number = \"$PROJECT_NUMBER\"" >> terraform.tfvars
echo "random_suffix = \"$RANDOM_SUFFIX\"" >> terraform.tfvars
- name: 'Install Python dependencies'
run: |
set -euo pipefail
python -m pip install --upgrade pip
pip install -r requirements.txt
working-directory: '.'
- name: 'Set up local data'
run: 'doit data'
working-directory: '.'
- name: 'Initialize Terraform'
run: 'terraform init -input=false'
- name: 'Plan infrastructure'
run: 'terraform plan -out=tfplan -input=false'
- name: 'Apply infrastructure'
run: 'terraform apply -input=false tfplan'
- id: 'get_outputs'
name: 'Save Terraform outputs'
run: |
set -euo pipefail
echo "trigger_topic=$(terraform output -raw trigger_topic)" >> "$GITHUB_OUTPUT"
echo "payload_topic=$(terraform output -raw payload_topic)" >> "$GITHUB_OUTPUT"
deploy-functions:
name: 'Deploy Cloud Functions'
runs-on: 'ubuntu-latest'
needs: 'deploy-infra'
env:
TRIGGER_TOPIC: '${{ needs.deploy-infra.outputs.data_mock_trigger }}'
PAYLOAD_TOPIC: '${{ needs.deploy-infra.outputs.data_mock_payload }}'
steps:
- uses: 'actions/checkout@v3'
- name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GOOGLE_CLOUD }}'
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v1'
with:
version: '>= 363.0.0'
- name: 'Deploy Cloud Function'
uses: 'google-github-actions/deploy-cloud-functions@v1'
with:
name: 'data-mock-${{ env.RANDOM_SUFFIX }}'
description: 'Function producing mocked data'
runtime: 'python310'
entry_point: 'produce'
memory_mb: 1024
region: 'europe-west1'
env_vars: 'TOPIC=${{ env.PAYLOAD_TOPIC }},COUNT=100'
labels: 'owner=matkob,purpose=mlops-demo,type=mock'
source_dir: 'infrastructure/functions/data-mock'
timeout: 10
max_instances: 1
event_trigger_type: 'providers/cloud.pubsub/eventTypes/topic.publish'
event_trigger_resource: '${{ env.TRIGGER_TOPIC }}'