Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .github/workflows/build_docker_images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ jobs:
DOCKER_VERSION=$(echo "${DOCKER}" | jq ".${{ matrix.version }}")
QGIS_VERSION=$(echo "${QGIS}" | jq ".${{ matrix.version }}")

QGIS_REF="NA"
TEST_URL="refs/heads"
if ! [[ "$QGIS_VERSION" == "master" || ]]; then
QGIS_REF=master
elif [[ "$QGIS_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
QGIS_REF="final-${QGIS_VERSION//./_}"
TEST_URL="refs/tags"
fi
if ! wget -q --spider https://api.github.com/repos/qgis/QGIS/git/${TEST_URL}/${QGIS_REF}; then
echo "Invalid git ref '${QGIS_REF}' for version '${QGIS_VERSION}'"
exit 1
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as requested, the logic to get the git ref is now in in the workflow.

as you can see, this simply assumes that any QGIS_VERSION will map to final-x_y_z tags (or simply master), it doesn't care about ltr-x_y tags. I'm not entirely sure what QGIS_VERSION can be, maybe you have a better idea here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, this shell code became a bit too big to be inlined. it's quite cumbersome to test changes locally. IMHO it'd be better to outsource this to a proper script and at least run shellcheck or so on the scripts, ideally even testing the image a bit (more) before pushing it. What do you think?

fi

echo "Existing ${{ matrix.version }} docker: ${DOCKER_VERSION}"
echo "Available ${{ matrix.version }} QGIS: ${QGIS_VERSION}"

Expand All @@ -111,6 +124,7 @@ jobs:

echo "will_update=${WILL_UPDATE}" >> $GITHUB_OUTPUT
echo "qgis_version=${QGIS_VERSION//\"/}">> $GITHUB_OUTPUT
echo "qgis_ref=${QGIS_REF}" >> $GITHUB_OUTPUT

- name: Set up QEMU
if: ${{ steps.determine.outputs.will_update == 1 }}
Expand All @@ -136,4 +150,4 @@ jobs:
env:
DOCKER_USERNAME: ${{ secrets.docker_username }}
DOCKER_PASSWORD: ${{ secrets.docker_password }}
run: ./scripts/build-push-docker.sh ${{ matrix.qgis_type }} ${{ matrix.version }} ${{steps.determine.outputs.qgis_version}} ${{ matrix.platform.os }} ${{ matrix.platform.release }} ${DEFAULT_UBUNTU_RELEASE}
run: ./scripts/build-push-docker.sh ${{ matrix.qgis_type }} ${{ matrix.version }} ${{steps.determine.outputs.qgis_version}} ${{ matrix.platform.os }} ${{ matrix.platform.release }} ${DEFAULT_UBUNTU_RELEASE} ${{ steps.determine.outputs.qgis_ref }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This repository automates the build of QGIS desktop and QGIS server Docker image

[![Docker Hub](https://img.shields.io/docker/pulls/qgis/qgis)](https://hub.docker.com/r/qgis/qgis)

- [Documentation](./desktop/README.md)
- [Documentation](./desktop/README.md), including instructions to test QGIS plugins

## Server

Expand Down
10 changes: 7 additions & 3 deletions desktop/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ ARG release=noble
FROM ${os}:${release}
LABEL maintainer="OPENGIS.ch <info@opengis.ch>"

ARG os
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not used anymore after

ARG release
ARG repo
ARG qgis_version=master
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to where it's used, for layer caching purposes


RUN apt update && apt install -y gnupg wget software-properties-common && \
wget -qO - https://qgis.org/downloads/qgis-2022.gpg.key | gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/qgis-archive.gpg --import && \
Expand All @@ -20,6 +18,12 @@ RUN apt update && apt install -y gnupg wget software-properties-common && \
python3-pytest python3-mock xvfb qttools5-dev-tools pyqt5-dev-tools && \
apt-get clean

# Test version
# Test version and download plugin test scripts
COPY scripts/check_version.sh /opt/check_version.sh
COPY scripts/qgis_test_setup.sh /opt/qgis_test_setup.sh

ARG qgis_version=master
ARG qgis_ref

RUN /opt/check_version.sh ${qgis_version}
RUN /opt/qgis_test_setup.sh ${qgis_ref}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will download and install the necessary scripts from qgis_ref

22 changes: 22 additions & 0 deletions desktop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,25 @@
[![Docker Hub](https://img.shields.io/docker/pulls/qgis/qgis)](https://hub.docker.com/r/qgis/qgis)

A simple QGIS desktop Docker image, pushed on [Docker Hub](https://hub.docker.com/r/qgis/qgis).

## Python Plugin testing

This image can be used to set up a testing environment for plugins, e.g.

```
PLUGIN_DIR=<plugin_name> # e.g. PLUGIN_NAME=valhalla
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this with https://github.com/nilsnolde/valhalla-qgis-plugin, should work similarly for all plugins

# it's important to map the plugin's root to /tests_directory and that $PLUGIN_DIR is the sub-directory containing the plugin sources
docker run -dt --name qgis -v ${PWD}:/tests_directory -e QT_QPA_PLATFORM="offscreen" qgis/qgis:latest
# run the qgis_setup.sh script and then your tests, e.g.
docker exec qgis bash -c "qgis_setup.sh ${PLUGIN_DIR}"
# now you can run whatever you need
docker exec qgis bash -c "apt-get update && apt-get install -y pre-commit python3-coverage"
docker exec qgis bash -c "git config --global --add safe.directory /tests_directory"
docker exec qgis bash -c "cd /tests_directory && pre-commit run --all-files"
docker exec qgis bash -c "cd /tests_directory && python3 -m coverage run -m unittest discover"
docker exec qgis bash -c "cd /tests_directory && python3 -m coverage report"
docker exec qgis bash -c "cd /tests_directory && python3 -m coverage report"
```
2 changes: 2 additions & 0 deletions scripts/build-push-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ QGIS_VERSION=$3
OS=$4
OS_RELEASE=$5
DEFAULT_OS_RELEASE=$6
QGIS_REF=$7

MAJOR_QGIS_VERSION=$(echo "${QGIS_VERSION}" | cut -d. -f1,2)

Expand Down Expand Up @@ -50,4 +51,5 @@ docker buildx build --push --platform linux/amd64 \
--build-arg release=${OS_RELEASE} \
--build-arg repo=${QGIS_PPA} \
--build-arg qgis_version=${QGIS_VERSION} \
--build-arg qgis_ref=${QGIS_REF} \
${ALL_TAGS} -f ${QGIS_TYPE}/Dockerfile .
30 changes: 30 additions & 0 deletions scripts/qgis_test_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

# Makes the qgis_setup.sh script available for plugin testing

# Usage: qgis_test_setup.sh <docker_tag> <plugin_name>, e.g. ./qgis_test_setup.sh 3.44.1

set -euo pipefail

# Check if version argument is provided
if [[ -z "$1" ]]; then
echo "Usage: $0 <QGIS git ref, e.g. final-3_44_1 or master>"
exit 1
fi

# Convert docker version to branch name
QGIS_REF="$1"

SETUP_SCRIPT_URL="https://raw.githubusercontent.com/qgis/QGIS/${QGIS_REF}/.docker/qgis_resources/test_runner/qgis_setup.sh"
SETUP_SCRIPT_PATH="/usr/bin/$(basename ${SETUP_SCRIPT_URL})"

STARTUP_SCRIPT_URL="https://raw.githubusercontent.com/qgis/QGIS/${QGIS_REF}/.docker/qgis_resources/test_runner/qgis_startup.py"
STARTUP_SCRIPT_PATH="/usr/bin/$(basename ${STARTUP_SCRIPT_URL})"

echo "Downloading qgis_setup.sh and friends from ref ${QGIS_REF}..."

wget -q -O "$SETUP_SCRIPT_PATH" "$SETUP_SCRIPT_URL"
wget -q -O "$STARTUP_SCRIPT_PATH" "$STARTUP_SCRIPT_URL"

chmod +x "$SETUP_SCRIPT_PATH"
chmod +x "$STARTUP_SCRIPT_PATH"