Skip to content

Commit 9774fb5

Browse files
Update Dockerfile (#34)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent bb21c7a commit 9774fb5

2 files changed

Lines changed: 122 additions & 16 deletions

File tree

.github/workflows/docker-image.yml

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,58 @@
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=${REPO}:${VERSION_TAG},${REPO}:latest" >> $GITHUB_OUTPUT
41+
42+
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
43+
PR_NUMBER=${{ github.event.pull_request.number }}
44+
echo "tags=${REPO}:pr-${PR_NUMBER}" >> $GITHUB_OUTPUT
45+
46+
else
47+
echo "tags=${REPO}:dev" >> $GITHUB_OUTPUT
48+
fi
49+
50+
- name: Build and push multi-platform image
51+
uses: docker/build-push-action@v5
52+
with:
53+
context: .
54+
platforms: linux/amd64,linux/arm64
55+
push: true
56+
tags: ${{ steps.meta.outputs.tags }}
57+
cache-from: type=gha
58+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,75 @@
1-
FROM jupyter/base-notebook:latest
2-
RUN pip install -U mapwidget && \
3-
fix-permissions "${CONDA_DIR}" && \
4-
fix-permissions "/home/${NB_USER}"
1+
# ------------------------------
2+
# Base image from Jupyter stack
3+
# ------------------------------
4+
FROM quay.io/jupyter/base-notebook:latest
55

6-
RUN mkdir ./examples
7-
COPY docs/examples ./examples
6+
# # ------------------------------
7+
# # 1. Switch to root to install system packages
8+
# # ------------------------------
9+
# USER root
810

9-
USER root
10-
RUN chown -R ${NB_UID} ${HOME}
11-
USER ${NB_USER}
11+
# RUN apt-get update && \
12+
# apt-get install -y --no-install-recommends \
13+
# git \
14+
# && apt-get clean && rm -rf /var/lib/apt/lists/*
15+
16+
# # ------------------------------
17+
# # 2. Install conda packages into base env
18+
# # ------------------------------
19+
# RUN mamba install -n base -c conda-forge -y \
20+
# gdal \
21+
# proj \
22+
# geos \
23+
# rasterio \
24+
# pyproj \
25+
# fiona \
26+
# geopandas \
27+
# rioxarray \
28+
# maplibre \
29+
# pmtiles \
30+
# flask \
31+
# flask-cors \
32+
# localtileserver \
33+
# jupyter-server-proxy \
34+
# leafmap \
35+
# && mamba clean --all --yes \
36+
# && fix-permissions $CONDA_DIR
37+
38+
# # ------------------------------
39+
# # 3. Set geospatial environment variables
40+
# # ------------------------------
41+
# ENV PROJ_LIB=$CONDA_DIR/share/proj \
42+
# GDAL_DATA=$CONDA_DIR/share/gdal \
43+
# LOCALTILESERVER_CLIENT_PREFIX='proxy/{port}'
44+
45+
# ------------------------------
46+
# 4. Copy source code after env setup
47+
# ------------------------------
48+
USER root
49+
COPY . /home/jovyan/mapwidget
50+
RUN chown -R $NB_UID:$NB_GID /home/jovyan/mapwidget
51+
WORKDIR /home/jovyan/mapwidget
52+
53+
# ------------------------------
54+
# 5. Install leafmap from source
55+
# ------------------------------
56+
# Prevent version resolution errors in CI
57+
ENV SETUPTOOLS_SCM_PRETEND_VERSION_FOR_MAPWIDGET=0.0.0
58+
59+
USER $NB_UID
60+
61+
RUN pip install . && \
62+
rm -rf ./build ./dist *.egg-info && \
63+
mkdir -p /home/jovyan/work && \
64+
fix-permissions /home/jovyan
65+
66+
# ------------------------------
67+
# 6. Switch back to default user
68+
# ------------------------------
69+
70+
WORKDIR /home/jovyan
71+
72+
# ------------------------------
73+
# Usage:
74+
# docker run -it -p 8888:8888 -v $(pwd):/home/jovyan/work ghcr.io/opengeos/mapwidget:latest
75+
# ------------------------------

0 commit comments

Comments
 (0)