-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (75 loc) · 2.98 KB
/
dispatch_deploy.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
# This workflow build and push a Docker container to Google Artifact Registry
# and deploy it on Cloud Run when manually triggered.
name: 'Dispatch Deploy'
on:
workflow_dispatch:
inputs:
environment:
description: 'Deployment environment (e.g., dev, uat, prod, alpha)'
required: true
type: string
default: 'dev'
version:
description: 'Optional version for the deployment'
required: true
type: string
default: 'v0.0.0-env'
deploy_branch:
description: 'Branch to deploy to the environment'
required: true
type: string
default: 'main'
env:
PROJECT_ID: ${{ secrets.PROJECT_ID }}
REGION: ${{ secrets.REGION_LOC_1 }}
SERVICE: 'mapdragon'
IMAGE_NAME: 'map-dragon_img'
GCP_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS }}
jobs:
deploy:
runs-on: 'ubuntu-latest'
environment:
name: ${{ github.event.inputs.environment }}
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: 'Checkout'
uses: 'actions/checkout@v4'
with:
ref: ${{ github.event.inputs.deploy_branch }} # This branch is deployed
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ env.GCP_CREDENTIALS }}'
- name: Generate .env.${{ github.event.inputs.environment }} file
run: |
echo "VITE_CLIENT_ID = ${{ secrets.VITE_CLIENT_ID }}" > .env.${{ github.event.inputs.environment }}
echo "VITE_SEARCH_ENDPOINT = ${{ secrets.VITE_SEARCH_ENDPOINT }}" >> .env.${{ github.event.inputs.environment }}
echo "VITE_VOCAB_ENDPOINT= ${{ secrets.VITE_VOCAB_ENDPOINT }}" >> .env.${{ github.event.inputs.environment }}
echo "VITE_MAPDRAGON_VERSION= ${{ github.event.inputs.version }}" >> .env.${{ github.event.inputs.environment }}
- name: 'Docker Auth'
run: |-
gcloud auth configure-docker '${{ env.REGION }}-docker.pkg.dev'
- name: 'Build Docker Image'
run: |-
if [[ "${{ github.event.inputs.environment }}" == "prod" ]]; then
SERVICE="${{ env.SERVICE }}"
else
SERVICE="${{ env.SERVICE }}-${{ github.event.inputs.environment }}"
fi
DOCKER_TAG="${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${SERVICE}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
echo "DOCKER_TAG=${DOCKER_TAG}" >> $GITHUB_ENV
echo "SERVICE=${SERVICE}" >> $GITHUB_ENV
docker build -t "${DOCKER_TAG}" --build-arg ENV=${{ github.event.inputs.environment }} .
- name: 'Push Docker Image'
run: |-
docker push "${DOCKER_TAG}"
- name: 'Deploy to Cloud Run'
uses: 'google-github-actions/deploy-cloudrun@v2'
with:
service: ${{ env.SERVICE }}
region: '${{ env.REGION }}'
image: ${{ env.DOCKER_TAG }}
env_vars: ${{ github.event.inputs.version }}