Skip to content

Commit 0ef1bd4

Browse files
authored
Merge pull request #384 from camptocamp/poetry-gsgmf-1726
Use Poetry instead of Pipenv
2 parents 808cd70 + 04c04c9 commit 0ef1bd4

17 files changed

+1627
-986
lines changed

.dockerignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
!runtime-desktop
55
!requirements.txt
66
!requirements-desktop.txt
7-
!Pipfile*
87
!cache
98
!package.json
109
!package-lock.json
10+
!pyproject.toml
11+
!poetry.lock

.hadolint.yaml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
ignored:
2-
- DL3008 # pin version: https://github.com/hadolint/hadolint/wiki/DL3008
3-
- DL3003 # use workdir: https://github.com/hadolint/hadolint/wiki/DL3003
2+
- DL3003 # Use WORKDIR to switch to a directory
3+
- DL3008 # Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
4+
- DL3042 # Avoid use of cache directory with pip. Use `pip install --no-cache-dir <package>`
45
- DL3059 # Multiple consecutive `RUN` instructions. Consider consolidation.
6+
- SC1091 # Not following: File not included in mock.
57
- SC2164 # Use cd ... || exit in case cd fails.

.prettierignore

-2
This file was deleted.

Dockerfile

+50-39
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,38 @@
1-
FROM osgeo/gdal:ubuntu-small-3.5.0 as base
1+
FROM osgeo/gdal:ubuntu-small-3.5.0 as base-all
2+
LABEL maintainer Camptocamp "info@camptocamp.com"
3+
SHELL ["/bin/bash", "-o", "pipefail", "-cux"]
24

3-
RUN --mount=type=cache,target=/var/lib/apt/lists,id=apt-list \
5+
RUN --mount=type=cache,target=/var/lib/apt/lists \
6+
--mount=type=cache,target=/var/cache,sharing=locked \
47
apt-get update \
5-
&& apt-get upgrade --yes
8+
&& apt-get upgrade --assume-yes \
9+
&& DEBIAN_FRONTEND=noninteractive apt-get install --assume-yes --no-install-recommends python3-pip
610

7-
SHELL ["/bin/bash", "-o", "pipefail", "-cux"]
11+
# Used to convert the locked packages by poetry to pip requirements format
12+
# We don't directly use `poetry install` because it force to use a virtual environment.
13+
FROM base-all as poetry
14+
15+
# Install Poetry
16+
WORKDIR /tmp
17+
COPY requirements.txt ./
18+
RUN --mount=type=cache,target=/root/.cache \
19+
python3 -m pip install --disable-pip-version-check --requirement=requirements.txt
820

9-
FROM base as builder
21+
# Do the conversion
22+
COPY poetry.lock pyproject.toml ./
23+
RUN poetry export --output=requirements.txt \
24+
&& poetry export --extras=desktop --output=requirements-desktop.txt
25+
26+
# Base, the biggest thing is to install the Python packages
27+
FROM base-all as builder
1028
LABEL maintainer="info@camptocamp.com"
1129

30+
SHELL ["/bin/bash", "-o", "pipefail", "-cux"]
31+
1232
RUN --mount=type=cache,target=/var/lib/apt/lists,id=apt-list \
1333
--mount=type=cache,target=/var/cache,id=var-cache,sharing=locked \
14-
. /etc/os-release \
34+
apt-get update \
35+
&& . /etc/os-release \
1536
&& apt-get install --assume-yes --no-install-recommends apt-utils software-properties-common \
1637
&& apt-get autoremove --assume-yes software-properties-common \
1738
&& LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install --assume-yes --no-install-recommends cmake gcc \
@@ -20,7 +41,7 @@ RUN --mount=type=cache,target=/var/lib/apt/lists,id=apt-list \
2041
libqt5scintilla2-dev libqt5opengl5-dev libqt5sql5-sqlite libqt5webkit5-dev qtpositioning5-dev \
2142
qtxmlpatterns5-dev-tools libqt5xmlpatterns5-dev libqt5svg5-dev libqwt-qt5-dev libspatialindex-dev \
2243
libspatialite-dev libsqlite3-dev libqt5designer5 qttools5-dev qt5keychain-dev lighttpd locales \
23-
pkg-config poppler-utils python3 python3-dev python3-pip python3-setuptools \
44+
pkg-config poppler-utils python3 python3-dev python3-pip \
2445
pyqt5-dev pyqt5-dev-tools pyqt5.qsci-dev python3-pyqt5.qtsql python3-pyqt5.qsci python3-pyqt5.qtpositioning \
2546
python3-sip python3-sip-dev qtscript5-dev spawn-fcgi xauth xfonts-100dpi \
2647
xfonts-75dpi xfonts-base xfonts-scalable xvfb git ninja-build ccache clang libpython3-dev \
@@ -38,16 +59,9 @@ RUN npm install
3859

3960
WORKDIR /tmp
4061

41-
COPY requirements.txt ./
42-
# hadolint ignore=DL3042
43-
RUN --mount=type=cache,target=/root/.cache,id=root-cache \
44-
python3 -m pip install --disable-pip-version-check --requirement=requirements.txt \
45-
&& rm --recursive --force /tmp/*
46-
47-
COPY Pipfile Pipfile.lock ./
48-
RUN --mount=type=cache,target=/root/.cache,id=root-cache \
49-
pipenv sync --system --dev \
50-
&& rm --recursive --force /usr/local/lib/python3.*/dist-packages/tests/ /tmp/* /root/.cache/* \
62+
RUN --mount=type=cache,target=/root/.cache \
63+
--mount=type=bind,from=poetry,source=/tmp,target=/poetry \
64+
python3 -m pip install --disable-pip-version-check --no-deps --requirement=/poetry/requirements.txt \
5165
&& (strip /usr/local/lib/python3.*/dist-packages/*/*.so || true)
5266

5367
RUN ln -s /usr/local/lib/libproj.so.* /usr/local/lib/libproj.so
@@ -115,36 +129,29 @@ RUN --mount=type=cache,target=/root/.ccache,id=ccache \
115129

116130
RUN ninja install
117131

118-
FROM base as runner
132+
FROM base-all as runner
119133
LABEL maintainer="info@camptocamp.com"
120134

121135
RUN --mount=type=cache,target=/var/lib/apt/lists,id=apt-list \
122136
--mount=type=cache,target=/var/cache,id=var-cache,sharing=locked \
123-
DEBIAN_FRONTEND=noninteractive apt-get install --assume-yes --no-install-recommends \
124-
libfcgi libgslcblas0 libqca-qt5-2 libqca-qt5-2-plugins libzip5 \
125-
libqt5opengl5 libqt5sql5-sqlite libqt5concurrent5 libqt5positioning5 libqt5script5 \
126-
libqt5webkit5 libqwt-qt5-6 libspatialindex6 libspatialite7 libsqlite3-0 libqt5keychain1 \
127-
python3 python3-pip python3-setuptools \
128-
python3-pyqt5 python3-pyqt5.qtsql python3-pyqt5.qsci python3-pyqt5.qtpositioning \
129-
spawn-fcgi xauth xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable xvfb \
130-
apache2 libapache2-mod-fcgid python3 \
131-
libqt5serialport5 libqt5quickwidgets5 libexiv2-27 libprotobuf17 libprotobuf-lite17 \
132-
libgsl23 libzstd1 binutils \
137+
apt-get update \
138+
&& DEBIAN_FRONTEND=noninteractive apt-get install --assume-yes --no-install-recommends \
139+
libfcgi libgslcblas0 libqca-qt5-2 libqca-qt5-2-plugins libzip5 \
140+
libqt5opengl5 libqt5sql5-sqlite libqt5concurrent5 libqt5positioning5 libqt5script5 \
141+
libqt5webkit5 libqwt-qt5-6 libspatialindex6 libspatialite7 libsqlite3-0 libqt5keychain1 \
142+
python3 python3-pip \
143+
python3-pyqt5 python3-pyqt5.qtsql python3-pyqt5.qsci python3-pyqt5.qtpositioning \
144+
spawn-fcgi xauth xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable xvfb \
145+
apache2 libapache2-mod-fcgid python3 \
146+
libqt5serialport5 libqt5quickwidgets5 libexiv2-27 libprotobuf17 libprotobuf-lite17 \
147+
libgsl23 libzstd1 binutils \
133148
&& strip --remove-section=.note.ABI-tag /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
134149

135150
WORKDIR /tmp
136151

137-
COPY requirements.txt ./
138-
# hadolint ignore=DL3042
139-
RUN --mount=type=cache,target=/root/.cache,id=root-cache \
140-
python3 -m pip install --disable-pip-version-check --requirement=requirements.txt \
141-
&& rm --recursive --force /tmp/*
142-
143-
COPY Pipfile Pipfile.lock ./
144-
RUN --mount=type=cache,target=/root/.cache,id=root-cache \
145-
pipenv sync --system \
146-
&& rm --recursive --force /usr/local/lib/python3.*/dist-packages/tests/ /tmp/* /root/.cache/* \
147-
&& (strip /usr/local/lib/python3.*/dist-packages/*/*.so || true)
152+
RUN --mount=type=cache,target=/root/.cache \
153+
--mount=type=bind,from=poetry,source=/tmp,target=/poetry \
154+
python3 -m pip install --disable-pip-version-check --no-deps --requirement=/poetry/requirements.txt
148155

149156
FROM runner as runner-server
150157

@@ -227,6 +234,10 @@ RUN --mount=type=cache,target=/root/.cache,id=root-cache \
227234
python3 -m pip install --disable-pip-version-check --requirement=requirements-desktop.txt \
228235
&& rm --recursive --force /tmp/*
229236

237+
RUN --mount=type=cache,target=/root/.cache \
238+
--mount=type=bind,from=poetry,source=/tmp,target=/poetry \
239+
python3 -m pip install --disable-pip-version-check --no-deps --requirement=/poetry/requirements-desktop.txt
240+
230241
COPY --from=builder-desktop /usr/local/bin /usr/local/bin/
231242
COPY --from=builder-desktop /usr/local/lib /usr/local/lib/
232243
COPY --from=builder-desktop /usr/local/share /usr/local/share/

Makefile

+15-10
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,35 @@ QGIS_BRANCH = master
22
DOCKER_TAG ?= latest
33
DOCKER_BASE = camptocamp/qgis-server
44
ROOT = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
5+
export DOCKER_BUILDKIT = 1
56

67
DOCKER_COMPOSE_TTY := $(shell [ ! -t 0 ] && echo -T)
78
BUILD_OPTIONS = build
89

10+
.PHONY: help
11+
help: ## Display this help message
12+
@echo "Usage: make <target>"
13+
@echo
14+
@echo "Available targets:"
15+
@grep --extended-regexp --no-filename '^[a-zA-Z_-]+:.*## ' $(MAKEFILE_LIST) | sort | \
16+
awk 'BEGIN {FS = ":.*?## "}; {printf " %-20s%s\n", $$1, $$2}'
17+
918
.PHONY: all
10-
all: build acceptance
19+
all: build acceptance ## Build and run acceptance tests
1120

1221
.PHONY: build-server
13-
build-server:
22+
build-server: ## Build the server Docker image
1423
DOCKER_BUILDKIT=1 docker $(BUILD_OPTIONS) --target=runner-server --tag=$(DOCKER_BASE):$(DOCKER_TAG) --build-arg=QGIS_BRANCH=$(QGIS_BRANCH) .
1524

1625
.PHONY: build-desktop
17-
build-desktop:
26+
build-desktop: ## Build the desktop Docker image
1827
DOCKER_BUILDKIT=1 docker $(BUILD_OPTIONS) --target=runner-desktop --tag=$(DOCKER_BASE):$(DOCKER_TAG)-desktop --build-arg=QGIS_BRANCH=$(QGIS_BRANCH) .
1928

2029
.PHONY: build-cache
2130
build-cache:
2231
DOCKER_BUILDKIT=1 docker $(BUILD_OPTIONS) --target=cache --tag=qgis-cache --build-arg=QGIS_BRANCH=$(QGIS_BRANCH) .
2332

24-
.PHONY: build
33+
.PHONY: build ## Build all the Docker images
2534
build: build-server build-desktop
2635

2736
.PHONY: build-acceptance-config
@@ -38,16 +47,12 @@ run: build-acceptance
3847
cd acceptance_tests; docker-compose up -d
3948

4049
.PHONY: acceptance
41-
acceptance: run
50+
acceptance: run ## Run the acceptance tests
4251
cd acceptance_tests; docker-compose exec $(DOCKER_COMPOSE_TTY) run pytest -vv --color=yes --junitxml=/tmp/junitxml/results.xml
4352
cd acceptance_tests; docker-compose exec $(DOCKER_COMPOSE_TTY) qgis python3 -c 'import qgis'
4453

45-
.PHONY: pull
46-
pull:
47-
for image in `find -name Dockerfile | xargs grep --no-filename ^FROM |grep -v 'FROM runner'|grep -v 'FROM builder'| awk '{print $$2}'`; do docker pull $$image; done
48-
4954
.PHONY: run-client
50-
run-client:
55+
run-client: ## Run the desktop application
5156
docker run --rm -ti -e DISPLAY=unix${DISPLAY} --volume=/tmp/.X11-unix:/tmp/.X11-unix --volume=${HOME}:${HOME} $(DOCKER_BASE):$(DOCKER_TAG)-desktop
5257

5358
clean:

Pipfile

-15
This file was deleted.

Pipfile.lock

-99
This file was deleted.

acceptance_tests/Dockerfile

+31-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,41 @@
1-
FROM python:3.10.5
1+
FROM python:3.10.5 as base-all
2+
LABEL maintainer "info@camptocamp.org"
3+
4+
SHELL ["/bin/bash", "-o", "pipefail", "-cux"]
5+
6+
RUN --mount=type=cache,target=/var/lib/apt/lists \
7+
--mount=type=cache,target=/var/cache,sharing=locked \
8+
apt-get update \
9+
&& apt-get upgrade --assume-yes \
10+
&& DEBIAN_FRONTEND=noninteractive apt-get install --assume-yes --no-install-recommends python3-pip
11+
12+
# Used to convert the locked packages by poetry to pip requirements format
13+
# We don't directly use `poetry install` because it force to use a virtual environment.
14+
FROM base-all as poetry
15+
16+
# Install Poetry
17+
WORKDIR /tmp
18+
COPY requirements.txt ./
19+
RUN --mount=type=cache,target=/root/.cache \
20+
python3 -m pip install --disable-pip-version-check --requirement=requirements.txt
21+
22+
# Do the conversion
23+
COPY poetry.lock pyproject.toml ./
24+
RUN poetry export --dev --output=requirements-dev.txt
25+
26+
# Base, the biggest thing is to install the Python packages
27+
FROM base-all
228

329
RUN mkdir -p /tmp/junitxml
430

5-
COPY requirements.txt /tmp/
6-
RUN python3 -m pip install --disable-pip-version-check --no-cache-dir --requirement=/tmp/requirements.txt \
7-
&& rm --recursive --force /tmp/*
31+
RUN --mount=type=cache,target=/root/.cache \
32+
--mount=type=bind,from=poetry,source=/tmp,target=/poetry \
33+
python3 -m pip install --disable-pip-version-check --no-deps --requirement=/poetry/requirements-dev.txt
834

935
WORKDIR /acceptance_tests
1036

11-
COPY Pipfile Pipfile.lock ./
12-
RUN pipenv sync --system --clear --dev \
13-
&& rm --recursive --force /usr/local/lib/python3.*/dist-packages/tests/ /tmp/* /root/.cache/*
14-
1537
COPY . ./
1638

1739
ENV DOCKER_RUN 1
1840

19-
CMD ["sleep", "infinity"]
41+
CMD ["tail", "--follow", "/dev/null"]

acceptance_tests/Pipfile

-13
This file was deleted.

0 commit comments

Comments
 (0)