-
-
Notifications
You must be signed in to change notification settings - Fork 0
122 lines (115 loc) · 4.62 KB
/
deploy.yml
File metadata and controls
122 lines (115 loc) · 4.62 KB
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
name: Deploy
permissions:
contents: read
id-token: write
on:
push:
branches: [main]
workflow_dispatch:
inputs:
environment:
description: 'Environment to deploy to ("prod" or "test")'
type: environment
default: test
required: true
env:
BACKEND_IMAGE_REF: us-west1-docker.pkg.dev/${{ secrets.GCP_PROJECT_SLUG }}/firetower-docker/firetower:${{ github.sha }}
STATIC_IMAGE_REF: us-west1-docker.pkg.dev/${{ secrets.GCP_PROJECT_SLUG }}/firetower-docker/nginx:${{ github.sha }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Authenticate with GCP
uses: 'google-github-actions/auth@v3'
with:
project_id: ${{ secrets.GCP_PROJECT_SLUG }}
workload_identity_provider: projects/${{ secrets.GCP_PROJECT_NUM }}/locations/global/workloadIdentityPools/github/providers/github-prvdr
- name: Login to Artifact Registry
run: gcloud auth configure-docker us-west1-docker.pkg.dev
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push (backend)
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ env.BACKEND_IMAGE_REF }}
file: docker/backend.Dockerfile
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push (static assets)
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ env.STATIC_IMAGE_REF }}
file: docker/static.Dockerfile
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
needs: [build]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Authenticate with GCP
uses: 'google-github-actions/auth@v3'
with:
project_id: ${{ secrets.GCP_PROJECT_SLUG }}
workload_identity_provider: projects/${{ secrets.GCP_PROJECT_NUM }}/locations/global/workloadIdentityPools/github/providers/github-prvdr
- name: deploy-test-db-migration
if: ${{ inputs.environment == 'test' }}
uses: "google-github-actions/deploy-cloudrun@v3"
with:
job: firetower-test-db-migration
project_id: ${{ secrets.GCP_PROJECT_SLUG }}
region: us-west1
image: ${{ env.BACKEND_IMAGE_REF }}
wait: true
- name: deploy-test
if: ${{ inputs.environment == 'test' }}
uses: "google-github-actions/deploy-cloudrun@v3"
with:
service: firetower-test
project_id: ${{ secrets.GCP_PROJECT_SLUG }}
region: us-west1
# NOTE: we use flags here because the action does not natively support updating multiple containers.
flags: >
--container nginx --image "${{ env.STATIC_IMAGE_REF }}" --port 80
--container firetower-backend --image "${{ env.BACKEND_IMAGE_REF }}"
- name: deploy-test-slack-bot
if: ${{ inputs.environment == 'test' }}
uses: "google-github-actions/deploy-cloudrun@v3"
with:
service: firetower-slack-app-test
project_id: ${{ secrets.GCP_PROJECT_SLUG }}
region: us-west1
image: ${{ env.BACKEND_IMAGE_REF }}
- name: deploy-prod-db-migration
if: ${{ github.ref == 'refs/heads/main' && ((!inputs.environment) || inputs.environment == 'prod') }}
uses: "google-github-actions/deploy-cloudrun@v3"
with:
job: firetower-prod-db-migration
project_id: ${{ secrets.GCP_PROJECT_SLUG }}
region: us-west1
image: ${{ env.BACKEND_IMAGE_REF }}
wait: true
- name: deploy-prod
if: ${{ github.ref == 'refs/heads/main' && ((!inputs.environment) || inputs.environment == 'prod') }}
uses: "google-github-actions/deploy-cloudrun@v3"
with:
service: firetower
project_id: ${{ secrets.GCP_PROJECT_SLUG }}
region: us-west1
# NOTE: we use flags here because the action does not natively support updating multiple containers.
flags: >
--container nginx --image "${{ env.STATIC_IMAGE_REF }}" --port 80
--container firetower-backend --image "${{ env.BACKEND_IMAGE_REF }}"
- name: deploy-prod-slack-bot
if: ${{ github.ref == 'refs/heads/main' && ((!inputs.environment) || inputs.environment == 'prod') }}
uses: "google-github-actions/deploy-cloudrun@v3"
with:
service: firetower-slack-app
project_id: ${{ secrets.GCP_PROJECT_SLUG }}
region: us-west1
image: ${{ env.BACKEND_IMAGE_REF }}