-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
54 lines (42 loc) · 1.91 KB
/
Dockerfile
File metadata and controls
54 lines (42 loc) · 1.91 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
# From example at: https://github.com/astral-sh/uv-docker-example/blob/main/multistage.Dockerfile
# Build app dependencies
FROM python:3.12.8-slim-bookworm@sha256:2199a62885a12290dc9c5be3ca0681d367576ab7bf037da120e564723292a2f0 AS builder
WORKDIR /app
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
# Needed by hatch-vcs
git \
# Needed by psycopg2
build-essential libpq-dev \
&& rm -rf /var/lib/apt/lists/*
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
COPY --from=ghcr.io/astral-sh/uv:0.11.8@sha256:3b7b60a81d3c57ef471703e5c83fd4aaa33abcd403596fb22ab07db85ae91347 /uv /bin/
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
--mount=type=bind,source=.python-version,target=.python-version \
SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CARPOOLERBOT=0 \
uv sync --locked --no-dev --no-install-project --no-editable
# Build app
COPY . .
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=.git,target=.git \
# NOTE: reinstall-package is needed to calculate the correct version
uv sync --locked --no-dev --no-editable --reinstall-package=carpoolerbot
# Copy app to runtime stage
FROM python:3.12.8-slim-bookworm@sha256:2199a62885a12290dc9c5be3ca0681d367576ab7bf037da120e564723292a2f0
WORKDIR /app
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
dumb-init=1.2.5-2 \
# Needed by psycopg2
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/.venv /app/.venv
# Needed by Alembic
COPY --from=builder /app/pyproject.toml /app/alembic.ini /app/
COPY --from=builder /app/migrations /app/migrations
# Place executables in the environment at the front of the path
ENV PATH="/app/.venv/bin:$PATH"
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["/bin/sh", "-c", "alembic upgrade head && carpoolerbot"]