Skip to content

Commit

Permalink
Use uv in Docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
olzhasar-reef committed Nov 5, 2024
1 parent 7a96310 commit c8f8b3e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 60 deletions.
33 changes: 12 additions & 21 deletions executor/app/envs/prod/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,39 @@ FROM $BASE_IMAGE AS base-image
LABEL builder=true

WORKDIR /root/src/

RUN pip3 install --no-cache-dir 'pdm>=2.12,<3'
COPY pyproject.toml uv.lock ./

RUN apt-get update && apt-get install -y git
COPY pyproject.toml pdm.lock ./
RUN pdm lock --check
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
COPY --from=compute-horde . /root/compute_horde

RUN --mount=type=cache,target=/tmp/pdm_cache \
pdm config cache_dir /tmp/pdm_cache && \
pdm config python.use_venv False && \
# compute-horde from path computes version from git tag which is unavailable here,
# hence we pass PDM_BUILD_SCM_VERSION=0 manually
PDM_BUILD_SCM_VERSION=0 pdm sync --prod --group :all
RUN mkdir -p /opt/ && mv __pypackages__/3.11/ /opt/pypackages/
ENV PATH=/opt/pypackages/bin:$PATH
ENV PYTHONPATH=/opt/pypackages/lib:$PYTHONPATH
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-install-project --no-dev --no-editable --compile-bytecode

COPY ./app/src/ /root/src/
COPY ./app/envs/prod/entrypoint.sh /root/src/
COPY ./app/envs/prod/gunicorn.conf.py /root/src/
COPY ./app/envs/prod/celery-entrypoint.sh /root/src/

RUN python3 -m compileall -b -f -q /root/
RUN ENV=prod ENV_FILL_MISSING_VALUES=1 DATABASE_URL= SECRET_KEY=dummy python3 manage.py collectstatic --no-input --clear
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev --no-editable --compile-bytecode

RUN ENV=prod ENV_FILL_MISSING_VALUES=1 DATABASE_URL= SECRET_KEY=dummy uv run --no-sync python3 manage.py collectstatic --no-input --clear


FROM $BASE_IMAGE AS secondary-image
LABEL builder=false

RUN apt-get update \
&& apt-get install -y wget docker.io docker-compose \
&& rm -rf /var/lib/apt/lists/*
&& apt-get install -y wget docker.io docker-compose \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /root/src/
ENV PYTHONUNBUFFERED=1
ENV PATH=/opt/pypackages/bin:$PATH
ENV PYTHONPATH=/opt/pypackages/lib:$PYTHONPATH
ENV PATH="/root/src/.venv/bin:$PATH"

COPY --from=base-image /root/src/ /root/src/
COPY --from=base-image /opt/pypackages/ /opt/pypackages/

EXPOSE 8000

CMD ["./entrypoint.sh"]
CMD ["./entrypoint.sh"]
28 changes: 9 additions & 19 deletions miner/app/envs/prod/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,14 @@ FROM $BASE_IMAGE AS base-image
LABEL builder=true

WORKDIR /root/src/

RUN pip3 install --no-cache-dir 'pdm>=2.12,<3'
COPY pyproject.toml uv.lock ./

RUN apt-get update && apt-get install -y git
COPY pyproject.toml pdm.lock ./
RUN pdm lock --check
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
COPY --from=compute-horde . /root/compute_horde

RUN --mount=type=cache,target=/tmp/pdm_cache \
pdm config cache_dir /tmp/pdm_cache && \
pdm config python.use_venv False && \
# compute-horde from path computes version from git tag which is unavailable here,
# hence we pass PDM_BUILD_SCM_VERSION=0 manually
PDM_BUILD_SCM_VERSION=0 pdm sync --prod --group :all
RUN mkdir -p /opt/ && mv __pypackages__/3.11/ /opt/pypackages/
ENV PATH=/opt/pypackages/bin:$PATH
ENV PYTHONPATH=/opt/pypackages/lib:$PYTHONPATH
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-install-project --no-dev --no-editable --compile-bytecode

COPY ./app/src/ /root/src/
COPY ./app/envs/prod/entrypoint.sh /root/src/
Expand All @@ -30,22 +21,21 @@ COPY ./app/envs/prod/celery-entrypoint.sh /root/src/
COPY ./app/envs/prod/prometheus-cleanup.sh /root/src/
COPY ./app/envs/prod/vendor_setup.sh /root/src/

RUN python3 -m compileall -b -f -q /root/
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev --no-editable --compile-bytecode

FROM $BASE_IMAGE AS secondary-image
LABEL builder=false

RUN apt-get update \
&& apt-get install -y wget docker.io docker-compose \
&& rm -rf /var/lib/apt/lists/*
&& apt-get install -y wget docker.io docker-compose \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /root/src/
ENV PYTHONUNBUFFERED=1
ENV PATH=/opt/pypackages/bin:$PATH
ENV PYTHONPATH=/opt/pypackages/lib:$PYTHONPATH
ENV PATH="/root/src/.venv/bin:$PATH"

COPY --from=base-image /root/src/ /root/src/
COPY --from=base-image /opt/pypackages/ /opt/pypackages/

ARG MINER_VERSION=notset
ENV MINER_VERSION=$MINER_VERSION
Expand Down
30 changes: 10 additions & 20 deletions validator/app/envs/prod/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,14 @@ FROM $BASE_IMAGE AS base-image
LABEL builder=true

WORKDIR /root/src/

RUN pip3 install --no-cache-dir 'pdm>=2.12,<3'
COPY pyproject.toml uv.lock ./

RUN apt-get update && apt-get install -y git
COPY pyproject.toml pdm.lock ./
RUN pdm lock --check
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
COPY --from=compute-horde . /root/compute_horde

RUN --mount=type=cache,target=/tmp/pdm_cache \
pdm config cache_dir /tmp/pdm_cache && \
pdm config python.use_venv False && \
# compute-horde from path computes version from git tag which is unavailable here,
# hence we pass PDM_BUILD_SCM_VERSION=0 manually
PDM_BUILD_SCM_VERSION=0 pdm sync --prod --group :all
RUN mkdir -p /opt/ && mv __pypackages__/3.11/ /opt/pypackages/
ENV PATH=/opt/pypackages/bin:$PATH
ENV PYTHONPATH=/opt/pypackages/lib:$PYTHONPATH
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-install-project --no-dev --no-editable --compile-bytecode

COPY ./app/src/ /root/src/
COPY ./app/envs/prod/entrypoint.sh /root/src/
Expand All @@ -30,27 +21,26 @@ COPY ./app/envs/prod/celery-entrypoint.sh /root/src/
COPY ./app/envs/prod/celery-beat-entrypoint.sh /root/src/
COPY ./app/envs/prod/prometheus-cleanup.sh /root/src/

RUN python3 -m compileall -b -f -q /root/
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev --no-editable --compile-bytecode


FROM $BASE_IMAGE AS secondary-image
LABEL builder=false

RUN apt-get update \
&& apt-get install -y wget \
&& rm -rf /var/lib/apt/lists/*
&& apt-get install -y wget \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /root/src/
ENV PYTHONUNBUFFERED=1
ENV PATH=/opt/pypackages/bin:$PATH
ENV PYTHONPATH=/opt/pypackages/lib:$PYTHONPATH
ENV PATH="/root/src/.venv/bin:$PATH"

COPY --from=base-image /root/src/ /root/src/
COPY --from=base-image /opt/pypackages/ /opt/pypackages/

ARG VALIDATOR_VERSION=notset
ENV VALIDATOR_VERSION=$VALIDATOR_VERSION

EXPOSE 8000

CMD ["./entrypoint.sh"]
CMD ["./entrypoint.sh"]

0 comments on commit c8f8b3e

Please sign in to comment.