Skip to content

Commit 0d1a951

Browse files
authored
Create deploy.yml
1 parent ee032bc commit 0d1a951

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Deploy to Cloud Run
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
7+
env:
8+
PROJECT_ID: job-tracker-pro-480917
9+
REGION: asia-south1
10+
# if not exist, create it: gcloud artifacts repositories create my-repo --repository-format=docker --location=asia-south1
11+
REPO_NAME: my-repo
12+
SERVICE_NAME: jobtracker-service
13+
IMAGE_NAME: my-java-app
14+
15+
jobs:
16+
deploy:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
# 1. Authenticate to Google Cloud
24+
- name: Google Auth
25+
id: auth
26+
uses: google-github-actions/auth@v2
27+
with:
28+
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
29+
30+
# 2. Configure Docker to use gcloud command-line tool as a credential helper
31+
- name: Docker Auth
32+
run: |
33+
gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev
34+
35+
# 3. Build and Push Container
36+
- name: Build and Push Container
37+
run: |
38+
TAG="${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO_NAME }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
39+
docker build -t $TAG .
40+
docker push $TAG
41+
echo "IMAGE_TAG=$TAG" >> $GITHUB_ENV
42+
43+
# 4. Update service.yaml with the new image tag
44+
- name: Update Service YAML
45+
run: |
46+
# Replace the hardcoded image line with the new dynamic tag
47+
sed -i "s|image: .*|image: ${{ env.IMAGE_TAG }}|g" service.yaml
48+
cat service.yaml # Optional: verify content in logs
49+
50+
# 5. Deploy to Cloud Run using the YAML
51+
- name: Deploy to Cloud Run
52+
uses: google-github-actions/deploy-cloudrun@v2
53+
with:
54+
metadata: service.yaml
55+
region: ${{ env.REGION }}

0 commit comments

Comments
 (0)