Skip to content

Commit

Permalink
Use a venv, remove some Poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Nov 4, 2024
1 parent bc3ef7f commit c3bf85d
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 313 deletions.
4 changes: 0 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
!checkout_release
!runtime
!runtime-desktop
!requirements.txt
!requirements-desktop.txt
!cache
!package.json
!package-lock.json
!.nvmrc
!pyproject.toml
!poetry.lock
4 changes: 1 addition & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ repos:
rev: 1.1.2
hooks:
- id: copyright
- id: poetry-check
additional_dependencies:
- poetry==1.8.4 # pypi
- id: poetry-lock
additional_dependencies:
- poetry==1.8.4 # pypi
exclude: ^pyproject\.toml$
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
Expand Down
53 changes: 11 additions & 42 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/osgeo/gdal:ubuntu-small-3.9.3 as base-all
FROM ghcr.io/osgeo/gdal:ubuntu-small-3.9.3 AS base-all
LABEL maintainer Camptocamp "info@camptocamp.com"
SHELL ["/bin/bash", "-o", "pipefail", "-cux"]

Expand All @@ -8,23 +8,7 @@ RUN --mount=type=cache,target=/var/lib/apt/lists \
&& apt-get upgrade --assume-yes \
&& DEBIAN_FRONTEND=noninteractive apt-get install --assume-yes --no-install-recommends python3-pip

# Used to convert the locked packages by poetry to pip requirements format
# We don't directly use `poetry install` because it force to use a virtual environment.
FROM base-all as poetry

# Install Poetry
WORKDIR /tmp
COPY requirements.txt ./
RUN --mount=type=cache,target=/root/.cache \
python3 -m pip install --disable-pip-version-check --requirement=requirements.txt

# Do the conversion
COPY poetry.lock pyproject.toml ./
RUN poetry export --output=requirements.txt \
&& poetry export --extras=desktop --output=requirements-desktop.txt

# Base, the biggest thing is to install the Python packages
FROM base-all as builder
FROM base-all AS builder
LABEL maintainer="info@camptocamp.com"

SHELL ["/bin/bash", "-o", "pipefail", "-cux"]
Expand Down Expand Up @@ -55,7 +39,7 @@ RUN --mount=type=cache,target=/var/lib/apt/lists,id=apt-list \
python3-markupsafe python3-mock python3-nose2 python3-owslib python3-plotly python3-psycopg2 \
python3-pygments python3-pyqt5 python3-pyqt5.qsci python3-pyqt5.qtpositioning \
python3-pyqt5.qtsql python3-pyqt5.qtsvg python3-pyqt5.qtwebkit python3-requests \
python3-sip python3-sip-dev python3-termcolor python3-tz python3-yaml qt3d-assimpsceneimport-plugin \
python3-sip python3-sip-dev python3-termcolor python3-tz python3-yaml python3-geolinks qt3d-assimpsceneimport-plugin \
qt3d-defaultgeometryloader-plugin qt3d-gltfsceneio-plugin qt3d-scene2d-plugin qt3d5-dev \
qtbase5-dev qtbase5-private-dev qtkeychain-qt5-dev qtpositioning5-dev qttools5-dev \
qttools5-dev-tools spawn-fcgi xauth xfonts-100dpi xfonts-75dpi xfonts-base \
Expand All @@ -71,11 +55,6 @@ ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/n

WORKDIR /tmp/

RUN --mount=type=cache,target=/root/.cache \
--mount=type=bind,from=poetry,source=/tmp,target=/poetry \
python3 -m pip install --disable-pip-version-check --no-deps --requirement=/poetry/requirements.txt \
&& (strip /usr/local/lib/python3.*/dist-packages/*/*.so || true)

ARG QGIS_BRANCH

RUN git clone https://github.com/qgis/QGIS --branch=${QGIS_BRANCH} --depth=100 /src
Expand Down Expand Up @@ -111,12 +90,12 @@ RUN --mount=type=cache,target=/root/.ccache,id=ccache \
&& ninja \
&& ccache --show-stats

FROM builder as builder-server
FROM builder AS builder-server

RUN ninja install
RUN rm -rf /usr/local/share/qgis/i18n/

FROM builder as builder-server-debug
FROM builder AS builder-server-debug

RUN cmake .. \
-GNinja \
Expand All @@ -140,7 +119,7 @@ RUN --mount=type=cache,target=/root/.ccache,id=ccache \

RUN ninja install

FROM builder as builder-desktop
FROM builder AS builder-desktop

# -DWITH_3D=ON generate error: undefined reference to `Qt3DExtras::Qt3DWindow::Qt3DWindow(QScreen*)'
RUN cmake .. \
Expand All @@ -166,7 +145,7 @@ RUN --mount=type=cache,target=/root/.ccache,id=ccache \

RUN ninja install

FROM base-all as runner
FROM base-all AS runner
LABEL maintainer="info@camptocamp.com"

RUN --mount=type=cache,target=/var/lib/apt/lists,id=apt-list \
Expand All @@ -187,12 +166,7 @@ RUN --mount=type=cache,target=/var/lib/apt/lists,id=apt-list \

WORKDIR /tmp

RUN --mount=type=cache,target=/root/.cache \
--mount=type=bind,from=poetry,source=/tmp,target=/poetry \
python3 -m pip install --disable-pip-version-check --no-deps --requirement=/poetry/requirements.txt \
&& python3 -m pip freeze > /requirements.txt

FROM runner as runner-server
FROM runner AS runner-server

RUN --mount=type=cache,target=/var/lib/apt/lists,id=apt-list \
--mount=type=cache,target=/var/cache,id=var-cache,sharing=locked \
Expand Down Expand Up @@ -263,7 +237,7 @@ EXPOSE 8080
CMD ["/usr/local/bin/start-server"]


FROM runner-server as runner-server-debug
FROM runner-server AS runner-server-debug

RUN --mount=type=cache,target=/var/lib/apt/lists,id=apt-list \
--mount=type=cache,target=/var/cache,id=var-cache,sharing=locked \
Expand All @@ -275,7 +249,7 @@ COPY --from=builder-server-debug /usr/local/bin /usr/local/bin/
COPY --from=builder-server-debug /usr/local/lib /usr/local/lib/
COPY --from=builder-server-debug /usr/local/share/qgis /usr/local/share/qgis

FROM runner as runner-desktop
FROM runner AS runner-desktop

RUN --mount=type=cache,target=/var/lib/apt/lists,id=apt-list \
--mount=type=cache,target=/var/cache,id=var-cache,sharing=locked \
Expand All @@ -288,11 +262,6 @@ RUN --mount=type=cache,target=/root/.cache,id=root-cache \
python3 -m pip install --disable-pip-version-check --requirement=requirements-desktop.txt \
&& rm --recursive --force /tmp/*

RUN --mount=type=cache,target=/root/.cache \
--mount=type=bind,from=poetry,source=/tmp,target=/poetry \
python3 -m pip install --disable-pip-version-check --no-deps --requirement=/poetry/requirements-desktop.txt \
&& python3 -m pip freeze > /requirements.txt

COPY --from=builder-desktop /usr/local/bin /usr/local/bin/
COPY --from=builder-desktop /usr/local/lib /usr/local/lib/
COPY --from=builder-desktop /usr/local/share /usr/local/share/
Expand All @@ -303,7 +272,7 @@ RUN ldconfig
WORKDIR /etc/qgisserver
CMD ["/usr/local/bin/start-client"]

FROM builder as cache
FROM builder AS cache

RUN --mount=type=cache,target=/root/.ccache,id=ccache \
ccache --show-stats \
Expand Down
5 changes: 4 additions & 1 deletion acceptance_tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ RUN --mount=type=cache,target=/var/lib/apt/lists \
--mount=type=cache,target=/var/cache,sharing=locked \
apt-get update \
&& apt-get upgrade --assume-yes \
&& DEBIAN_FRONTEND=noninteractive apt-get install --assume-yes --no-install-recommends python3-pip
&& DEBIAN_FRONTEND=noninteractive apt-get install --assume-yes --no-install-recommends python3-pip python3-venv \
&& pythone -m venv /venv

ENV PATH=/venv/bin:$PATH

# Used to convert the locked packages by poetry to pip requirements format
# We don't directly use `poetry install` because it force to use a virtual environment.
Expand Down
Loading

0 comments on commit c3bf85d

Please sign in to comment.