Skip to content

Commit 5d7b2b9

Browse files
committed
improve speed by baking the catalogs into the docker image
1 parent 22dac08 commit 5d7b2b9

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

.github/workflows/deploy_function.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ name: Build and Deploy Report function to Cloud Run
4747
on:
4848
push:
4949
branches:
50-
- "main"
51-
- report-pdf-cloud-run
50+
- main
51+
pull_request:
52+
branches:
53+
- main
5254

5355
env:
5456
PROJECT_ID: dgds-i1000482-002
@@ -97,6 +99,7 @@ jobs:
9799
# END - Docker auth and build
98100

99101
- name: Deploy to Cloud Run
102+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
100103
id: deploy
101104
uses: google-github-actions/deploy-cloudrun@v2
102105
with:
@@ -111,4 +114,5 @@ jobs:
111114
112115
# If required, use the Cloud Run url output in later steps
113116
- name: Show Output
117+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
114118
run: echo ${{ steps.deploy.outputs.url }}

App/functions/report-python-cloud-run/.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
*.pyj
99
*.pyx
1010
*.pyd
11+
data/catalogs

App/functions/report-python-cloud-run/Dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,21 @@ RUN apt-get update && \
4848
# Place executables in the environment at the front of the path
4949
ENV PATH="/app/.venv/bin:$PATH"
5050

51+
# Clone the coclicodata and global-coastal-atlas repositories STAC catalogs
52+
RUN mkdir -p /app/data/catalogs
53+
RUN cd /app/data/catalogs && \
54+
git clone -n --depth=1 --filter=tree:0 https://github.com/openearth/coclicodata.git && \
55+
cd coclicodata && \
56+
git sparse-checkout set --no-cone /current && \
57+
git checkout && \
58+
cd /app/data/catalogs && \
59+
git clone -b subsidence_etienne -n --depth=1 --filter=tree:0 https://github.com/openearth/global-coastal-atlas.git && \
60+
cd global-coastal-atlas && \
61+
git sparse-checkout set --no-cone /STAC/data/current && \
62+
git checkout && \
63+
cd /app
64+
65+
ENV STAC_ROOT_DEFAULT="./data/catalogs/global-coastal-atlas/STAC/data/current/catalog.json"
66+
ENV STAC_COCLICO="./data/catalogs/coclicodata/current/catalog.json"
67+
5168
CMD uv run --with gunicorn gunicorn --bind :8080 --workers 1 --threads 8 --timeout 0 main:app
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
catalogs/

App/functions/report-python-cloud-run/report/report.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# %%
22
from dataclasses import dataclass
33
from io import BytesIO
4+
import os
45
from pathlib import Path
56

67
# import fitz # type: ignore
@@ -19,9 +20,15 @@
1920
from datetime import datetime
2021

2122
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"}"""
22-
STAC_ROOT_DEFAULT = "https://raw.githubusercontent.com/openearth/global-coastal-atlas/subsidence_etienne/STAC/data/current/catalog.json"
23-
STAC_COCLICO = (
24-
"https://raw.githubusercontent.com/openearth/coclicodata/main/current/catalog.json"
23+
# Get stac catalog location from environment variable if available otherwise use default
24+
# this is used to use local catalog instead of remote versions in deployed versions
25+
STAC_ROOT_DEFAULT = os.getenv(
26+
"STAC_ROOT_DEFAULT",
27+
"https://raw.githubusercontent.com/openearth/global-coastal-atlas/subsidence_etienne/STAC/data/current/catalog.json",
28+
)
29+
STAC_COCLICO = os.getenv(
30+
"STAC_COCLICO",
31+
"https://raw.githubusercontent.com/openearth/coclicodata/main/current/catalog.json",
2532
)
2633

2734

0 commit comments

Comments
 (0)