-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (72 loc) · 2.82 KB
/
publish-gcs.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
name: Publish and deploy to Google Cloud Services
on:
release:
types: [published]
workflow_dispatch:
permissions:
contents: read
env:
TAG: ${{ github.ref_name }}
jobs:
publish:
runs-on: ubuntu-latest
environment:
name: Google Cloud Services
steps:
- name: Checkout
uses: actions/checkout@v4
- id: 'auth'
uses: 'google-github-actions/auth@v2'
with:
project_id: ${{ secrets.PROJECT_ID }}
credentials_json: ${{ secrets.ARTIFACT_REGISTRY_PRIVATE_KEY }}
- name: Setup Google Cloud Services
uses: google-github-actions/setup-gcloud@v2
with:
project_id: ${{ secrets.PROJECT_ID }}
- name: Setup Docker with the Artifact Registry
run: gcloud auth configure-docker ${{ vars.REGION }}-docker.pkg.dev
- name: Build Docker image
run: |
docker build -t ${{ vars.REGION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/${{ vars.REPOSITORY }}/${{ vars.IMAGE }}:${{ env.TAG }} --no-cache .
- name: Push Docker image to the Artifact Registry
run: |
docker push ${{ vars.REGION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/${{ vars.REPOSITORY }}/${{ vars.IMAGE }}:${{ env.TAG }}
deploy:
runs-on: ubuntu-latest
environment:
name: Google Cloud Services
steps:
- id: 'auth'
uses: 'google-github-actions/auth@v2'
with:
project_id: ${{ secrets.PROJECT_ID }}
credentials_json: ${{ secrets.CLOUD_RUN_PRIVATE_KEY }}
- name: Setup Google Cloud Services
uses: google-github-actions/setup-gcloud@v2
with:
project_id: ${{ secrets.PROJECT_ID }}
- name: Wait for the Docker image to be available in the Artifact Registry
run: |
AVAILABLE=false
for i in {1..36}; do
if gcloud artifacts docker images describe ${{ vars.REGION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/${{ vars.REPOSITORY }}/${{ vars.IMAGE }}:${{ env.TAG }}; then
echo "The Docker image is available in the Artifact Registry."
AVAILABLE=true
break
else
echo "Waiting for the Docker image to be available..."
sleep 10
fi
done
if [ "$AVAILABLE" = false ]; then
echo "ERROR: Unable to deploy to Cloud Run. The Docker image is not available in the Artifact Registry. Login to the Google Cloud console for more information."
exit 1
fi
- name: Deploy to Cloud Run
run: |
gcloud run deploy ${{ vars.SERVICE }} \
--image=${{ vars.REGION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/${{ vars.REPOSITORY }}/${{ vars.IMAGE }}:${{ env.TAG }} \
--region=${{ vars.REGION }} \
--platform=managed \
--allow-unauthenticated