Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
132 lines (109 loc) · 4.36 KB
/
Copy pathDockerfile
File metadata and controls
132 lines (109 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# syntax=docker/dockerfile:1
# See https://reproducible-builds.org/docs/source-date-epoch/
ARG SOURCE_DATE_EPOCH
FROM ghcr.io/osgeo/gdal:ubuntu-small-3.13.3@sha256:64250faf833c06d4b21afce4c27190039ba7ab58d70f0eebc87cf77d929c0b40 AS base
LABEL org.opencontainers.image.source=https://github.com/opendatacube/datacube-explorer
LABEL org.opencontainers.image.description="Datacube Explorer"
LABEL org.opencontainers.image.licences="Apache-2.0"
LABEL org.opencontainers.image.title="Datacube Explorer"
ENV LC_ALL=C.UTF-8 \
LANG=C.UTF-8 \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1
# This cannot be inlined below (e.g., COPY --from=...) because Dependabot does not support that syntax yet
FROM ghcr.io/astral-sh/uv:0.13.0@sha256:cdc6093146eb3ff6a40107b38f008b789e050e77ad87865e381d9917da55a168 AS uv
FROM base AS builder
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends \
gcc \
g++ \
git \
# For shapely with --no-binary.
libgeos-dev \
libhdf5-dev \
libnetcdf-dev \
libudunits2-dev \
# For psycopg2.
libpq-dev \
python3-dev
ENV UV_COMPILE_BYTECODE=0 \
UV_HTTP_RETRIES=10 \
UV_LINK_MODE=copy \
UV_PROJECT_ENVIRONMENT=/app \
UV_PYTHON_DOWNLOADS=never \
UV_PYTHON=python3.14
WORKDIR /build
COPY --link --from=uv /uv /uvx /usr/local/bin/
COPY --link pyproject.toml uv.lock /build/
# Use a separate cache volume for uv on opendatacube projects, so it is
# not inseparable from pip/poetry/npm/etc. cache stored in /root/.cache.
RUN --mount=type=cache,id=opendatacube-uv-cache,target=/root/.cache \
uv sync --frozen --extra=deployment --no-install-project \
--no-binary-package fiona \
--no-binary-package netcdf4 \
--no-binary-package psycopg \
--no-binary-package psycopg-c \
--no-binary-package psycopg2 \
--no-binary-package rasterio \
--no-binary-package shapely
COPY --link . /build/
ARG ENVIRONMENT=deployment
ARG EXPLORER_VERSION=""
# The deployment image should not have binaries that aid an attacker to get their
# rootkit in place, and uv downloads over the network. There is no conditional
# copy in Docker, so truncate the uv binaries to 0 bytes to render them harmless
# in the resulting deployment image.
RUN --mount=type=cache,id=opendatacube-uv-cache,target=/root/.cache \
EXTRAS=$( ([ "$ENVIRONMENT" = "deployment" ] && echo "--extra=deployment --no-dev") || \
echo "--extra=test") \
&& export SETUPTOOLS_SCM_PRETEND_VERSION_FOR_DATACUBE_EXPLORER="${EXPLORER_VERSION}" \
&& uv sync --frozen $EXTRAS --no-editable \
&& ([ "$ENVIRONMENT" != "deployment" ] || \
(chmod 644 /usr/local/bin/uv* && \
echo "" > /usr/local/bin/uv && \
echo "" > /usr/local/bin/uvx))
FROM base
ARG EXPLORER_VERSION=""
LABEL org.opencontainers.image.version=${EXPLORER_VERSION}
# Add login-script for UID/GID-remapping.
COPY --chown=root:root --link docker/files/remap-user.sh /usr/local/bin/remap-user.sh
ARG ENVIRONMENT=deployment
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
export DEBIAN_FRONTEND=noninteractive \
&& EXTRAS=$( ([ "$ENVIRONMENT" = "deployment" ] && echo "") || \
echo "git") \
&& apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends \
$EXTRAS \
gosu \
libpq5 \
tini \
&& mkdir /app \
&& chown ubuntu:ubuntu /app
# In the "deployment" build, these `uv` binaries will be 0 bytes.
# In the "test" build they're the actual `uv` tools.
COPY --from=builder --link /usr/local/bin/uv* /usr/local/bin/
COPY --from=builder --link --chown=1000:1000 /app /app
# Configure user
WORKDIR "/home/ubuntu"
ENV PATH=/app/bin:$PATH
ENTRYPOINT ["/usr/local/bin/remap-user.sh"]
# This is for prod, and serves as docs. It's usually overwritten
CMD ["gunicorn", \
"-b", \
"0.0.0.0:8080", \
"-w", \
"3", \
"--threads=2", \
"-k", \
"gthread", \
"--config", \
"python:cubedash.gunicorn_config", \
"cubedash.startup_utils:create_app()"]