-
Notifications
You must be signed in to change notification settings - Fork 1
49 lines (49 loc) · 1.54 KB
/
gcp.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
---
name: Build and Push Image to Google Cloud Platform
on:
push:
branches: [ master ]
paths-ignore:
- 'k8s/**'
- 'docs/**'
- 'README.md'
- 'LICENSE'
- 'CHANGELOG.md'
- 'CODE_OF_CONDUCT.md'
- 'CONTRIBUTING.md'
- 'SECURITY.md'
jobs:
build-push-gcr:
name: Build and Push to GCP
runs-on: ubuntu-latest
env:
IMAGE_NAME: food-track-be
PROJECT_ID: foody-me
LOCATION: us-central1-docker.pkg.dev
REPOSITORY: foody-ar
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: benjlevesque/[email protected]
id: short-sha
with:
length: 7
- uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.SERVICE_ACCOUNT_KEY }}
- uses: google-github-actions/setup-gcloud@v2
with:
project_id: ${{ env.PROJECT_ID }}
- name: Build Docker Image
run: docker build -t $IMAGE_NAME:latest .
env:
SHORT_SHA: ${{ steps.short-sha.outputs.sha }}
- name: Configure Docker Client
run: |-
gcloud auth configure-docker $LOCATION --quiet
- name: Push Docker Image to Artifact Registry
run: |-
docker tag $IMAGE_NAME:latest $LOCATION/$PROJECT_ID/$REPOSITORY/$IMAGE_NAME:latest
docker tag $IMAGE_NAME:latest $LOCATION/$PROJECT_ID/$REPOSITORY/$IMAGE_NAME:$SHA
docker push $LOCATION/$PROJECT_ID/$REPOSITORY/$IMAGE_NAME:latest
docker push $LOCATION/$PROJECT_ID/$REPOSITORY/$IMAGE_NAME:$SHA