-
Notifications
You must be signed in to change notification settings - Fork 2
57 lines (49 loc) · 2.53 KB
/
build_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
name: Build and Deploy
on:
push:
branches:
- main
- next
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Setup gcloud
uses: google-github-actions/setup-gcloud@v2
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
version: 'latest'
- name: Build and Push Docker image for App
run: |
gcloud builds submit --tag gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ vars.IMAGE_NAME }}:${{ github.sha }} .
- name: Deploy App to Cloud Run
run: |
gcloud run deploy ${{ vars.IMAGE_NAME }} \
--image gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ vars.IMAGE_NAME }}:${{ github.sha }} \
--platform managed --region ${{ vars.REGION }} \
--allow-unauthenticated \
--set-env-vars "^##^API_VERSION=${{ vars.API_VERSION }}##PROTOCOL=${{ vars.PROTOCOL }}##DOMAIN=${{ vars.DOMAIN }}##AVAILABLE_BUCKETS=${{ vars.AVAILABLE_BUCKETS }}"
- name: Map Custom Domain for Apps
run: |
set +e # Disable immediate exit on error
CREATE_OUTPUT=$(gcloud -q beta run integrations create --type=custom-domains --region=${{ vars.REGION }} --parameters='set-mapping=${{ vars.DOMAIN }}:${{ vars.IMAGE_NAME }}' 2>&1)
CREATE_STATUS=$?
set -e # Re-enable immediate exit on error
if [ $CREATE_STATUS -ne 0 ]; then
echo "Attempt to create domain mapping failed: $CREATE_OUTPUT"
if echo "$CREATE_OUTPUT" | grep -q "Integration with name \[custom-domains\] already exists"; then
echo "Domain already exists, attempting to update..."
gcloud -q beta run integrations update custom-domains --region=${{ vars.REGION }} --parameters='set-mapping=${{ vars.DOMAIN }}:${{ vars.IMAGE_NAME }}'
else
echo "Failed due to an unexpected reason. Exiting with status code $CREATE_STATUS"
exit $CREATE_STATUS
fi
else
echo "Domain mapping created successfully."
fi