-
Notifications
You must be signed in to change notification settings - Fork 0
105 lines (87 loc) · 3.02 KB
/
google-cloudrun-docker.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
name: 'Build and Deploy to Cloud Run'
on:
push:
branches:
- main
env:
REGION: 'us-east4'
CLOUD_RUN_SERVICE_DEV: 'mayberry-mini-trucks-api-dev'
CLOUD_RUN_SERVICE_PROD: 'mayberry-mini-trucks-api-prod'
REPOSITORY_SERVICE: 'mayberry-mini-trucks-api'
IMAGE: 'mayberry-mini-trucks-api'
jobs:
build:
name: Build Image and Push Container to Registry
runs-on: 'ubuntu-latest'
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: 'Checkout'
uses: 'actions/checkout@v4'
- id: "auth"
uses: "google-github-actions/auth@v2"
with:
credentials_json: "${{ secrets.SERVICE_ACCOUNT_KEY }}"
- name: "Set up GCP SDK"
uses: "google-github-actions/setup-gcloud@v2"
- name: "Use GCP CLI"
run: "gcloud info"
- name: "Docker Auth for GCP"
run: |-
gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev --quiet
- name: 'Build and Push Container to GCP Artifact Registry'
run: |
DOCKER_TAG="${{ env.REGION }}-docker.pkg.dev/${{ vars.PROJECT_ID }}/${{ env.REPOSITORY_SERVICE }}/${{ env.IMAGE }}:${{ github.sha }}"
docker build --no-cache --tag "${DOCKER_TAG}" .
docker push "${DOCKER_TAG}"
deploy-dev:
name: Deploy Container to Cloud Run - Dev
needs: build
runs-on: 'ubuntu-latest'
permissions:
contents: 'read'
id-token: 'write'
steps:
- id: "auth"
uses: "google-github-actions/auth@v2"
with:
credentials_json: "${{ secrets.SERVICE_ACCOUNT_KEY }}"
- name: 'Deploy to Cloud Run'
uses: 'google-github-actions/deploy-cloudrun@v2'
with:
service: '${{ env.CLOUD_RUN_SERVICE_DEV }}'
region: '${{ env.REGION }}'
image: '${{ env.REGION }}-docker.pkg.dev/${{ vars.PROJECT_ID }}/${{ env.REPOSITORY_SERVICE }}/${{ env.IMAGE }}:${{ github.sha }}'
env_vars: |-
ENVIRONMENT=dev
secrets: |-
/secrets/gcp-service-account-json=gcp-service-account-json:latest
COSMOS_DB_CONNECTION_KEY=dev-cosmosdb-key:latest
- name: 'Show output'
run: |2-
echo ${{ steps.deploy.outputs.url }}
deploy-prod:
name: Deploy Container to Cloud Run - Prod
needs: deploy-dev
environment: prod
runs-on: 'ubuntu-latest'
permissions:
contents: 'read'
id-token: 'write'
steps:
- id: "auth"
uses: "google-github-actions/auth@v2"
with:
credentials_json: "${{ secrets.SERVICE_ACCOUNT_KEY }}"
- name: 'Deploy to Cloud Run'
uses: 'google-github-actions/deploy-cloudrun@v2'
with:
service: '${{ env.CLOUD_RUN_SERVICE_PROD }}'
region: '${{ env.REGION }}'
image: '${{ env.REGION }}-docker.pkg.dev/${{ vars.PROJECT_ID }}/${{ env.REPOSITORY_SERVICE }}/${{ env.IMAGE }}:${{ github.sha }}'
env_vars: |-
ENVIRONMENT=prod
- name: 'Show output'
run: |2-
echo ${{ steps.deploy.outputs.url }}