Skip to content

Build and deploy on GHA #352

Build and deploy on GHA

Build and deploy on GHA #352

Workflow file for this run

name: CI
on:
pull_request:
branches:
- main
paths-ignore:
- '**/*.md'
push:
branches:
- main
paths-ignore:
- '**/*.md'
env:
TERM: dumb
jobs:
assemble-and-check:
name: Build executable jar, run unit tests and static analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '22'
- uses: gradle/actions/setup-gradle@v4
with:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
- run: ./gradlew assemble check
deploy:
name: Build and push container image to Google Artifact Registry, deploy to Cloud Run
# needs: [ assemble-and-check ]
# if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
env:
CONTAINER_IMAGE: ${{ secrets.GCP_CONTAINER_IMAGE }}
REGION: ${{ secrets.GCP_REGION }}
SERVICE_NAME: ${{ secrets.GCP_SERVICE_NAME }}
CPU: 4
MEMORY: 2Gi
MIN_INSTANCES: 0
MAX_INSTANCES: 4
REQUEST_TIMEOUT: 30s
steps:
- uses: actions/checkout@v4
- uses: graalvm/setup-graalvm@v1
with:
distribution: 'graalvm-community'
java-version: '22'
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: gradle/actions/setup-gradle@v4
with:
cache-read-only: false # TODO remove
- name: Build GraalVM native executable
run: ./gradlew nativeCompile --no-configuration-cache
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ${{ env.REGION }}-docker.pkg.dev
username: _json_key
password: ${{ secrets.GCP_CREDENTIALS_JSON }}
- name: Build and push container image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ env.CONTAINER_IMAGE }}:latest
- uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_CREDENTIALS_JSON }}
- uses: google-github-actions/setup-gcloud@v2
- name: Deploy to Cloud Run
run: |
gcloud run deploy ${{ env.SERVICE_NAME }} \
--image ${{ env.CONTAINER_IMAGE }}:latest \
--region ${{ env.REGION }} \
--cpu ${{ env.CPU }} \
--memory ${{ env.MEMORY }} \
--timeout ${{ env.REQUEST_TIMEOUT }} \
--min-instances ${{ env.MIN_INSTANCES }} \
--max-instances ${{ env.MAX_INSTANCES }} \
--platform managed \
--allow-unauthenticated