Skip to content

Commit 9108036

Browse files
committed
updated Dockerfile
1 parent 8048490 commit 9108036

File tree

1 file changed

+53
-50
lines changed

1 file changed

+53
-50
lines changed

services/director/Dockerfile

Lines changed: 53 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# syntax=docker/dockerfile:1
2-
ARG PYTHON_VERSION="3.6.10"
3-
FROM python:${PYTHON_VERSION}-slim-buster AS base
2+
3+
# Define arguments in the global scope
4+
ARG 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
8+
FROM python:${PYTHON_VERSION}-slim-bookworm AS base
9+
410
#
511
# USAGE:
612
# cd sercices/director
@@ -14,8 +20,8 @@ LABEL maintainer=sanderegg
1420
# for docker apt caching to work this needs to be added: [https://vsupalov.com/buildkit-cache-mount-dockerfile/]
1521
RUN rm -f /etc/apt/apt.conf.d/docker-clean && \
1622
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
17-
RUN --mount=type=cache,id=basecache36,target=/var/cache/apt,mode=0755,sharing=locked \
18-
--mount=type=cache,id=baseapt36,target=/var/lib/apt,mode=0755,sharing=locked \
23+
RUN --mount=type=cache,target=/var/cache/apt,mode=0755,sharing=private \
24+
--mount=type=cache,target=/var/lib/apt,mode=0755,sharing=private \
1925
set -eux && \
2026
apt-get update && \
2127
apt-get install -y --no-install-recommends \
@@ -44,22 +50,13 @@ ENV LANG=C.UTF-8
4450
# Turns off writing .pyc files; superfluous on an ephemeral container.
4551
ENV PYTHONDONTWRITEBYTECODE=1 \
4652
VIRTUAL_ENV=/home/scu/.venv
53+
4754
# Ensures that the python and pip executables used
4855
# in the image will be those from our virtualenv.
4956
ENV PATH="${VIRTUAL_ENV}/bin:$PATH"
5057

51-
# environment variables
52-
ENV REGISTRY_AUTH='' \
53-
REGISTRY_USER='' \
54-
REGISTRY_PW='' \
55-
REGISTRY_URL='' \
56-
REGISTRY_VERSION='v2' \
57-
PUBLISHED_HOST_NAME='' \
58-
SIMCORE_SERVICES_NETWORK_NAME='' \
59-
EXTRA_HOSTS_SUFFIX='undefined'
60-
61-
62-
EXPOSE 8080
58+
EXPOSE 8000
59+
EXPOSE 3000
6360

6461
# -------------------------- Build stage -------------------
6562
# Installs build/package management tools and third party dependencies
@@ -71,36 +68,26 @@ FROM base AS build
7168

7269
ENV SC_BUILD_TARGET=build
7370

74-
RUN --mount=type=cache,id=buildbasecache36,target=/var/cache/apt,mode=0755,sharing=locked \
75-
--mount=type=cache,id=buildbaseapt36,target=/var/lib/apt,mode=0755,sharing=locked \
71+
RUN --mount=type=cache,target=/var/cache/apt,mode=0755,sharing=private \
72+
--mount=type=cache,target=/var/lib/apt,mode=0755,sharing=private \
7673
set -eux \
7774
&& apt-get update \
7875
&& apt-get install -y --no-install-recommends \
79-
build-essential \
80-
git
76+
build-essential
8177

78+
# install UV https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
79+
COPY --from=uv_build /uv /uvx /bin/
8280

83-
# NOTE: python virtualenv is used here such that installed packages may be moved to production image easily by copying the venv
84-
RUN python -m venv "${VIRTUAL_ENV}"
81+
# NOTE: python virtualenv is used here such that installed
82+
# packages may be moved to production image easily by copying the venv
83+
RUN uv venv "${VIRTUAL_ENV}"
8584

86-
RUN --mount=type=cache,id=pip36,mode=0755,target=/root/.cache/pip \
87-
pip install --upgrade \
88-
pip~=21.3 \
85+
RUN --mount=type=cache,target=/root/.cache/uv \
86+
uv pip install --upgrade \
8987
wheel \
9088
setuptools
9189

92-
# install base 3rd party dependencies (NOTE: this speeds up devel mode)
93-
RUN \
94-
--mount=type=bind,source=packages,target=/build/packages,rw \
95-
--mount=type=bind,source=services/director,target=/build/services/director,rw \
96-
pip install \
97-
-r /build/services/director/requirements/_base.txt
98-
99-
# FIXME:
100-
# necessary to prevent duplicated files.
101-
# Will be removed when director is refactored using cookiecutter as this will not be necessary anymore
102-
COPY --chown=scu:scu api/specs/director/schemas/node-meta-v0.0.1.json \
103-
/build/services/director/src/simcore_service_director/api/v0/oas-parts/schemas/node-meta-v0.0.1.json
90+
WORKDIR /build
10491

10592
# --------------------------Prod-depends-only stage -------------------
10693
# This stage is for production only dependencies that get partially wiped out afterwards (final docker image concerns)
@@ -110,12 +97,18 @@ COPY --chown=scu:scu api/specs/director/schemas/node-meta-v0.0.1.json \
11097
#
11198
FROM build AS prod-only-deps
11299

113-
WORKDIR /build/services/director
114100
ENV SC_BUILD_TARGET=prod-only-deps
101+
102+
WORKDIR /build/services/director
103+
115104
RUN \
116105
--mount=type=bind,source=packages,target=/build/packages,rw \
117106
--mount=type=bind,source=services/director,target=/build/services/director,rw \
118-
pip install -r requirements/prod.txt
107+
--mount=type=cache,target=/root/.cache/uv \
108+
uv pip sync \
109+
requirements/prod.txt \
110+
&& uv pip list
111+
119112

120113
# --------------------------Production stage -------------------
121114
# Final cleanup up to reduce image size and startup setup
@@ -128,25 +121,32 @@ FROM base AS production
128121

129122
ENV SC_BUILD_TARGET=production \
130123
SC_BOOT_MODE=production
124+
131125
ENV PYTHONOPTIMIZE=TRUE
126+
# https://docs.astral.sh/uv/guides/integration/docker/#compiling-bytecode
127+
ENV UV_COMPILE_BYTECODE=1
132128

133129
WORKDIR /home/scu
134-
135130
# ensure home folder is read/writable for user scu
136131
RUN chown -R scu /home/scu
137-
# bring installed package without build tools
138-
COPY --from=prod-only-deps --chown=scu:scu ${VIRTUAL_ENV} ${VIRTUAL_ENV}
132+
133+
# Starting from clean base image, copies pre-installed virtualenv from prod-only-deps
134+
COPY --chown=scu:scu --from=prod-only-deps ${VIRTUAL_ENV} ${VIRTUAL_ENV}
135+
136+
# Copies booting scripts
139137
COPY --chown=scu:scu services/director/docker services/director/docker
140138
RUN chmod +x services/director/docker/*.sh
141139

142140

143-
HEALTHCHECK --interval=30s \
144-
--timeout=120s \
141+
HEALTHCHECK --interval=10s \
142+
--timeout=5s \
145143
--start-period=30s \
146-
--retries=3 \
147-
CMD ["python3", "/home/scu/services/director/docker/healthcheck.py", "http://localhost:8080/v0/"]
148-
ENTRYPOINT [ "services/director/docker/entrypoint.sh" ]
149-
CMD ["services/director/docker/boot.sh"]
144+
--start-interval=1s \
145+
--retries=5 \
146+
CMD ["python3", "/home/scu/services/director/docker/healthcheck.py", "http://localhost:8000/v0/"]
147+
148+
ENTRYPOINT [ "/bin/sh", "services/director/docker/entrypoint.sh" ]
149+
CMD ["/bin/sh", "services/director/docker/boot.sh"]
150150

151151

152152
# --------------------------Development stage -------------------
@@ -159,9 +159,12 @@ CMD ["services/director/docker/boot.sh"]
159159
#
160160
FROM build AS development
161161

162-
ENV SC_BUILD_TARGET=development
163-
ENV NODE_SCHEMA_LOCATION=../../../api/specs/director/schemas/node-meta-v0.0.1.json
162+
ENV SC_BUILD_TARGET=development \
163+
SC_DEVEL_MOUNT=/devel/services/director
164+
164165
WORKDIR /devel
166+
165167
RUN chown -R scu:scu "${VIRTUAL_ENV}"
168+
166169
ENTRYPOINT [ "/bin/sh", "services/director/docker/entrypoint.sh" ]
167170
CMD ["/bin/sh", "services/director/docker/boot.sh"]

0 commit comments

Comments
 (0)