From 511a00df1ffeea81a474e08c85ae409fc3def69c Mon Sep 17 00:00:00 2001 From: Stef Piatek Date: Fri, 9 Feb 2024 09:39:45 +0000 Subject: [PATCH] Install module requirements before module in docker (#285) * Install module requirements before module in docker * Update python to 3.11 in Dockerfiles * Remove unused dockerfile --- .github/workflows/main.yml | 9 +++++++++ docker/ehr-api/Dockerfile | 9 ++++++++- docker/hasher-api/Dockerfile | 7 ++++++- docker/imaging-api/Dockerfile | 9 ++++++++- docker/orthanc-anon/Dockerfile | 13 +++++++++++-- docker/postgres/Dockerfile | 14 +++++++++++--- pixl_core/tests/Dockerfile | 19 ------------------- test/Dockerfile.fake_emap_star | 5 +++-- test/dummy-services/cogstack/Dockerfile | 5 +++-- 9 files changed, 59 insertions(+), 31 deletions(-) delete mode 100644 pixl_core/tests/Dockerfile diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 37673d38e..9e75c5a2f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -246,6 +246,15 @@ jobs: python-version: 3.10.6 cache: "pip" + - name: Build test services + working-directory: test + run: | + docker compose build + + - name: Build services + run: | + docker compose build + - name: Run tests working-directory: test run: | diff --git a/docker/ehr-api/Dockerfile b/docker/ehr-api/Dockerfile index 3e8cc6a47..ef2195eba 100644 --- a/docker/ehr-api/Dockerfile +++ b/docker/ehr-api/Dockerfile @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -FROM python:3.10.6-slim-bullseye +FROM python:3.11.7-slim-bullseye SHELL ["/bin/bash", "-o", "pipefail", "-e", "-u", "-x", "-c"] ARG TEST="false" @@ -25,6 +25,13 @@ RUN apt-get autoremove && apt-get clean && rm -rf /var/lib/apt/lists/* WORKDIR /app +# Install requirements before copying modules +COPY ./pixl_core/pyproject.toml ./pixl_core/pyproject.toml +COPY ./pixl_ehr/pyproject.toml ./pixl_ehr/pyproject.toml +RUN --mount=type=cache,target=/root/.cache \ + pip3 install pixl_core/ \ + && pip3 install pixl_ehr/ + COPY ./pixl_core/ core/ COPY ./pixl_ehr/ . RUN --mount=type=cache,target=/root/.cache \ diff --git a/docker/hasher-api/Dockerfile b/docker/hasher-api/Dockerfile index 82cf04b51..af1305c68 100644 --- a/docker/hasher-api/Dockerfile +++ b/docker/hasher-api/Dockerfile @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -FROM python:3.10.7-slim-bullseye +FROM python:3.11.7-slim-bullseye SHELL ["/bin/bash", "-o", "pipefail", "-e", "-u", "-x", "-c"] # OS setup @@ -25,6 +25,11 @@ RUN sed -i '/en_GB.UTF-8/s/^# //g' /etc/locale.gen && locale-gen RUN apt-get autoremove && apt-get clean && rm -rf /var/lib/apt/lists/* WORKDIR /app +# Install requirements before copying modules +COPY ./hasher/pyproject.toml . +RUN --mount=type=cache,target=/root/.cache \ + pip install /app/ + COPY ./hasher/ . RUN --mount=type=cache,target=/root/.cache \ pip install . diff --git a/docker/imaging-api/Dockerfile b/docker/imaging-api/Dockerfile index 52a178d77..5ad47de1a 100644 --- a/docker/imaging-api/Dockerfile +++ b/docker/imaging-api/Dockerfile @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -FROM python:3.10.6-slim-bullseye +FROM python:3.11.7-slim-bullseye SHELL ["/bin/bash", "-o", "pipefail", "-e", "-u", "-x", "-c"] ARG TEST="false" @@ -25,6 +25,13 @@ RUN apt-get autoremove && apt-get clean && rm -rf /var/lib/apt/lists/* WORKDIR /app +# Install requirements before copying modules +COPY ./pixl_core/pyproject.toml ./pixl_core/pyproject.toml +COPY ./pixl_imaging/pyproject.toml ./pixl_imaging/pyproject.toml +RUN --mount=type=cache,target=/root/.cache \ + pip3 install pixl_core/ \ + && pip3 install pixl_imaging/ + COPY ./pixl_core/ core/ COPY ./pixl_imaging/ . RUN --mount=type=cache,target=/root/.cache \ diff --git a/docker/orthanc-anon/Dockerfile b/docker/orthanc-anon/Dockerfile index d3cf4eca3..8aa3e7cea 100644 --- a/docker/orthanc-anon/Dockerfile +++ b/docker/orthanc-anon/Dockerfile @@ -14,11 +14,20 @@ FROM osimis/orthanc:22.9.0-full-stable SHELL ["/bin/bash", "-o", "pipefail", "-e", "-u", "-x", "-c"] +# Install requirements before copying modules +COPY ./pixl_core/pyproject.toml ./pixl_core/pyproject.toml +COPY ./pixl_dcmd/pyproject.toml ./pixl_dcmd/pyproject.toml +RUN --mount=type=cache,target=/root/.cache \ + pip3 install pixl_core/ \ + && pip3 install pixl_dcmd/ + COPY ./orthanc/orthanc-anon/plugin/pixl.py /etc/orthanc/pixl.py COPY ./orthanc/orthanc-anon/plugin/tag-operations.yaml /etc/orthanc/tag-operations.yaml COPY ./pixl_core/ ./pixl_core -RUN pip3 install --no-cache-dir ./pixl_core +RUN --mount=type=cache,target=/root/.cache \ + pip3 install ./pixl_core COPY ./pixl_dcmd/ ./pixl_dcmd -RUN pip3 install --no-cache-dir ./pixl_dcmd \ No newline at end of file +RUN --mount=type=cache,target=/root/.cache \ + pip3 install ./pixl_dcmd \ No newline at end of file diff --git a/docker/postgres/Dockerfile b/docker/postgres/Dockerfile index dbd841609..6eb55a17f 100644 --- a/docker/postgres/Dockerfile +++ b/docker/postgres/Dockerfile @@ -27,8 +27,16 @@ COPY --chmod=0777 ./postgres/pixl-db_init.sh /docker-entrypoint-initdb.d/pixl-db COPY --chmod=0777 ./postgres/create_pixl_tbls.py /pixl/create_pixl_tbls.py +# Install requirements before copying modules +COPY ./pixl_core/pyproject.toml /pixl/pixl_core/pyproject.toml +RUN --mount=type=cache,target=/root/.cache \ + python3 -m venv /pixl/venv \ + && cd /pixl/venv/bin \ + && ./pip install /pixl/pixl_core/ + +WORKDIR /pixl/venv/bin + COPY ./pixl_core/ /pixl/pixl_core -RUN python3 -m venv /pixl/venv \ - && cd /pixl/venv/bin \ - && ./pip install /pixl/pixl_core/ +RUN --mount=type=cache,target=/root/.cache \ + ./pip install /pixl/pixl_core/ diff --git a/pixl_core/tests/Dockerfile b/pixl_core/tests/Dockerfile deleted file mode 100644 index 5a2123ea7..000000000 --- a/pixl_core/tests/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) University College London Hospitals NHS Foundation Trust -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -FROM python:3.10.6-slim-bullseye -SHELL ["/bin/bash", "-o", "pipefail", "-e", "-u", "-x", "-c"] - -WORKDIR /core -COPY . . -RUN pip install --no-cache-dir .[test] diff --git a/test/Dockerfile.fake_emap_star b/test/Dockerfile.fake_emap_star index 25e7d0b9b..37d2b243a 100644 --- a/test/Dockerfile.fake_emap_star +++ b/test/Dockerfile.fake_emap_star @@ -42,10 +42,11 @@ RUN if [ "$TAG" != "" ] ; then \ rm -rf /Satellite && \ git clone --depth 1 --branch ${TAG} https://github.com/UCLH-DIF/Satellite.git ;\ fi && \ - pip install --no-cache-dir --upgrade pip==22.3.1 + pip install --upgrade pip==22.3.1 WORKDIR /Satellite -RUN pip install --no-cache-dir . && \ +RUN --mount=type=cache,target=/root/.cache \ + pip install . && \ satellite print-db-create-command > /docker-entrypoint-initdb.d/create.sql && \ satellite print-create-command >> /docker-entrypoint-initdb.d/create.sql diff --git a/test/dummy-services/cogstack/Dockerfile b/test/dummy-services/cogstack/Dockerfile index 65366ba57..581900d41 100644 --- a/test/dummy-services/cogstack/Dockerfile +++ b/test/dummy-services/cogstack/Dockerfile @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -FROM python:3.10.6-slim-bullseye +FROM python:3.11.7-slim-bullseye RUN export DEBIAN_FRONTEND=noninteractive && \ apt-get update && \ @@ -23,6 +23,7 @@ WORKDIR /app COPY cogstack.py . COPY pyproject.toml . -RUN pip install -e . +RUN --mount=type=cache,target=/root/.cache \ + pip install -e . ENTRYPOINT ["uvicorn", "cogstack:app", "--host", "0.0.0.0", "--port", "8000"]