Build system working with custom config files so I don't have to customize the script every time!

This commit is contained in:
Ad5001 2024-09-20 01:05:08 +02:00
parent dd21b21829
commit 236a9c4bc5
Signed by: Ad5001
GPG key ID: EF45F9C6AFE20160
7 changed files with 118 additions and 83 deletions

157
build.sh
View file

@ -20,6 +20,12 @@ L_GREEN_FG="\e[32m"
# Sets the forground color to red.
RED_FG="\e[38;5;204m"
pyside6=false
pyside2=false
latest=false
push=true
repo="ad5001/ubuntu-pyside-xvfb"
# Display text in a box
# Signature: (<string message>) -> string
box() {
@ -29,36 +35,93 @@ box() {
echo "└─$(yes ─ | head -$len | tr -d "\n")─┘"
}
box_red() {
echo -n "$RED_FG"
box-red() {
echo -n -e "$RED_FG"
box "$@"
echo -n "$RESET"
echo -n -e "$RESET"
}
box_green() {
echo -n "$L_GREEN_FG"
box-green() {
echo -n -e "$L_GREEN_FG"
box "$@"
echo -n "$RESET"
echo -n -e "$RESET"
}
# Returns a string of KEY="VALUES" separated by newlines for the corresponding category.
# Signature: (<string source_file>, <string dict_name>) -> string
from-toml-dict() {
if [ -z "$2" ]; then
sed -n -e '1,/\[/ p' "$1" | grep '="'
else
sed -n -e '/\['"$2"']/,/\[/ p' "$1" | grep '="'
fi
}
# Replaces {KEY} by value in given context.
# Signature: stdin+(<string key>, <string value>) -> string
pass-argument() {
while read -r line; do
echo "${line//\{$1\}/$2}"
done
}
# Queries a value from an INI/singular dict TOML into for a given key
# Signature: stdin+(<string key>) -> string
get-value-of() {
while read -r line; do
if [ "${line%=*}" = "$1" ]; then
echo "$line" | cut -d'"' -f 2
return 0
fi
done
}
# Converts arguments from an INI/singular dict TOML file into a list of build args for docker.
# Signature: (<string source_file>) -> string
config_to_docker_args() {
grep '="' "$1" | sed 's@^@--build-arg @g' | paste -s -d " "
# Signature: stdin+(<string repo>, <string pyside_version>) -> string
to-docker-args() {
# Read stdin
out=""
while read -r line; do
key="${line%=*}"
value="$(echo "${line#=*}" | pass-argument REPO "$1" | pass-argument VERSION "$2")"
out="$out--build-arg $key=$value";
done
echo "$out"
}
# Queries a value from an INI/singular dict TOML file into for a given key
# Signature: (<string source_file>, <string key>) -> string
query_from_config() {
grep "$2=" "$1" | cut -d'"' -f 2
# Builds a pyside directory (with a config.toml for additional parameters.
# Signature (<string directory>) -> void
build_pyside() {
directory=$1
cfg="$directory/config.toml"
# Query information from config
major=$(from-toml-dict "$cfg" | get-value-of MAJOR_VERSION)
version=$(from-toml-dict "$cfg" | get-value-of PYSIDE_VERSION)
for build in $(from-toml-dict "$cfg" | get-value-of BUILDS); do
# Build each build individidually
tag="$(from-toml-dict "$cfg" "$build.settings" | get-value-of TAG | pass-argument VERSION "$version")"
latest_tag="$(from-toml-dict "$cfg" "$build.settings" | get-value-of TAG | pass-argument VERSION "${major}-latest")"
build_args="$(from-toml-dict "$cfg" "$build.docker-args" | to-docker-args "$repo" "$version")"
box-green "Building image $tag..."
docker build -t "$tag" $build_args "$directory/${build}"
# Tag as latest
if [ "$latest" != "false" ]; then
docker tag "$tag" "$latest_tag"
fi
# Push builds
if [ "$push" != "false" ]; then
if [ "$latest" != "false" ]; then
box-green "Pushing image $repo/$tag and $repo/$latest_tag..."
docker push "$latest_tag"
docker push "$tag"
else
box-green "Pushing image $repo/$tag..."
docker push "$tag"
fi
fi
done
}
pyside6=false
pyside2=false
latest=false
push=true
repo="ad5001/ubuntu-pyside-xvfb"
# Query arguments
while [ $# -gt 0 ]; do
@ -86,65 +149,15 @@ while [ $# -gt 0 ]; do
done
if [ "$pyside6" = "false" ] && [ "$pyside2" = "false" ]; then
box "Must at least either use --pyside2 or --pyside6"
box-red "Must at least either use --pyside2 or --pyside6"
fi
# Build PySide6
if [ "$pyside6" != "false" ]; then
config="pyside6/config.toml"
version=$(query_from_config "$config" "PYSIDE6_VERSION")
tag_linux="${repo}:linux-${version}"
tag_wine="${repo}:wine-${version}"
tag_linux_latex="${repo}:linux-${version}-latex"
# Building
box "Building PySide6 Linux Image..."
docker build -t "${tag_linux}" $(config_to_docker_args "$config") pyside6/linux
box "Building PySide6 Wine Image..."
docker build -t "${tag_wine}" $(config_to_docker_args "$config") pyside6/wine
box "Building PySide6 Linux-Latex Image..."
docker build -t "${tag_linux_latex}" $(config_to_docker_args "$config") --build-arg BASE_IMAGE="${tag_linux}" pyside6/linux-latex
# Tagging
if [ "$latest" != "false" ]; then
docker tag "${tag_linux}" "${repo}:linux-6-latest"
docker tag "${tag_wine}" "${repo}:wine-6-latest"
docker tag "${tag_linux_latex}" "${repo}:linux-6-latest-latex"
fi
# Pushing
if [ "$push" != "true" ]; then
docker push "${tag_linux}"
docker push "${tag_wine}"
docker push "${tag_linux_latex}"
if [ "$latest" != "false" ]; then
docker push "${repo}:linux-6-latest"
docker push "${repo}:wine-6-latest"
docker push "${repo}:linux-6-latest-latex"
fi
fi
build_pyside "pyside6"
fi
# Build PySide2
if [ "$pyside2" != "false" ]; then
config="pyside2/config.toml"
version=$(query_from_config "$config" "PYSIDE2_VERSION")
tag_linux="${repo}:linux-${version}"
tag_wine="${repo}:wine-${version}"
# Building
box "Building PySide2 Linux Image..."
docker build -t "${tag_linux}" $(config_to_docker_args "$config") pyside2/linux
box "Building PySide2 Wine Image..."
docker build -t "${tag_wine}" $(config_to_docker_args "$config") pyside2/wine
# Tagging
if [ "$latest" != "false" ]; then
docker tag "${tag_linux}" "${repo}:linux-5-latest"
docker tag "${tag_wine}" "${repo}:wine-5-latest"
fi
# Pushing
if [ "$push" != "true" ]; then
docker push "${tag_linux}"
docker push "${tag_wine}"
if [ "$latest" != "false" ]; then
docker push "${repo}:linux-5-latest"
docker push "${repo}:wine-5-latest"
fi
fi
build_pyside "pyside2"
fi

View file

@ -10,9 +10,17 @@
# SOFTWARE.
#
PYSIDE2_VERSION="5.12.2.1"
MAJOR_VERSION="5"
PYSIDE_VERSION="5.12.2.1"
BUILDS="linux wine"
[linux.settings]
TAG="linux-{VERSION}"
[wine.settings]
TAG="wine-{VERSION}"
[wine.docker-args]
# Arguments for wine builds
PYTHON_VERSION="3.10.11"
PYINSTALLER_VERSION="6.10.0"

View file

@ -14,7 +14,7 @@ FROM ubuntu:jammy
# Jammy uses python3.10 and not 3.12, which is not compatible with PySide2.
ARG DEBIAN_FRONTEND=noninteractive
ARG PYSIDE2_VERSION=5.15.2.1
ARG PYSIDE_VERSION=5.15.2.1
ENV TZ=Europe/Paris
RUN apt-get update
@ -24,5 +24,5 @@ RUN apt-get -y install make git rpm dh-python \
python3 python3-pip python3-stdeb python3-requests python3-packaging python3-pip python3-pytest python3-pytest-cov python3-pytestqt \
qml-module-qtquick-controls2 qml-module-qtmultimedia qml-module-qtgraphicaleffects qml-module-qtquick2 qml-module-qtqml-models2 qml-module-qtquick-controls
RUN python3 -m pip install -U pip py certifi setuptools wheel # Upgrading packages that need fixes.
RUN python3 -m pip install PySide2==$PYSIDE2_VERSION
RUN python3 -m pip install PySide2==$PYSIDE_VERSION
RUN apt clean

View file

@ -12,7 +12,7 @@
FROM ubuntu:noble
ARG PYSIDE2_VERSION=5.15.2.1
ARG PYSIDE_VERSION=5.15.2.1
# Adapted from https://github.com/cdrx/docker-pyinstaller/blob/master/Dockerfile-py3-win64
# Upstream hasn't been updated for a while.
@ -90,4 +90,4 @@ RUN set -x \
RUN apt install -y wget curl p7zip-full git unzip nsis xvfb xdotool wmctrl
RUN apt clean
# Installing pyside2 & pyinstaller
RUN pip install wheel PySide2==$PYSIDE2_VERSION pyinstaller==$PYINSTALLER_VERSION requests pytest pytest-cov pytest-qt packaging
RUN pip install wheel PySide2==$PYSIDE_VERSION pyinstaller==$PYINSTALLER_VERSION requests pytest pytest-cov pytest-qt packaging

View file

@ -10,9 +10,23 @@
# SOFTWARE.
#
PYSIDE6_VERSION="6.7.2"
MAJOR_VERSION="6"
PYSIDE_VERSION="6.7.2"
BUILDS="linux wine linux-latex"
[linux.settings]
TAG="linux-{VERSION}"
[wine.settings]
TAG="wine-{VERSION}"
[linux-latex.settings]
TAG="linux-{VERSION}-latex"
[wine.docker-args]
# Arguments for wine builds
PYTHON_VERSION="3.12.6"
PYINSTALLER_VERSION="6.10.0"
[linux-latex.docker-args]
BASE_IMAGE="{REPO}:linux-{VERSION}"

View file

@ -12,7 +12,7 @@
FROM ubuntu:noble
ARG DEBIAN_FRONTEND=noninteractive
ARG PYSIDE2_VERSION=6.7.2
ARG PYSIDE_VERSION=6.7.2
ENV TZ=Europe/Paris
RUN apt-get update
@ -22,5 +22,5 @@ RUN apt-get -y install make git rpm dh-python \
python3 python3-pip python3-stdeb python3-requests python3-packaging python3-pip python3-pytest python3-pytest-cov python3-pytestqt
RUN rm /usr/lib/python3.*/EXTERNALLY-MANAGED # Disable managed environment. We don't care about breaking system packages here.
RUN python3 -m pip install -U setuptools # Upgrading packages that need fixes.
RUN python3 -m pip install PySide6==$PYSIDE2_VERSION
RUN python3 -m pip install PySide6==$PYSIDE_VERSION
RUN apt clean

View file

@ -12,7 +12,7 @@
FROM ubuntu:noble
ARG PYSIDE6_VERSION=6.7.2
ARG PYSIDE_VERSION=6.7.2
# Adapted from https://github.com/cdrx/docker-pyinstaller/blob/master/Dockerfile-py3-win64
# Upstream hasn't been updated for a while.
@ -90,4 +90,4 @@ RUN set -x \
RUN apt install -y wget curl p7zip-full git unzip nsis xvfb xdotool wmctrl
RUN apt clean
# Installing pyside6 & pyinstaller
RUN pip install wheel PySide6==$PYSIDE6_VERSION pyinstaller==$PYINSTALLER_VERSION requests pytest pytest-cov pytest-qt packaging
RUN pip install wheel PySide6==$PYSIDE_VERSION pyinstaller==$PYINSTALLER_VERSION requests pytest pytest-cov pytest-qt packaging