axel-op / package-java-google-cloud-function

Package a Java Google Cloud Function

Repository from Github https://github.comaxel-op/package-java-google-cloud-functionRepository from Github https://github.comaxel-op/package-java-google-cloud-function

Package a Google Cloud Function in Java

A GitHub Action to package a Google Cloud Function in Java with Maven.

Google Cloud Functions in Java should be packaged as an Uber JAR.

The maven-shade-plugin is used to build the Uber JAR. While configuring it in the pom.xml is the recommended way to use it, here we execute it from the command line so the pom.xml doesn't have to be edited.

Inputs/Outputs

  • The input working-directory is optional and indicates where is the root directory of your function.
  • The output deployment-directory is an absolute path to the directory containing the JAR to deploy (see usage in the example below).
  • The output deployment-file is an absolute path to the ZIP file that should be deployed in case of a ZIP deployment with Cloud Storage.

Example workflow

This GitHub Actions workflow shows how to deploy a Google Cloud Function using the GitHub Action google-github-actions/deploy-cloud-functions:

name: Example workflow

on:
  push:
    branches:
      - main

jobs:
  deploy-google-cloud-function:
    runs-on: ubuntu-latest
    env:
      REGION: europe-west1
      FUNCTION_NAME: name-of-function
      ENTRYPOINT: com.example.Entrypoint
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-java@v2
        with:
          java-version: 11
          distribution: adopt
      - uses: axel-op/package-java-google-cloud-function@main
        id: package
      - name: Authenticate on Google Cloud
        uses: google-github-actions/auth@v0
        with:
          credentials_json: ${{ secrets.GCLOUD_SERVICE_ACCOUNT }}
      - name: Deploy on Google Cloud
        id: deploy
        uses: google-github-actions/deploy-cloud-functions@v0
        with:
          name: ${{ env.FUNCTION_NAME }}
          region: ${{ env.REGION }}
          source_dir: ${{ steps.package.outputs.deployment-directory }}
          entry_point: ${{ env.ENTRYPOINT }}
          runtime: java11

The Google Cloud documentation describes all the possible ways to deploy your function.

About

Package a Java Google Cloud Function

License:MIT License


Languages

Language:Shell 100.0%