Skip to content

Commit

Permalink
✨feat : add github actions for cloud run
Browse files Browse the repository at this point in the history
  • Loading branch information
ddoddii committed Feb 22, 2024
1 parent 02cf2e0 commit 8bcc47e
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/google-cloud-run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Build and Deploy to GKE

on:
push:
branches: [ "main" ]

env:
PROJECT_ID: ${{ secrets.GKE_PROJECT }}
GAR_LOCATION: asia-northeast3
SERVICE_NAME: lookncook-service
REPOSITORY: gcr.io/solution-challenge-lookncook
IMAGE: lookncook-app-server
jobs:
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest
environment: production

permissions:
contents: 'read'
id-token: 'write'

steps:
- name: Checkout
uses: actions/checkout@v3

# Configure Workload Identity Federation and generate an access token.
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v0'
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'


- name: Docker configuration
run: |-
echo ${{steps.auth.outputs.access_token}} | docker login -u oauth2accesstoken --password-stdin https://$GAR_LOCATION-docker.pkg.dev

# Build the Docker image
- name: Build
run: |-
docker build \
--tag "$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE:$GITHUB_SHA" \
--build-arg GITHUB_SHA="$GITHUB_SHA" \
--build-arg GITHUB_REF="$GITHUB_REF" \
.
# Push the Docker image to Google Artifact Registry
- name: Publish
run: |-
docker push "$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE:$GITHUB_SHA"
# Deploy the Docker image to Google Cloud Run
- name: Deploy to Cloud Run
run: |-
gcloud run deploy $SERVICE_NAME \
--image="$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE:$GITHUB_SHA" \
--region="$GAR_LOCATION" \
--platform=managed \
--allow-unauthenticated
env:
CLOUDSDK_CORE_PROJECT: ${{ env.PROJECT_ID }}
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GCP_SA_KEY }}

0 comments on commit 8bcc47e

Please sign in to comment.