Skip to content

Commit 9c8217d

Browse files
authored
Update docker image workflows (#2261)
* Update docker image workflows * Add nodejs and npm
1 parent 3b07be1 commit 9c8217d

File tree

3 files changed

+143
-46
lines changed

3 files changed

+143
-46
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Delete All GHCR PR Tags
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
workflow_dispatch:
8+
9+
jobs:
10+
delete-pr-tags:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Delete all GHCR image tags starting with "pr-"
15+
env:
16+
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
17+
REPO: ${{ github.event.repository.name }}
18+
OWNER: ${{ github.repository_owner }}
19+
run: |
20+
echo "Fetching GHCR container versions for ghcr.io/${OWNER}/${REPO}..."
21+
22+
response=$(curl -s -H "Authorization: Bearer ${GHCR_TOKEN}" \
23+
"https://api.github.com/orgs/${OWNER}/packages/container/${REPO}/versions")
24+
25+
# Check that the response is a JSON array
26+
if ! echo "$response" | jq -e 'type == "array"' > /dev/null; then
27+
echo "❌ Unexpected response from GitHub API:"
28+
echo "$response"
29+
exit 1
30+
fi
31+
32+
echo "$response" | jq -c '.[]' | while read -r version; do
33+
version_id=$(echo "$version" | jq -r '.id')
34+
tag_names=$(echo "$version" | jq -r '.metadata.container.tags[]?')
35+
36+
for tag in $tag_names; do
37+
if [[ "$tag" == pr-* ]]; then
38+
echo "🗑️ Deleting tag: $tag (version ID: $version_id)"
39+
curl -s -X DELETE -H "Authorization: Bearer ${GHCR_TOKEN}" \
40+
"https://api.github.com/orgs/${OWNER}/packages/container/${REPO}/versions/${version_id}"
41+
break # One deletion per version is sufficient
42+
fi
43+
done
44+
done

.github/workflows/docker-image.yml

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,62 @@
1-
name: Docker Image CI
1+
name: Build Docker Image
22

33
on:
4+
release:
5+
types: [published]
46
push:
5-
branches: ["master"]
7+
branches:
8+
- master
69
pull_request:
7-
branches: ["master"]
10+
types: [opened, synchronize, reopened]
811

912
jobs:
10-
build:
13+
build-and-push:
1114
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
packages: write
1218

1319
steps:
14-
- uses: actions/checkout@v4
15-
- name: Build the Docker image
16-
run: docker build . --file Dockerfile --tag ${{ github.repository }}:$(date +%s)
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v3
25+
26+
- name: Log in to GitHub Container Registry (ghcr.io)
27+
uses: docker/login-action@v3
28+
with:
29+
registry: ghcr.io
30+
username: ${{ github.actor }}
31+
password: ${{ secrets.GITHUB_TOKEN }}
32+
33+
- name: Set Docker image tags
34+
id: meta
35+
run: |
36+
REPO=ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
37+
38+
if [[ "${{ github.event_name }}" == "release" ]]; then
39+
VERSION_TAG=${{ github.event.release.tag_name }}
40+
echo "tags<<EOF" >> $GITHUB_OUTPUT
41+
echo "${REPO}:${VERSION_TAG}" >> $GITHUB_OUTPUT
42+
echo "${REPO}:latest" >> $GITHUB_OUTPUT
43+
echo "EOF" >> $GITHUB_OUTPUT
44+
45+
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
46+
PR_NUMBER=${{ github.event.pull_request.number }}
47+
echo "tags=${REPO}:pr-${PR_NUMBER}" >> $GITHUB_OUTPUT
48+
49+
else
50+
echo "tags=${REPO}:dev" >> $GITHUB_OUTPUT
51+
fi
52+
53+
- name: Build and push multi-platform image
54+
uses: docker/build-push-action@v5
55+
with:
56+
context: .
57+
platforms: linux/amd64,linux/arm64
58+
push: true
59+
tags: ${{ steps.meta.outputs.tags }}
60+
provenance: false
61+
cache-from: type=gha
62+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,78 @@
1+
# ------------------------------
2+
# Base image from Jupyter stack
3+
# ------------------------------
14
FROM quay.io/jupyter/base-notebook:latest
25

3-
# -------------------------------------------------------
4-
# 1. Install system-level packages (minimal, just git)
5-
# -------------------------------------------------------
6+
# ------------------------------
7+
# 1. Switch to root to install system packages
8+
# ------------------------------
69
USER root
10+
711
RUN apt-get update && \
8-
apt-get install -y git && \
9-
rm -rf /var/lib/apt/lists/*
12+
apt-get install -y --no-install-recommends \
13+
git \
14+
curl \
15+
nodejs \
16+
npm \
17+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
1018

11-
# -------------------------------------------------------
12-
# 2. Install geospatial Python packages via conda (base env)
13-
# -------------------------------------------------------
14-
RUN mamba install -n base -c conda-forge \
19+
# ------------------------------
20+
# 2. Install conda packages into base env
21+
# ------------------------------
22+
RUN mamba install -n base -c conda-forge -y \
1523
gdal \
1624
proj \
1725
geos \
1826
rasterio \
1927
pyproj \
2028
fiona \
21-
localtileserver \
2229
geopandas \
2330
rioxarray \
2431
maplibre \
2532
pmtiles \
26-
leafmap \
2733
flask \
2834
flask-cors \
29-
tippecanoe \
35+
localtileserver \
36+
jupyter-server-proxy \
3037
ffmpeg-python \
3138
gdown \
3239
xee \
33-
jupyter-server-proxy -y && \
34-
fix-permissions "${CONDA_DIR}"
40+
leafmap \
41+
&& mamba clean --all --yes \
42+
&& fix-permissions $CONDA_DIR
3543

36-
# -------------------------------------------------------
37-
# 3. Environment variables
38-
# -------------------------------------------------------
39-
ENV PROJ_LIB=/opt/conda/share/proj
40-
ENV GDAL_DATA=/opt/conda/share/gdal
41-
ENV LOCALTILESERVER_CLIENT_PREFIX='proxy/{port}'
44+
# ------------------------------
45+
# 3. Set geospatial environment variables
46+
# ------------------------------
47+
ENV PROJ_LIB=$CONDA_DIR/share/proj \
48+
GDAL_DATA=$CONDA_DIR/share/gdal \
49+
LOCALTILESERVER_CLIENT_PREFIX='proxy/{port}'
4250

43-
# -------------------------------------------------------
44-
# 4. Copy source code (do this *after* package installs to improve caching)
45-
# -------------------------------------------------------
51+
# ------------------------------
52+
# 4. Copy source code after env setup
53+
# ------------------------------
4654
COPY . /home/jovyan/geemap
4755
WORKDIR /home/jovyan/geemap
4856

49-
50-
# -------------------------------------------------------
51-
# 5. Build and install geemap from source
52-
# -------------------------------------------------------
53-
# Prevent setuptools_scm issues if .git is missing
57+
# ------------------------------
58+
# 5. Install geemap from source
59+
# ------------------------------
60+
# Prevent version resolution errors in CI
5461
ENV SETUPTOOLS_SCM_PRETEND_VERSION_FOR_GEEMAP=0.0.0
5562

56-
RUN rm -rf /home/jovyan/geemap/geemap.egg-info && \
57-
pip install -U geemap && \
63+
RUN pip install . && \
64+
rm -rf ./build ./dist *.egg-info && \
5865
mkdir -p /home/jovyan/work && \
5966
fix-permissions /home/jovyan
6067

61-
# -------------------------------------------------------
62-
# 6. Set back to default user
63-
# -------------------------------------------------------
68+
# ------------------------------
69+
# 6. Switch back to default user
70+
# ------------------------------
71+
USER $NB_UID
6472
WORKDIR /home/jovyan
65-
USER jovyan
66-
6773

68-
# -------------------------------------------------------
69-
# 7. Run the docker container
70-
# -------------------------------------------------------
71-
# docker run -it -p 8888:8888 -v $(pwd):/home/jovyan/work giswqs/geemap:latest
74+
# ------------------------------
75+
# Usage:
76+
# docker pull ghcr.io/gee-community/geemap:latest
77+
# docker run -it -p 8888:8888 -v $(pwd):/home/jovyan/work ghcr.io/gee-community/geemap:latest
78+
# ------------------------------

0 commit comments

Comments
 (0)