-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDockerfile
More file actions
85 lines (61 loc) · 3.18 KB
/
Copy pathDockerfile
File metadata and controls
85 lines (61 loc) · 3.18 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
########################################################################################################################
# Base stage, includes uv
########################################################################################################################
FROM python:3.11-alpine3.24@sha256:cf0253107a1e77e63c814a05428308965a47eb44a2d62fc828564c4a8c839fab AS base
# Copy uv + uvx binaries
COPY --from=ghcr.io/astral-sh/uv:0.11.21@sha256:ff07b86af50d4d9391d9daf4ff89ce427bc544f9aae87057e69a1cc0aa369946 /uv /uvx /bin/
# Enable bytecode compilation
ENV UV_COMPILE_BYTECODE=1
# Copy from the cache instead of linking since it's a mounted volume
ENV UV_LINK_MODE=copy
# Disable use of uv-managed Python versions
ENV UV_NO_MANAGED_PYTHON=1
# Disable Python downloads so that the system interpreter is used across images
ENV UV_PYTHON_DOWNLOADS=0
WORKDIR /datagateway-api-run
COPY pyproject.toml uv.lock README.md ./
########################################################################################################################
# Stage for local development
########################################################################################################################
FROM base AS dev
RUN --mount=type=cache,target=/root/.cache/uv \
set -eux; \
# Lock and install all dependencies but do not install the project \
uv sync --locked --no-install-project
COPY datagateway_api/ datagateway_api/
RUN --mount=type=cache,target=/root/.cache/uv \
set -eux; \
# Install the project \
uv sync --locked
CMD ["/datagateway-api-run/.venv/bin/fastapi", "dev", "datagateway_api/main.py", "--host", "0.0.0.0", "--port", "8000"]
EXPOSE 8000
########################################################################################################################
# Stage for production-ready build of the project
########################################################################################################################
FROM base AS prod-build
# Omit development dependencies
ENV UV_NO_DEV=1
RUN --mount=type=cache,target=/root/.cache/uv \
set -eux; \
# Lock and install all dependencies but do not install the project \
uv sync --locked --no-install-project
COPY datagateway_api/ datagateway_api/
RUN --mount=type=cache,target=/root/.cache/uv \
set -eux; \
# Install the project \
uv sync --locked
########################################################################################################################
# Minimal production-ready image
########################################################################################################################
FROM python:3.11-alpine3.24@sha256:cf0253107a1e77e63c814a05428308965a47eb44a2d62fc828564c4a8c839fab AS prod
WORKDIR /datagateway-api-run
# Copy the application from the prod-build stage
COPY --from=prod-build /datagateway-api-run /datagateway-api-run
RUN set -eux; \
\
# Create a non-root user to run as \
addgroup -S datagateway-api; \
adduser -S -D -G datagateway-api -H -h /datagateway-api-run datagateway-api;
USER datagateway-api
CMD ["/datagateway-api-run/.venv/bin/fastapi", "run", "datagateway_api/main.py", "--host", "0.0.0.0", "--port", "8000"]
EXPOSE 8000