-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile.api
More file actions
80 lines (61 loc) · 2.33 KB
/
Dockerfile.api
File metadata and controls
80 lines (61 loc) · 2.33 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
# use minimal image (Alpine w/ Python) for base
FROM python:3.12-slim AS base
# install uv binary from official distro-less image
COPY --from=ghcr.io/astral-sh/uv:0.10.0 /uv /uvx /bin/
####################
FROM base AS builder
RUN apt update \
&& apt install -y g++ git \
&& apt clean \
&& rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man
# set working directory for colandr
ENV COLANDR_APP_DIR=/app
RUN mkdir -p ${COLANDR_APP_DIR}
WORKDIR ${COLANDR_APP_DIR}
# copy from cache instead of linking since it's a mounted volume
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy UV_PYTHON_DOWNLOADS=0
# install dependencies only
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 \
uv sync --locked --no-install-project
################
FROM base AS dev
# install curl, for use in this image's healthcheck
RUN apt update && apt install -y curl && apt clean
ENV COLANDR_APP_DIR=/app
WORKDIR ${COLANDR_APP_DIR}
# copy built artifacts from builder
COPY --from=builder --chown=app:app ${COLANDR_APP_DIR} ${COLANDR_APP_DIR}
# copy and install project
COPY . ${COLANDR_APP_DIR}
# place executables in env at the front of the path
ENV PATH="/app/.venv/bin:$PATH"
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy UV_PYTHON_DOWNLOADS=0
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --locked --group dev
# set up development env
ENV FLASK_ENV=development
# expose app port
EXPOSE 5000
CMD ["flask", "--app", "colandr.app:create_app()", "run", "--host", "0.0.0.0", "--port", "5000", "--debug"]
#################
FROM base AS prod
# install curl, for use in this image's healthcheck
RUN apt update && apt install -y curl && apt clean
ENV COLANDR_APP_DIR=/app
WORKDIR ${COLANDR_APP_DIR}
# copy built artifacts from builder
COPY --from=builder --chown=app:app ${COLANDR_APP_DIR} ${COLANDR_APP_DIR}
# copy and install project
COPY . ${COLANDR_APP_DIR}
# place executables in env at the front of the path
ENV PATH="/app/.venv/bin:$PATH"
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy UV_PYTHON_DOWNLOADS=0
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --locked --no-group dev
# set up production env
ENV FLASK_ENV=production
# expose app port
EXPOSE 5000
CMD ["gunicorn", "--config", "./gunicorn.conf.py", "colandr.app:create_app()"]