11# syntax=docker/dockerfile:1
2+
3+ # Define arguments in the global scope
24ARG PYTHON_VERSION="3.11.9"
5+ ARG UV_VERSION="0.4"
6+ FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv_build
7+ # we docker image is built based on debian
38FROM python:${PYTHON_VERSION}-slim-bookworm AS base
49
510#
611# USAGE:
7- # cd sercices /autoscaling
12+ # cd services /autoscaling
813# docker build -f Dockerfile -t autoscaling:prod --target production ../../
914# docker run autoscaling:prod
1015#
@@ -90,31 +95,21 @@ RUN --mount=type=cache,target=/var/cache/apt,mode=0755,sharing=private \
9095 build-essential
9196
9297# install UV https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
93- ARG UV_VERSION= "0.4"
94- COPY --from=ghcr.io/ astral- sh/uv:${UV_VERSION} /uv /uvx /bin/
95-
98+ COPY --from=uv_build /uv /uvx /bin/
99+ # https://docs. astral. sh/uv/guides/integration/docker/#compiling-bytecode
100+ ENV UV_COMPILE_BYTECODE=1
96101
97102# NOTE: python virtualenv is used here such that installed
98103# packages may be moved to production image easily by copying the venv
99104RUN uv venv "${VIRTUAL_ENV}"
100105
101- RUN --mount=type=cache,mode=0755, target=/root/.cache/uv \
106+ RUN --mount=type=cache,target=/root/.cache/uv \
102107 uv pip install --upgrade \
103- pip~=24.0 \
104108 wheel \
105109 setuptools
106110
107111WORKDIR /build
108112
109- # install base 3rd party dependencies
110- # NOTE: copies to /build to avoid overwriting later which would invalidate this layer
111- RUN \
112- --mount=type=bind,source=services/autoscaling/requirements/_base.txt,target=_base.txt \
113- --mount=type=cache,mode=0755,target=/root/.cache/uv \
114- uv pip install \
115- --requirement _base.txt
116-
117-
118113# --------------------------Prod-depends-only stage -------------------
119114# This stage is for production only dependencies that get partially wiped out afterwards (final docker image concerns)
120115#
@@ -130,9 +125,9 @@ WORKDIR /build/services/autoscaling
130125RUN \
131126 --mount=type=bind,source=packages,target=/build/packages,rw \
132127 --mount=type=bind,source=services/autoscaling,target=/build/services/autoscaling,rw \
133- --mount=type=cache,mode=0755, target=/root/.cache/uv \
134- uv pip install \
135- --requirement requirements/prod.txt \
128+ --mount=type=cache,target=/root/.cache/uv \
129+ uv pip sync \
130+ requirements/prod.txt \
136131 && uv pip list
137132
138133
0 commit comments