Skip to content

Build Ontology Service & Deploy Cloud Run #11

Build Ontology Service & Deploy Cloud Run

Build Ontology Service & Deploy Cloud Run #11

name: Build Ontology Service & Deploy Cloud Run
on:
workflow_dispatch:
inputs:
ontology:
description: 'The ontology to use.'
required: true
type: string
international:
description: 'Is the ontology babelon international?'
default: false
type: boolean
load:
description: 'Should load the data?'
default: true
type: boolean
tag:
description: 'The data tag'
type: string
workflow_call:
inputs:
ontology:
description: 'The ontology to use.'
required: true
type: string
international:
description: 'Is the ontology babelon international?'
default: false
type: boolean
load:
description: 'Should load the data?'
default: true
type: boolean
tag:
description: 'The data tag'
type: string
env:
GCLOUD_PROJECT_ID: ${{ secrets.GCLOUD_PROJECT_ID }}
GCLOUD_REGION: us-east1
GCLOUD_GCR: us-docker.pkg.dev
GCLOUD_REGISTRY_PROJECT_ID: ${{ secrets.GCLOUD_REGISTRY_PROJECT_ID }}
GCLOUD_REGISTRY_IMAGE_ENV: docker
GCLOUD_REGISTRY_IMAGE_PROJECT: ontology
ONTOLOGY: ${{ inputs.ontology }}
ONTOLOGY_SERVICE_LOAD: ${{ inputs.load }}
ONTOLOGY_SERVICE_INTERNATIONAL: ${{ inputs.international }}
SERVICE_NAME: ontology-service-${{ inputs.ontology }}
SERVICE_TAG: ${{ inputs.tag }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
~/.m2/repository
key: ${{ runner.os }}-gradle-test-${{ hashFiles('**/*.gradle') }}
restore-keys: |
${{ runner.os }}-gradle-test-
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17
- name: Authenticate to Google Cloud
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GCLOUD_SA_KEY }}'
- name: Setup Google Cloud CLI
uses: 'google-github-actions/setup-gcloud@v1'
- name: Get project version
run: |
echo "PROJECT_VERSION=$(./gradlew properties -q | awk '/^version:/ {print $2}')" >> $GITHUB_ENV
- name: Get ontology data
run: |
bash ontology.sh ${ONTOLOGY}
- name: Docker Login
run: |
gcloud auth configure-docker "${GCLOUD_GCR}"
- name: Build And Push Docker Image
env:
TESTCONTAINERS_RYUK_DISABLED: true
run: |
export DOCKER_IMAGE=`echo "${GCLOUD_GCR}/${GCLOUD_REGISTRY_PROJECT_ID}/${GCLOUD_REGISTRY_IMAGE_ENV}/${GCLOUD_REGISTRY_IMAGE_PROJECT}/$SERVICE_NAME:$SERVICE_TAG" | sed -e 's#//#/#' -e 's#^/##'`
./gradlew check dockerPush --no-daemon
- name: Tag Artifact Registry
run: |
gcloud artifacts docker tags add "${GCLOUD_GCR}/${GCLOUD_REGISTRY_PROJECT_ID}/${GCLOUD_REGISTRY_IMAGE_ENV}/${GCLOUD_REGISTRY_IMAGE_PROJECT}/$SERVICE_NAME:$SERVICE_TAG" "${GCLOUD_GCR}/${GCLOUD_REGISTRY_PROJECT_ID}/${GCLOUD_REGISTRY_IMAGE_ENV}/${GCLOUD_REGISTRY_IMAGE_PROJECT}/$SERVICE_NAME:latest"
gcloud artifacts docker tags add "${GCLOUD_GCR}/${GCLOUD_REGISTRY_PROJECT_ID}/${GCLOUD_REGISTRY_IMAGE_ENV}/${GCLOUD_REGISTRY_IMAGE_PROJECT}/$SERVICE_NAME:$SERVICE_TAG" "${GCLOUD_GCR}/${GCLOUD_REGISTRY_PROJECT_ID}/${GCLOUD_REGISTRY_IMAGE_ENV}/${GCLOUD_REGISTRY_IMAGE_PROJECT}/$SERVICE_NAME:$PROJECT_VERSION"
- name: Deploy Cloud Run
run: |
DOCKER_IMAGE_REPOSITORY=$(docker images --format "{{.Repository}}" | grep ontology-service)
DOCKER_IMAGE=$(docker images --format "{{.Repository}}:{{.Tag}}" "${DOCKER_IMAGE_REPOSITORY}" )
gcloud run deploy $SERVICE_NAME --quiet \
--image "${DOCKER_IMAGE}" --project "${GCLOUD_PROJECT_ID}" \
--region "${GCLOUD_REGION}" --platform managed --allow-unauthenticated --format json \
--memory 4Gi --cpu 2
echo "Invoke endpoint:"
gcloud run services list --platform managed --format json | jq -r \
'.[] | select(.metadata.name == "google-cloud-run-maven-test") | .status.address.url'