Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:Vizzuality/global-rangelands-dat…
Browse files Browse the repository at this point in the history
…a-platform into staging
  • Loading branch information
mbarrenechea committed Jun 13, 2024
2 parents a7a50a8 + 9a4bbd7 commit fb4ff3c
Show file tree
Hide file tree
Showing 90 changed files with 315,570 additions and 590 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}} \
4 changes: 2 additions & 2 deletions .github/actions/generate-env-file-from-json/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ outputs:
description: "The env file contents"
value: ${{steps.env_entries_stripped.outputs.entries_stripped}}

runs:
runs:
using: "composite"
steps:
- name: Output secrets and vars as key=value entries
Expand Down Expand Up @@ -57,4 +57,4 @@ runs:
echo 'entries_stripped<<EOF'
echo '${{ steps.env_entries_filtered.outputs.entries_filtered }}' | sed -E "s/^(TF_)?("$ENVIRONMENT"_)?"$APP_ENV_PREFIX"_//g"
echo 'EOF'
} >> $GITHUB_OUTPUT
} >> $GITHUB_OUTPUT
79 changes: 71 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ on:
- staging

paths:
- "client/**"
- "cms/**"
- ".github/workflows/*"
- "infrastructure/**"
- 'client/**'
- 'cms/**'
- 'cloud_functions/**'
- '.github/workflows/*'
- 'infrastructure/**'

env:
PROJECT_ID: ${{ secrets.TF_GCP_PROJECT_ID }}
Expand All @@ -41,8 +42,8 @@ jobs:
deploy_client:
# Add 'id-token' with the intended permissions for workload identity federation
permissions:
contents: "read"
id-token: "write"
contents: 'read'
id-token: 'write'

runs-on: ubuntu-latest
env:
Expand Down Expand Up @@ -151,8 +152,8 @@ jobs:
deploy_cms:
# Add 'id-token' with the intended permissions for workload identity federation
permissions:
contents: "read"
id-token: "write"
contents: 'read'
id-token: 'write'

runs-on: ubuntu-latest
env:
Expand Down Expand Up @@ -245,3 +246,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' }}

13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ This README is an early WIP, and will be edited as needed, as the project moves

- *Strapi Headless CMS*: The back-end application is implemented using Strapi, which provides a flexible content management system and exposes APIs for dynamic data retrieval.

- *TiTiler*: A Python FastAPI application for dynamic tiling, used for serving Raster tile data
- *Cloud Functions*: A small GCP Cloud Function to server as a mini tiler server/interface to use request data from GMV's Earth Engine account

External services:

- *Mapbox*: used for serving layers for the map
- *Mapbox* and *Google Earth Engine*: used for serving layers for the map

- *Transifex*: a globalization management system, used to localize the application into several languages.


This repository contains all the code and documentation necessary to set up and deploy the project. It is organized into the following subdirectories:

| Subdirectory name | Description | Documentation |
|-------------------|-------------------------------------------------------------|---------------------------------------------------------|
| frontend | The Next.js client application | [frontend/README.md](frontend/README.md) |
| cms | The Strapi CMS / API | [cms/README.md](cms/README.md) |
| Subdirectory name | Description | Documentation |
|-------------------|--------------------------------------------------------------------------------------------------|------------------------------------------------------|
| frontend | The Next.js client application | [frontend/README.md](frontend/README.md) |
| cms | The Strapi CMS / API | [cms/README.md](cms/README.md) |
| cloud_functions | Cloud Functions (Earth Engine Tiler) | [cloud_functions/README.md](cms/README.md) |
| infrastructure | The Terraform project & GH Actions workflow (provisioning & deployment to Google Cloud Platform) | [infrastructure/README.md](infrastructure/README.md) |

### Deployment and Infrastructure
Expand Down
15 changes: 13 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "yarn types && next dev",
"build": "next build",
"start": "next start",
"check-types": "tsc",
Expand All @@ -16,10 +16,18 @@
"@deck.gl/json": "^9.0.17",
"@deck.gl/layers": "^9.0.17",
"@deck.gl/mapbox": "^9.0.17",
"@loaders.gl/core": "^4.2.2",
"@loaders.gl/csv": "^4.2.2",
"@radix-ui/react-collapsible": "^1.0.3",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-radio-group": "^1.1.3",
"@radix-ui/react-scroll-area": "^1.0.5",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-toggle": "^1.0.3",
"@radix-ui/react-tooltip": "^1.0.7",
"@svgr/webpack": "^8.1.0",
"@t3-oss/env-core": "^0.10.1",
"@tanstack/react-query": "^5.40.1",
Expand All @@ -28,7 +36,9 @@
"axios": "^1.7.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"cmdk": "^1.0.0",
"color": "^4.2.3",
"d3-dsv": "^3.0.1",
"deck.gl": "^9.0.17",
"express": "^4.19.2",
"jotai": "^2.8.2",
Expand All @@ -47,10 +57,11 @@
"rooks": "^7.14.1",
"tailwind-merge": "^2.3.0",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.23.6"
"zod": "^3.23.8"
},
"devDependencies": {
"@types/color": "^3.0.6",
"@types/d3-dsv": "^3",
"@types/express": "^4",
"@types/mapbox-gl": "^3",
"@types/node": "^20",
Expand Down
Loading

0 comments on commit fb4ff3c

Please sign in to comment.