Skip to content

Commit b023c29

Browse files
authored
Add custom pygeoapi image build (#36)
* feat: add custom pygeoapi image build * fix: build tippecanoe from source * build: install tippecanoe via homebrew
1 parent 99b4491 commit b023c29

8 files changed

Lines changed: 126 additions & 2 deletions

File tree

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/tiles/
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Publish Pygeoapi Docker Image
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- "pygeoapi/**"
8+
- "data/**"
9+
- ".github/workflows/pygeoapi-image.yml"
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: write
14+
packages: write
15+
16+
jobs:
17+
build-and-push:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v3
24+
25+
- name: Bump repo version
26+
run: |
27+
VERSION=$(cat VERSION)
28+
IFS='.' read -r MAJ MIN PATCH <<<"$VERSION"
29+
PATCH=$((PATCH+1))
30+
NEW_VERSION="$MAJ.$MIN.$PATCH"
31+
echo "$NEW_VERSION" > VERSION
32+
echo "VERSION=$NEW_VERSION" >> "$GITHUB_ENV"
33+
34+
- name: Commit version bump
35+
run: |
36+
git config user.name "GitHub Actions"
37+
git config user.email "actions@github.com"
38+
git add VERSION
39+
git commit -m "chore: bump repo version to $VERSION" && git push || echo "No changes to commit"
40+
41+
- name: Get pygeoapi version
42+
id: pgv
43+
run: |
44+
PYGEOAPI_VERSION=$(docker run --rm geopython/pygeoapi:latest pygeoapi --version | awk '{print $2}')
45+
echo "PYGEOAPI_VERSION=$PYGEOAPI_VERSION" >> "$GITHUB_OUTPUT"
46+
47+
- name: Log in to GHCR
48+
uses: docker/login-action@v3
49+
with:
50+
registry: ghcr.io
51+
username: ${{ github.actor }}
52+
password: ${{ secrets.GITHUB_TOKEN }}
53+
54+
- name: Build and push Docker image
55+
uses: docker/build-push-action@v6
56+
with:
57+
context: .
58+
file: ./docker/Dockerfile.pygeoapi
59+
push: true
60+
build-args: |
61+
REPO_VERSION=${{ env.VERSION }}
62+
tags: |
63+
ghcr.io/${{ github.repository_owner }}/pygeoapi-w-global-tsunami-data:latest
64+
ghcr.io/${{ github.repository_owner }}/pygeoapi-w-global-tsunami-data:${{ steps.pgv.outputs.PYGEOAPI_VERSION }}-${{ env.VERSION }}

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,9 @@ A GitHub Actions workflow builds and publishes the frontend Docker image wheneve
3737
changes are pushed to the `frontend/` directory on the `main` branch. The image
3838
is pushed to the GitHub Container Registry under the tag
3939
`global-tsunami-risk-map-frontend`.
40+
41+
Another workflow builds a custom `pygeoapi` image containing the data from this
42+
repository. Whenever files in the `data/` or `pygeoapi/` folders change, the
43+
workflow bumps the repository `VERSION` file and publishes a new Docker image
44+
named `pygeoapi-w-global-tsunami-data`. The image tag combines the upstream
45+
pygeoapi version with the bumped repository version.

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.0

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: "3.9"
22

33
services:
44
backend:
5-
image: geopython/pygeoapi:latest
5+
image: ${PYGEOAPI_IMAGE:-ghcr.io/yejiyang/pygeoapi-w-global-tsunami-data:latest}
66
container_name: backend
77
ports:
88
- "5000:5000"

docker/Dockerfile.pygeoapi

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
FROM geopython/pygeoapi:latest
2+
3+
# Copy configuration
4+
COPY pygeoapi/pygeoapi-config.yml /pygeoapi/local.config.yml
5+
6+
# Copy data except tiles
7+
COPY data/hazard /data/hazard
8+
COPY data/hyderabad /data/hyderabad
9+
COPY data/norway /data/norway
10+
COPY data/scripts /data/scripts
11+
12+
# Install tippecanoe for tile generation via Homebrew
13+
RUN apt-get update \
14+
&& apt-get install -y --no-install-recommends \
15+
build-essential \
16+
curl \
17+
file \
18+
git \
19+
&& git clone https://github.com/Homebrew/brew /home/linuxbrew/.linuxbrew/Homebrew \
20+
&& mkdir -p /home/linuxbrew/.linuxbrew/bin \
21+
&& ln -s ../Homebrew/bin/brew /home/linuxbrew/.linuxbrew/bin \
22+
&& /home/linuxbrew/.linuxbrew/bin/brew install tippecanoe \
23+
&& /home/linuxbrew/.linuxbrew/bin/brew cleanup \
24+
&& rm -rf /var/lib/apt/lists/*
25+
ENV PATH="/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:$PATH"
26+
27+
# Build version string
28+
ARG REPO_VERSION
29+
RUN PY_VER=$(python3 -c 'import pkg_resources;print(pkg_resources.get_distribution("pygeoapi").version)') \
30+
&& echo "${PY_VER}-${REPO_VERSION}" > /VERSION
31+
32+
# Add init script
33+
COPY docker/init.sh /init.sh
34+
RUN chmod +x /init.sh
35+
36+
ENTRYPOINT ["/init.sh"]

docker/init.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Generate hazard vector tiles if missing
5+
if [ ! -d /data/tiles/global-hazard ]; then
6+
echo "[init] Generating hazard vector tiles"
7+
mkdir -p /data/tiles/global-hazard
8+
tippecanoe -r1 -pk -pf \
9+
--output-to-directory=/data/tiles/global-hazard/ \
10+
--force --maximum-zoom=15 \
11+
--extend-zooms-if-still-dropping \
12+
--no-tile-compression \
13+
/data/hazard/global-hazard-points.geojson
14+
fi
15+
16+
exec /entrypoint.sh "$@"

k8s/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ spec:
202202
spec:
203203
containers:
204204
- name: pygeoapi
205-
image: geopython/pygeoapi:latest
205+
image: ghcr.io/yejiyang/pygeoapi-w-global-tsunami-data:latest
206206
ports:
207207
- containerPort: 5000
208208
env:

0 commit comments

Comments
 (0)