docker-ubuntu-pyside-xvfb/build.sh

151 lines
4.4 KiB
Bash
Raw Normal View History

2024-09-19 21:28:21 +00:00
#!/bin/bash
#
# Copyright (c) 2021-2024 Ad5001
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# shellcheck disable=SC2046
# Resets all ansi codes.
RESET="\e[0m"
# Sets the forground color to light green.
L_GREEN_FG="\e[32m"
# Sets the forground color to red.
RED_FG="\e[38;5;204m"
# Display text in a box
# Signature: (<string message>) -> string
box() {
len=${#1}
echo "┌─$(yes ─ | head -$len | tr -d "\n")─┐"
echo "$1"
echo "└─$(yes ─ | head -$len | tr -d "\n")─┘"
}
box_red() {
echo -n "$RED_FG"
box "$@"
echo -n "$RESET"
}
box_green() {
echo -n "$L_GREEN_FG"
box "$@"
echo -n "$RESET"
}
# 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 " "
}
# 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
}
pyside6=false
pyside2=false
latest=false
push=true
repo="ad5001/ubuntu-pyside-xvfb"
# Query arguments
while [ $# -gt 0 ]; do
case "$1" in
--pyside6)
pyside6=true
;;
--pyside2)
pyside2=true
;;
--latest)
latest=true
;;
--no-push)
push=false
;;
--repo=*)
repo="${1#*=}"
;;
*)
box "Error: Invalid argument."
exit 1
esac
shift
done
if [ "$pyside6" = "false" ] && [ "$pyside2" = "false" ]; then
box "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
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
fi