Skip to content

Commit 52c8840

Browse files
Update gcr-deploy.yml
1 parent d525911 commit 52c8840

File tree

1 file changed

+40
-50
lines changed

1 file changed

+40
-50
lines changed

.github/workflows/gcr-deploy.yml

Lines changed: 40 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,48 @@
1-
name: 'Build and Deploy to Cloud Run'
1+
name: Deploy to GCP
22

33
on:
44
push:
55
branches:
6-
- 'main'
7-
8-
env:
9-
PROJECT_ID: '${{ secrets.PROJECT_ID }}'
10-
GCR_REGION: '${{ secrets.GCR_REGION }}'
11-
GCR_SERVICE: '${{ secrets.GCR_SERVICE }}'
12-
GAR_NAME: '${{ secrets.GAR_NAME }}'
13-
GAR_REGION: '${{ secrets.GAR_REGION }}'
6+
- main
147

158
jobs:
16-
deploy:
17-
runs-on: 'ubuntu-latest'
18-
19-
permissions:
20-
contents: 'read'
21-
id-token: 'write'
9+
build-and-deploy:
10+
runs-on: ubuntu-latest
2211

2312
steps:
24-
- name: 'Checkout'
25-
uses: 'actions/checkout@v4'
26-
27-
- name: 'Authenticate to GCP'
28-
id: 'auth'
29-
uses: 'google-github-actions/auth@v2'
30-
with:
31-
credentials_json: '${{ secrets.GCP_CREDS }}'
32-
33-
- name: Set up Cloud SDK
34-
uses: 'google-github-actions/setup-gcloud@v2'
35-
36-
- name: 'Docker Auth To GAR'
37-
run: |
38-
gcloud auth configure-docker "${{env.GAR_REGION}}-docker.pkg.dev"
39-
40-
- name: 'Build and Push To GAR'
41-
run: |-
42-
DOCKER_TAG="gcr.io/${{ env.PROJECT_ID }}/gcp-automation:latest"
43-
docker build --tag "${DOCKER_TAG}" .
44-
docker push "${DOCKER_TAG}"
45-
46-
- name: Deploy to Cloud Run
47-
run: |
48-
echo SERVICE_NAME ${{ env.GCR_SERVICE }}
49-
gcloud run deploy ${{ env.GCR_SERVICE }} \
50-
--image ${{ env.GAR_REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.GAR_NAME }}/${{ env.GCR_SERVICE }}:${{ github.sha }} \
51-
--platform managed \
52-
--region ${{ env.GCR_REGION }} \
53-
--port 5757 \
54-
--allow-unauthenticated
55-
56-
- name: 'Show output'
57-
run: |2-
58-
echo ${{ steps.deploy.outputs.url }}
13+
- name: Checkout code
14+
uses: actions/checkout@v3
15+
16+
- name: Set up Docker Buildx
17+
uses: docker/setup-buildx-action@v2
18+
19+
- name: Authenticate to Google Cloud
20+
uses: google-github-actions/auth@v2
21+
with:
22+
credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
23+
24+
- name: Set up Google Cloud SDK
25+
uses: google-github-actions/setup-gcloud@v1
26+
with:
27+
project_id: ${{ secrets.GCP_PROJECT_ID }}
28+
service_account_key: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
29+
30+
- name: Configure Docker to use the Google Cloud Registry
31+
run: gcloud auth configure-docker
32+
33+
- name: Build the Docker image
34+
run: |
35+
docker build -t gcr.io/${{ secrets.GCP_PROJECT_ID }}/gcp-automation:latest .
36+
37+
- name: Push the Docker image to GCP Container Registry
38+
run: |
39+
docker push gcr.io/${{ secrets.GCP_PROJECT_ID }}/gcp-automation:latest
40+
41+
- name: Deploy to Cloud Run
42+
run: |
43+
gcloud run deploy gcp-automation \
44+
--image gcr.io/${{ secrets.GCP_PROJECT_ID }}/gcp-automation:latest \
45+
--platform managed \
46+
--region us-central1 \
47+
--allow-unauthenticated \
48+
--port 8080

0 commit comments

Comments
 (0)