Skip to content

Commit

Permalink
run pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Jul 16, 2024
1 parent dd89f4b commit 368f62b
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 88 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/build_docker_images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:

- id: determine
name: determine QGIS and Docker versions
env:
env:
GITHUB_EVENT_NAME: ${{ github.event_name }}
run : |
DOCKER=$(./scripts/get_docker_image_version.py --qgis=${{ matrix.qgis_type }} --dist=${{ matrix.platform.release }})
Expand All @@ -99,14 +99,14 @@ jobs:
echo "Existing ${{ matrix.version }} docker: ${DOCKER_VERSION}"
echo "Available ${{ matrix.version }} QGIS: ${QGIS_VERSION}"
WILL_UPDATE=$(python3 -c "from packaging import version; print(1 if version.parse(${DOCKER_VERSION} or '0') < version.parse(${QGIS_VERSION}) else 0)")
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
echo "Force build on workflow dispatch."
WILL_UPDATE=1
fi
if [[ ${WILL_UPDATE} == 1 ]]; then
echo "--> ${{ matrix.version }} will be updated from ${DOCKER_VERSION} to ${QGIS_VERSION}."
else
Expand Down Expand Up @@ -141,4 +141,3 @@ jobs:
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}

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*.orig
.idea
__pycache__
__pycache__
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This repository automates the build of QGIS desktop and QGIS server Docker image
- [QGIS Server](./server/README.md)
- [QGIS Desktop](./desktop/README.md)

**Warning**:
**Warning**:

There are discussions on how to build these images and they are not considered stable.
There are discussions on how to build these images and they are not considered stable.
They are considered as NOT production ready.
2 changes: 1 addition & 1 deletion desktop/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ 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 && \
chmod a+r /etc/apt/trusted.gpg.d/qgis-archive.gpg && \
# run twice because of https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1041012
add-apt-repository "deb https://qgis.org/${repo} ${release} main" && \
add-apt-repository "deb https://qgis.org/${repo} ${release} main" && \
add-apt-repository "deb https://qgis.org/${repo} ${release} main" && \
apt update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y python3-pip qgis python3-qgis python3-qgis-common python3-venv \
Expand Down
4 changes: 2 additions & 2 deletions desktop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ A simple QGIS desktop Docker image

**Warning**

There are discussions on how to build these images and they are not considered stable.
They are considered as NOT production ready.
There are discussions on how to build these images and they are not considered stable.
They are considered as NOT production ready.
73 changes: 33 additions & 40 deletions scripts/apt_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lzma
import posixpath
import re

import requests


Expand All @@ -26,7 +27,7 @@ def _download(url):
# Arguments
url (str): URL to file
"""
return __download_raw(url).decode('utf-8')
return __download_raw(url).decode("utf-8")


def _download_compressed(base_url):
Expand All @@ -39,10 +40,10 @@ def _download_compressed(base_url):
url (str): URL to file
"""
decompress = {
'': lambda c: c,
'.xz': lambda c: lzma.decompress(c),
'.gz': lambda c: gzip.decompress(c),
'.bzip2': lambda c: bz2.decompress(c)
"": lambda c: c,
".xz": lambda c: lzma.decompress(c),
".gz": lambda c: gzip.decompress(c),
".bzip2": lambda c: bz2.decompress(c),
}

for suffix, method in decompress.items():
Expand All @@ -53,7 +54,7 @@ def _download_compressed(base_url):
except requests.error.URLError:
continue

return method(req.content).decode('utf-8')
return method(req.content).decode("utf-8")


def _get_value(content, key):
Expand All @@ -64,7 +65,7 @@ def _get_value(content, key):
content (str): the content of the Packages/Release file
key (str): the key to return the value for
"""
pattern = key + ': (.*)\n'
pattern = key + ": (.*)\n"
match = re.search(pattern, content)
try:
return match.group(1)
Expand All @@ -79,44 +80,45 @@ class ReleaseFile:
# Arguments
content (str): the content of the Release file
"""

def __init__(self, content):
self.__content = content.strip()

@property
def origin(self):
return _get_value(self.__content, 'Origin')
return _get_value(self.__content, "Origin")

@property
def label(self):
return _get_value(self.__content, 'Label')
return _get_value(self.__content, "Label")

@property
def suite(self):
return _get_value(self.__content, 'Suite')
return _get_value(self.__content, "Suite")

@property
def version(self):
return _get_value(self.__content, 'Version')
return _get_value(self.__content, "Version")

@property
def codename(self):
return _get_value(self.__content, 'Codename')
return _get_value(self.__content, "Codename")

@property
def date(self):
return _get_value(self.__content, 'Date')
return _get_value(self.__content, "Date")

@property
def architectures(self):
return _get_value(self.__content, 'Architectures').split()
return _get_value(self.__content, "Architectures").split()

@property
def components(self):
return _get_value(self.__content, 'Components').split()
return _get_value(self.__content, "Components").split()

@property
def description(self):
return _get_value(self.__content, 'Description')
return _get_value(self.__content, "Description")


class PackagesFile:
Expand All @@ -126,14 +128,15 @@ class PackagesFile:
# Arguments
content (str): the content of the Packages file
"""

def __init__(self, content):
self.__content = content.strip()

@property
def packages(self):
"""Returns all binary packages in this Packages files"""
packages = []
for package_content in self.__content.split('\n\n'):
for package_content in self.__content.split("\n\n"):
if not package_content:
continue

Expand All @@ -150,20 +153,21 @@ class BinaryPackage:
# Arguments
content (str): the section of the Packages file for this specific package
"""

def __init__(self, content):
self.__content = content.strip()

@property
def package(self):
return _get_value(self.__content, 'Package')
return _get_value(self.__content, "Package")

@property
def version(self):
return _get_value(self.__content, 'Version')
return _get_value(self.__content, "Version")

@property
def filename(self):
return _get_value(self.__content, 'Filename')
return _get_value(self.__content, "Filename")


class APTRepository:
Expand All @@ -181,6 +185,7 @@ class APTRepository:
APTRepository('https://pkg.jenkins.io/debian/', 'binary')
```
"""

def __init__(self, url, dist, components=[]):
self.url = url
self.dist = dist
Expand Down Expand Up @@ -219,19 +224,14 @@ def all_components(self):
@property
def release_file(self):
"""Returns the Release file of this repository"""
url = posixpath.join(
self.url,
'dists',
self.dist,
'Release'
)
url = posixpath.join(self.url, "dists", self.dist, "Release")

release_content = _download(url)

return ReleaseFile(release_content)

@property
def packages(self, arch='amd64'):
def packages(self, arch="amd64"):
"""
Returns all binary packages of this repository
Expand All @@ -246,7 +246,7 @@ def packages(self, arch='amd64'):

return packages

def get_binary_packages_by_component(self, component, arch='amd64'):
def get_binary_packages_by_component(self, component, arch="amd64"):
"""
Returns all binary packages of this repository for a given component
Expand All @@ -255,19 +255,11 @@ def get_binary_packages_by_component(self, component, arch='amd64'):
arch (str): the architecture to return packages for, default: 'amd64'
"""
if component is None:
url = posixpath.join(
self.url,
self.dist,
'Packages')
url = posixpath.join(self.url, self.dist, "Packages")
else:
url = posixpath.join(
self.url,
'dists',
self.dist,
component,
'binary-' + arch,
'Packages'
)
self.url, "dists", self.dist, component, "binary-" + arch, "Packages"
)

packages_file = _download_compressed(url)

Expand Down Expand Up @@ -323,6 +315,7 @@ class APTSources:
# Arguments
repositories (list): list of APTRepository objects
"""

def __init__(self, repositories):
self.__repositories = repositories

Expand Down Expand Up @@ -384,4 +377,4 @@ def get_packages_by_name(self, name):
for repo in self.__repositories:
packages.extend(repo.get_packages_by_name(name))

return packages
return packages
3 changes: 1 addition & 2 deletions scripts/build-push-docker.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -e
set -e

QGIS_TYPE=$1
RELEASE_TYPE=$2
Expand Down Expand Up @@ -46,4 +46,3 @@ for TAG in ${TAGS}; do
done

docker buildx build --push --platform linux/amd64,linux/arm64 --build-arg os=${OS} --build-arg release=${OS_RELEASE} --build-arg repo=${QGIS_PPA} ${ALL_TAGS} ${QGIS_TYPE}

45 changes: 23 additions & 22 deletions scripts/get_docker_image_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,37 @@
# This scripts will output the QGIS versions on which LTR and stable rely on
# Formatted as json: {"stable": "3.14.0", "ltr": "3.10.7"}

import requests
import argparse
import json
import re
import argparse

import requests

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-q', '--qgis', help='desktop or server', choices=['desktop', 'server'])
parser.add_argument('-u', '--dist', help='The Ubuntu/Debian distribution')
#parser.add_argument('-d', '--default-dist', help='The default Ubuntu distribution, for which no suffix is in the tag')
parser.add_argument("-q", "--qgis", help="desktop or server", choices=["desktop", "server"])
parser.add_argument("-u", "--dist", help="The Ubuntu/Debian distribution")
# parser.add_argument('-d', '--default-dist', help='The default Ubuntu distribution, for which no suffix is in the tag')
args = parser.parse_args()
distro = args.dist
#default_distro = args.default_dist
# default_distro = args.default_dist

stable = ""
ltr = ""

if args.qgis == 'desktop':
repo_name = 'qgis'
if args.qgis == "desktop":
repo_name = "qgis"
else:
repo_name = 'qgis-server'
repo_name = "qgis-server"

url = f'https://registry.hub.docker.com/v2/repositories/qgis/{repo_name}/tags?page_size=10000'
url = f"https://registry.hub.docker.com/v2/repositories/qgis/{repo_name}/tags?page_size=10000"
r = requests.get(url)
if r.status_code == 404:
# the image does not exist yet
pass
else:
data = r.content.decode('utf-8')
tags = json.loads(data)['results']
data = r.content.decode("utf-8")
tags = json.loads(data)["results"]

stable_sha = None
ltr_sha = None
Expand All @@ -41,24 +42,24 @@
availables_tags = dict()

# get the full version
match = f'^\d\.\d+\.\d+-{distro}$'
match = rf"^\d\.\d+\.\d+-{distro}$"

for tag in tags:
if tag['name'] == f'stable-{distro}':
stable_sha = tag['images'][0]['digest'] # sha
elif tag['name'] == f'ltr-{distro}':
ltr_sha = tag['images'][0]['digest'] # sha
elif re.match(match, tag['name']):
availables_tags[tag['name']] = tag['images'][0]['digest']
if tag["name"] == f"stable-{distro}":
stable_sha = tag["images"][0]["digest"] # sha
elif tag["name"] == f"ltr-{distro}":
ltr_sha = tag["images"][0]["digest"] # sha
elif re.match(match, tag["name"]):
availables_tags[tag["name"]] = tag["images"][0]["digest"]

# determine what is ltr and stable
for tag, sha in availables_tags.items():
if sha == stable_sha:
stable = tag
stable = stable.replace(f'-{distro}', '')
stable = stable.replace(f"-{distro}", "")
elif sha == ltr_sha:
ltr = tag
ltr = ltr.replace(f'-{distro}', '')
ltr = ltr.replace(f"-{distro}", "")

output = {'stable': stable, 'ltr': ltr}
output = {"stable": stable, "ltr": ltr}
print(json.dumps(output))
Loading

0 comments on commit 368f62b

Please sign in to comment.