-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
106 lines (74 loc) · 3.66 KB
/
Copy pathDockerfile
File metadata and controls
106 lines (74 loc) · 3.66 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
########################################################################################################################
# Base stage, includes uv
########################################################################################################################
FROM python:3.13.14-alpine3.24@sha256:399babc8b49529dabfd9c922f2b5eea81d611e4512e3ed250d75bd2e7683f4b0 AS base
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 /app
COPY pyproject.toml uv.lock .python-version README.md ./
########################################################################################################################
# Stage for local development
########################################################################################################################
FROM base AS dev
WORKDIR /app
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 object_storage_api/ object_storage_api/
RUN --mount=type=cache,target=/root/.cache/uv \
set -eux; \
\
# Install the project \
uv sync --locked;
CMD ["/app/.venv/bin/fastapi", "dev", "object_storage_api/main.py", "--host", "0.0.0.0", "--port", "8000"]
EXPOSE 8000
########################################################################################################################
# Stage for running tests
########################################################################################################################
FROM dev AS test
WORKDIR /app
COPY test/ test/
CMD ["/app/.venv/bin/pytest", "--config-file", "test/pytest.ini", "-v"]
########################################################################################################################
# Stage for production-ready build of the project
########################################################################################################################
FROM base AS prod-build
# Omit development dependencies
ENV UV_NO_DEV=1
WORKDIR /app
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 object_storage_api/ object_storage_api/
RUN --mount=type=cache,target=/root/.cache/uv \
set -eux; \
\
# Install the project \
uv sync --locked;
########################################################################################################################
# Minimal production-ready image
########################################################################################################################
# The same image that matches the build stage must be used as the path to the Python executable must be the same.
FROM python:3.13.14-alpine3.24@sha256:399babc8b49529dabfd9c922f2b5eea81d611e4512e3ed250d75bd2e7683f4b0 AS prod
WORKDIR /app
RUN set -eux; \
\
# Create a non-root user to run as \
addgroup -g 500 -S object-storage-api; \
adduser -S -D -G object-storage-api -H -u 500 -h /app object-storage-api;
# Copy the application from the prod-build stage
COPY --from=prod-build /app /app
USER object-storage-api
CMD ["/app/.venv/bin/fastapi", "run", "object_storage_api/main.py", "--host", "0.0.0.0", "--port", "8000"]
EXPOSE 8000