forked from MikeDacre/python_bed_lookup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
68 lines (59 loc) · 3.16 KB
/
Copy pathDockerfile
File metadata and controls
68 lines (59 loc) · 3.16 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
# Multi-stage build. The builder compiles the Cython extension into a wheel; the runtime
# image installs just that wheel and its core deps (typer, rich) with no toolchain, so it
# stays small. BuildKit cache mounts keep apt/pip downloads off the image layers and make
# rebuilds fast. The entrypoint is the bed_location_lookup CLI.
#
# The CLI does not use pandas, so it is intentionally NOT installed here (keeps the image
# lean). If you need the `lookup_df`/`lookup_series` helpers in-container, layer pandas onto a
# derived image (switch to root for the install; see the README "pandas helpers" section):
# FROM ghcr.io/msk-access/python_bed_lookup:latest
# USER root
# RUN pip install --no-cache-dir pandas
# USER app
#
# BASE_IMAGE is overridable so the build can use a locally-cached base when offline, e.g.
# docker build --build-arg BASE_IMAGE=python:3.11-bookworm -t bed_lookup .
ARG BASE_IMAGE=python:3.12-slim
FROM ${BASE_IMAGE} AS builder
# Minimal C++ toolchain (g++ pulls gcc + libc-dev) — lighter than full build-essential.
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
rm -f /etc/apt/apt.conf.d/docker-clean \
&& apt-get update \
&& apt-get install -y --no-install-recommends g++
WORKDIR /src
COPY . .
# Build only the bed_lookup wheel (build isolation pulls cython+setuptools transiently).
RUN --mount=type=cache,target=/root/.cache/pip \
pip wheel --no-deps --wheel-dir /wheels .
FROM ${BASE_IMAGE} AS runtime
# Static OCI image annotations. The dynamic ones (version, revision, created) are injected at
# build time by docker/metadata-action in .github/workflows/docker.yml.
LABEL org.opencontainers.image.title="python_bed_lookup" \
org.opencontainers.image.description="Fast gene/SNP lookup from a BED file by coordinate" \
org.opencontainers.image.url="https://github.com/msk-access/python_bed_lookup" \
org.opencontainers.image.source="https://github.com/msk-access/python_bed_lookup" \
org.opencontainers.image.documentation="https://github.com/msk-access/python_bed_lookup/blob/master/README.rst" \
org.opencontainers.image.authors="Michael Dacre <mike.dacre@gmail.com>" \
org.opencontainers.image.vendor="msk-access" \
org.opencontainers.image.licenses="MIT"
# libstdc++6 is the only shared library the compiled extension needs at runtime.
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
rm -f /etc/apt/apt.conf.d/docker-clean \
&& apt-get update \
&& apt-get install -y --no-install-recommends libstdc++6
# Install the locally-built wheel + core deps (typer, rich); strip bytecode/caches after.
COPY --from=builder /wheels /wheels
RUN --mount=type=cache,target=/root/.cache/pip \
pip install --no-compile /wheels/*.whl \
&& rm -rf /wheels \
&& find /usr/local/lib -type d -name '__pycache__' -prune -exec rm -rf {} +
# Run as an unprivileged user; /data is the working dir for mounted bed files.
RUN useradd --create-home --uid 1000 app \
&& mkdir /data \
&& chown app /data
USER app
WORKDIR /data
ENTRYPOINT ["bed_location_lookup"]
CMD ["--help"]