Skip to content

Commit

Permalink
improve speed by baking the catalogs into the docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
N-Clerkx committed Dec 19, 2024
1 parent 22dac08 commit 5d7b2b9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/deploy_function.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ name: Build and Deploy Report function to Cloud Run
on:
push:
branches:
- "main"
- report-pdf-cloud-run
- main
pull_request:
branches:
- main

env:
PROJECT_ID: dgds-i1000482-002
Expand Down Expand Up @@ -97,6 +99,7 @@ jobs:
# END - Docker auth and build

- name: Deploy to Cloud Run
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
id: deploy
uses: google-github-actions/deploy-cloudrun@v2
with:
Expand All @@ -111,4 +114,5 @@ jobs:
# If required, use the Cloud Run url output in later steps
- name: Show Output
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: echo ${{ steps.deploy.outputs.url }}
1 change: 1 addition & 0 deletions App/functions/report-python-cloud-run/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
*.pyj
*.pyx
*.pyd
data/catalogs
17 changes: 17 additions & 0 deletions App/functions/report-python-cloud-run/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,21 @@ RUN apt-get update && \
# Place executables in the environment at the front of the path
ENV PATH="/app/.venv/bin:$PATH"

# Clone the coclicodata and global-coastal-atlas repositories STAC catalogs
RUN mkdir -p /app/data/catalogs
RUN cd /app/data/catalogs && \
git clone -n --depth=1 --filter=tree:0 https://github.com/openearth/coclicodata.git && \
cd coclicodata && \
git sparse-checkout set --no-cone /current && \
git checkout && \
cd /app/data/catalogs && \
git clone -b subsidence_etienne -n --depth=1 --filter=tree:0 https://github.com/openearth/global-coastal-atlas.git && \
cd global-coastal-atlas && \
git sparse-checkout set --no-cone /STAC/data/current && \
git checkout && \
cd /app

ENV STAC_ROOT_DEFAULT="./data/catalogs/global-coastal-atlas/STAC/data/current/catalog.json"
ENV STAC_COCLICO="./data/catalogs/coclicodata/current/catalog.json"

CMD uv run --with gunicorn gunicorn --bind :8080 --workers 1 --threads 8 --timeout 0 main:app
1 change: 1 addition & 0 deletions App/functions/report-python-cloud-run/data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
catalogs/
13 changes: 10 additions & 3 deletions App/functions/report-python-cloud-run/report/report.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# %%
from dataclasses import dataclass
from io import BytesIO
import os
from pathlib import Path

# import fitz # type: ignore
Expand All @@ -19,9 +20,15 @@
from datetime import datetime

POLYGON_DEFAULT = """{"coordinates":[[[2.3915028831735015,51.7360381463356],[5.071438932343227,50.89406012060684],[6.955992986278972,51.49577449585874],[7.316959036046541,53.18700330195111],[6.636226617140238,53.961350092621075],[3.8631377106468676,54.14643052276938],[2.1218958391276317,53.490771261555096],[2.3915028831735015,51.7360381463356]]],"type":"Polygon"}"""
STAC_ROOT_DEFAULT = "https://raw.githubusercontent.com/openearth/global-coastal-atlas/subsidence_etienne/STAC/data/current/catalog.json"
STAC_COCLICO = (
"https://raw.githubusercontent.com/openearth/coclicodata/main/current/catalog.json"
# Get stac catalog location from environment variable if available otherwise use default
# this is used to use local catalog instead of remote versions in deployed versions
STAC_ROOT_DEFAULT = os.getenv(
"STAC_ROOT_DEFAULT",
"https://raw.githubusercontent.com/openearth/global-coastal-atlas/subsidence_etienne/STAC/data/current/catalog.json",
)
STAC_COCLICO = os.getenv(
"STAC_COCLICO",
"https://raw.githubusercontent.com/openearth/coclicodata/main/current/catalog.json",
)


Expand Down

0 comments on commit 5d7b2b9

Please sign in to comment.