Skip to content

Commit

Permalink
build(Infra): Adds infrastructure/build workflow for GEE tile server …
Browse files Browse the repository at this point in the history
…cloud function (using a placeholder function)
  • Loading branch information
KevSanchez committed Jun 6, 2024
1 parent 6af7260 commit f96ff8c
Show file tree
Hide file tree
Showing 21 changed files with 4,867 additions and 5 deletions.
52 changes: 52 additions & 0 deletions .github/actions/build-and-deploy-cloud-function/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Build And Deploy to Cloud Run
description: Build And Deploy to Cloud Run
inputs:
GCP_SA_KEY:
description: "Service Account Key to log into GCP"
required: true
REGION:
description: "GCP Region"
required: true
CLOUD_FUNCTION_NAME:
description: "Cloud Function Name"
required: true
CLOUD_FUNCTION_PATH:
description: "Path to the source code of the Cloud Function to be deployed (./cloudfunction/someFunction ...)"
required: true
DRY_RUN:
description: "Makes the action work in Dry Run Mode"
required: false
default: "false" # WARNING Input type is not supported in composite actions. Must treat it as a string

#NOTE Actions needs to specify the shell to use on every steps that uses "runs:" https://stackoverflow.com/questions/71041836/github-actions-required-property-is-missing-shell

outputs:
url:
description: url
value: ${{steps.deploy.outputs.url}}

runs:
using: "composite"
steps:
- name: Google Auth
id: auth
uses: 'google-github-actions/auth@v2'
with:
credentials_json: "${{ inputs.GCP_SA_KEY }}"
token_format: 'access_token'
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v2'
with:
version: '>= 363.0.0'
#- name: 'Use gcloud CLI'
# shell: bash
#run: 'gcloud info'
- name: 'Deploy to gen2 cloud function'
if: ${{ inputs.DRY_RUN == 'false' || inputs.DRY_RUN == ''}}
shell: bash
#NOTE .env file must be in YAML format
run: |
gcloud functions deploy ${{ inputs.CLOUD_FUNCTION_NAME }} \
--gen2 \
--region=${{ inputs.REGION }} \
--source=${{ inputs.CLOUD_FUNCTION_PATH}} \
63 changes: 63 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ on:
paths:
- 'client/**'
- 'cms/**'
- 'cloud_functions/**'
- '.github/workflows/*'
- 'infrastructure/**'

Expand Down Expand Up @@ -232,3 +233,65 @@ jobs:
- name: Show Output
if: ${{ steps.applicable_check.outputs.flag }}
run: echo ${{ steps.build_and_deploy.outputs.url || 'No URL generated' }}

deploy_cloud_function:
# Add 'id-token' with the intended permissions for workload identity federation
permissions:
contents: 'read'
id-token: 'write'

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: dorny/paths-filter@v3
id: cf-changes
with:
filters: |
cloud_function:
- 'cloud_functions/**'
- '.github/workflows/**'
- name: Applicable check
id: applicable_check
run: |
{
echo "flag=${{ github.event_name == 'workflow_dispatch' || steps.cf-changes.outputs.cloud_function == 'true' }}"
} >> $GITHUB_OUTPUT
- name: Extract branch name
if: ${{ steps.applicable_check.outputs.flag }}
run: |
{
branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
echo "branch=${branch}"
echo "branch_upper=${branch^^}"
} >> $GITHUB_OUTPUT
id: extract_branch

- name: Set environment name
if: ${{ steps.applicable_check.outputs.flag }}
id: environment_name
run: |
{
echo "ENVIRONMENT=${{ inputs.ENVIRONMENT_NAME_OVERRIDE || steps.extract_branch.outputs.branch == 'main' && 'PRODUCTION' || steps.extract_branch.outputs.branch_upper }}"
} >> $GITHUB_ENV
- name: Build and Deploy
if: ${{ steps.applicable_check.outputs.flag }}
id: build_and_deploy
uses: ./.github/actions/build-and-deploy-cloud-function
with:
GCP_SA_KEY: ${{ secrets[format('TF_{0}_GCP_SA_KEY', env.ENVIRONMENT)] }}
REGION: ${{ env.REGION }}
CLOUD_FUNCTION_NAME: ${{ secrets[format('TF_{0}_EET_CF_NAME', env.ENVIRONMENT)] }}
CLOUD_FUNCTION_PATH: "cloud_functions/earth_engine_tiler/"
DRY_RUN: ${{ inputs.dry_run }}

# If required, use the Cloud Run url output in later steps
- name: Show Output
if: ${{ steps.applicable_check.outputs.flag }}
run: echo ${{ steps.build_and_deploy.outputs.url || 'No URL generated' }}

1 change: 1 addition & 0 deletions cloud_functions/earth_engine_tiler/.gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock.json
Loading

0 comments on commit f96ff8c

Please sign in to comment.