-
Notifications
You must be signed in to change notification settings - Fork 0
172 lines (149 loc) · 6.06 KB
/
main.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: Main Deployment Workflow
run-name: "Main Deployment Run #${{ github.run_number }} (via @${{ github.actor }})"
concurrency:
group: "deploy"
cancel-in-progress: false
on:
push:
branches: [main]
workflow_dispatch: {}
# jscpd:ignore-start
jobs:
build_images:
name: Build Images
uses: ./.github/workflows/image_build_and_publish.yml
deploy-infra-and-services:
name: Deploy Infrastructure & Services
runs-on: ubuntu-latest
needs: [build_images]
environment:
name: production
url: "https://card.losverd.es"
# TODO: maybe don't have a static URL here? I.e.:
# url: ${{ steps.build-and-publish.outputs.site_url }}
permissions:
contents: "read"
id-token: "write"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup just
uses: taiki-e/install-action@v2
with:
tool: just
- name: Utilize .terraform cache
uses: actions/cache@v4
with:
path: terraform/.terraform
key: ${{ hashFiles('terraform/.terraform.lock.hcl') }}
- name: Read .terraform-version
id: read_tf_version
run: just set-tf-ver-output
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ steps.read_tf_version.outputs.terraform_version }}
terraform_wrapper: false
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
id: auth
with:
workload_identity_provider: "projects/567739286055/locations/global/workloadIdentityPools/los-verdes-digital-membership/providers/los-verdes-digital-membership"
service_account: "[email protected]"
access_token_scopes: "https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/sqlservice.admin"
token_format: access_token
access_token_lifetime: 1800s
- name: Plan
run: |
just tf init
just tf plan
env:
TF_VAR_website_image: "gcr.io/lv-digital-membership/website:sha-${{ needs.build_images.outputs.short_sha_tag }}"
TF_VAR_worker_image: "gcr.io/lv-digital-membership/worker:sha-${{ needs.build_images.outputs.short_sha_tag }}"
TF_VAR_management_sql_user_password: ${{ secrets.management_sql_user_password }}
- name: Apply
run: just tf apply -auto-approve
env:
TF_VAR_website_image: "gcr.io/lv-digital-membership/website:sha-${{ needs.build_images.outputs.short_sha_tag }}"
TF_VAR_worker_image: "gcr.io/lv-digital-membership/worker:sha-${{ needs.build_images.outputs.short_sha_tag }}"
TF_VAR_management_sql_user_password: ${{ secrets.management_sql_user_password }}
upload-statics-to-gcs:
name: Upload Statics to GCS
needs: deploy-infra-and-services
permissions:
contents: "read"
id-token: "write"
uses: los-verdes/digital-membership/.github/workflows/just_cloudbuild.yml@main
with:
# TODO: add a CloudFlare cache purge somewhere 'round here....
command: cloudbuild-upload-statics
apply-database-config:
name: Apply Database Configuration
runs-on: ubuntu-latest
needs: deploy-infra-and-services
permissions:
contents: "read"
id-token: "write"
outputs:
management_sql_user_name: ${{ steps.just-configure-database.outputs.management_sql_user_name }}
management_sql_user_password: ${{ steps.just-configure-database.outputs.management_sql_user_password }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup just
uses: taiki-e/install-action@v2
with:
tool: just
- name: Utilize .terraform cache
uses: actions/cache@v4
with:
path: terraform/.terraform
key: ${{ hashFiles('terraform/.terraform.lock.hcl') }}
- name: Read .terraform-version
id: read_tf_version
run: just set-tf-ver-output
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ steps.read_tf_version.outputs.terraform_version }}
terraform_wrapper: false
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
id: auth
with:
workload_identity_provider: "projects/567739286055/locations/global/workloadIdentityPools/los-verdes-digital-membership/providers/los-verdes-digital-membership"
service_account: "[email protected]"
access_token_scopes: "https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/sqlservice.admin"
token_format: access_token
access_token_lifetime: 1800s
- name: Create Google application creds secret
id: google-app-creds
run: |
creds="$(cat '${{ env.GOOGLE_APPLICATION_CREDENTIALS }}')"
echo "::add-mask::$creds"
echo "creds=$creds" | tee --append "$GITHUB_OUTPUT"
- name: Start Google Cloud SQL Proxy
uses: mattes/gce-cloudsql-proxy-action@v1
with:
creds: ${{ steps.google-app-creds.outputs.creds }}
# TODO: load instance from TF outputs...
instance: lv-digital-membership:us-central1:lv-digital-membership-6b6a7153
- name: Configure Database ACLs
id: just-configure-database
run: just configure-database
- name: TMP print sql username
run: echo ${{ steps.just-configure-database.outputs.management_sql_user_name }}
apply-database-migrations:
name: Apple Database Migrations
needs: apply-database-config
permissions:
contents: "read"
id-token: "write"
uses: los-verdes/digital-membership/.github/workflows/flask_command.yml@main
with:
command: apply-migrations
flask_env: "remote-sql"
management_sql_user_name: ${{ needs.apply-database-config.outputs.management_sql_user_name }}
secrets:
management_sql_user_password: ${{ secrets.management_sql_user_password }}
# jscpd:ignore-end