Skip to content

Merge pull request #39 from KjellBerlin/github-deployment-action-1 #2

Merge pull request #39 from KjellBerlin/github-deployment-action-1

Merge pull request #39 from KjellBerlin/github-deployment-action-1 #2

name: Deploy to Google Cloud
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'temurin'
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v1
with:
credentials_json: '${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}'
- name: Configure gcloud
run: gcloud config set project ${{ secrets.GCP_PROJECT_ID }}
- name: Build with Gradle
run: ./gradlew build
- name: Build Docker image
run: |
docker build -t gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.ARTIFACT_REGISTRY_REPO }}/my-app:$GITHUB_SHA .
docker push gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.ARTIFACT_REGISTRY_REPO }}/my-app:$GITHUB_SHA
- name: Deploy to Cloud Run
run: |
gcloud run deploy ${{ secrets.CLOUD_RUN_SERVICE }} \
--image gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.ARTIFACT_REGISTRY_REPO }}/my-app:$GITHUB_SHA \
--platform managed \
--region europe-west1 \
--allow-unauthenticated \
--set-env-vars SPRING_PROFILES_ACTIVE=staging
- name: Clean up
run: docker rmi gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.ARTIFACT_REGISTRY_REPO }}/my-app:$GITHUB_SHA