From 4b56dc19df4143cd8e2874a9f0c1a0551c64c701 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Mon, 25 Nov 2024 00:26:47 +0100 Subject: [PATCH] Modernize and fix build system --- ci/Dockerfile | 9 ++++---- ci/build-docker-image.sh | 26 +++++++--------------- ci/build-in-docker.sh | 46 ++++++++++++++++++++++++++++----------- ci/install-deps.sh | 47 +++------------------------------------- 4 files changed, 48 insertions(+), 80 deletions(-) diff --git a/ci/Dockerfile b/ci/Dockerfile index 790372d4..535a3fe6 100644 --- a/ci/Dockerfile +++ b/ci/Dockerfile @@ -1,8 +1,7 @@ # these args are available *only* for the FROM call -ARG DOCKER_ARCH -ARG DIST +ARG RELEASE -FROM $DOCKER_ARCH/ubuntu:$DIST +FROM ubuntu:$RELEASE # we need to repeat all args from above which we need during build and runtime to make them available ARG ARCH @@ -12,9 +11,9 @@ ENV CI=1 COPY ./install-deps.sh / # see above, for build time we need to pass the args manually (using ENV does not work) -RUN bash -xe install-deps.sh +RUN bash -xe /install-deps.sh # create unprivileged user for non-build-script use of this image # build-in-docker.sh will likely not use this one, as it enforces the caller's uid inside the container -RUN adduser --system --group build +RUN useradd build USER build diff --git a/ci/build-docker-image.sh b/ci/build-docker-image.sh index ab37c85d..1bd7426b 100755 --- a/ci/build-docker-image.sh +++ b/ci/build-docker-image.sh @@ -1,12 +1,11 @@ #! /bin/bash -if [[ "$DIST" == "" ]] || [[ "$ARCH" == "" ]]; then - echo "Usage: env ARCH=... DIST=... bash $0" +if [[ "${ARCH:-}" == "" ]] || [[ "${RELEASE:-}" == "" ]]; then + echo "Usage: env ARCH=... RELEASE=... bash $0" exit 1 fi -set -x -set -e +set -euo pipefail # the other script sources this script, therefore we have to support that use case if [[ "${BASH_SOURCE[*]}" != "" ]]; then @@ -15,19 +14,10 @@ else this_dir="$(readlink -f "$(dirname "$0")")" fi -case "$ARCH" in - x86_64) - export DOCKER_ARCH=amd64 - ;; - *) - export DOCKER_ARCH="$ARCH" - ;; -esac - -image=quay.io/appimage/libappimage-build:"$DIST"-"$ARCH" +image=quay.io/appimage/libappimage-build:"$RELEASE" extra_build_args=() -if [[ "$NO_PULL" == "" ]]; then +if [[ "${NO_PULL:-}" == "" ]]; then # speed up build by pulling last built image from quay.io and building the docker file using the old image as a base docker pull "$image" || true extra_build_args=(--cache-from "$image") @@ -35,10 +25,10 @@ fi # if the image hasn't changed, this should be a no-op docker build \ + --platform "$platform" \ --pull \ - --build-arg DOCKER_ARCH \ --build-arg ARCH \ - --build-arg DIST \ + --build-arg RELEASE \ -t "$image" \ "${extra_build_args[@]}" \ "$this_dir" @@ -48,7 +38,7 @@ docker build \ # rebuilt anyway # credentials shall only be available on (protected) master branch set +x -if [[ "$DOCKER_USERNAME" != "" ]]; then +if [[ "${DOCKER_USERNAME:-}" != "" ]]; then echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin quay.io docker push "$image" fi diff --git a/ci/build-in-docker.sh b/ci/build-in-docker.sh index d05cb92a..be5eb895 100755 --- a/ci/build-in-docker.sh +++ b/ci/build-in-docker.sh @@ -1,31 +1,51 @@ #! /bin/bash -if [[ "$DIST" == "" ]] || [[ "$ARCH" == "" ]]; then - echo "Usage: env ARCH=... DIST=... bash $0" +if [[ "${ARCH:-}" == "" ]] || [[ "${RELEASE:-}" == "" ]]; then + echo "Usage: env ARCH=... RELEASE=... bash $0" exit 1 fi -set -x -set -e +set -euo pipefail -cd "$(readlink -f "$(dirname "$0")")" - -if [[ "$DIST" != appimagebuild* ]]; then - # sets variables $image - source build-docker-image.sh +# the other script sources this script, therefore we have to support that use case +if [[ "${BASH_SOURCE[*]}" != "" ]]; then + this_dir="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")" else - image=quay.io/appimage/appimagebuild:centos7-"$ARCH" - docker pull "$image" + this_dir="$(readlink -f "$(dirname "$0")")" fi +case "$ARCH" in + x86_64) + platform=linux/amd64 + ;; + i686) + platform=linux/i386 + ;; + armhf) + platform=linux/arm/v7 + ;; + aarch64) + platform=linux/arm64/v8 + ;; + *) + echo "unknown architecture: $ARCH" + exit 2 + ;; +esac + +cd "$(readlink -f "$(dirname "$0")")" + +# sets variables $image +source build-docker-image.sh + DOCKER_OPTS=() # fix for https://stackoverflow.com/questions/51195528/rcc-error-in-resource-qrc-cannot-find-file-png -if [ "$CI" != "" ]; then +if [ "${CI:-}" != "" ]; then DOCKER_OPTS+=("--security-opt" "seccomp:unconfined") fi # only if there's more than 3G of free space in RAM, we can build in a RAM disk -if [[ "$GITHUB_ACTIONS" != "" ]]; then +if [[ "${GITHUB_ACTIONS:-}" != "" ]]; then echo "Building on GitHub actions, which does not support --tmpfs flag -> building on regular disk" elif [[ "$(free -m | grep "Mem:" | awk '{print $4}')" -gt 3072 ]]; then echo "Host system has enough free memory -> building in RAM disk" diff --git a/ci/install-deps.sh b/ci/install-deps.sh index b02aab99..291e5163 100755 --- a/ci/install-deps.sh +++ b/ci/install-deps.sh @@ -1,37 +1,14 @@ #! /bin/bash -set -e +set -euo pipefail -if [[ "$ARCH" == "" ]]; then - echo "Usage: env ARCH=... bash $0" - exit 2 -fi - -if [[ "$CI" == "" ]]; then +if [[ "${CI:-}" == "" ]]; then echo "Caution: this script is supposed to run inside a (disposable) CI environment" echo "It will alter a system, and should not be run on workstations or alike" echo "You can export CI=1 to prevent this error from being shown again" exit 3 fi -case "$ARCH" in - x86_64|i386|armhf|arm64) - ;; - *) - echo "Error: unsupported architecture: $ARCH" - exit 4 - ;; -esac - -case "$DIST" in - bionic|focal) - ;; - *) - echo "Error: unsupported distribution: $DIST" - exit 5 - ;; -esac - set -x packages=( @@ -58,29 +35,11 @@ packages=( lcov gcovr libboost-dev + g++-multilib ) -# install gcc-10 (supports C++17 with std::filesystem properly) -if [[ "$DIST" == "bionic" ]]; then - apt-get update - apt-get install --no-install-recommends -y software-properties-common - add-apt-repository -y ppa:ubuntu-toolchain-r/test - packages+=(g++-10-multilib) -else - packages+=(g++-multilib) -fi - # make sure installation won't hang on GitHub actions export DEBIAN_FRONTEND=noninteractive apt-get update apt-get -y --no-install-recommends install "${packages[@]}" - -# install more recent CMake version -wget https://artifacts.assassinate-you.net/prebuilt-cmake/continuous/cmake-v3.24.1-ubuntu_"$DIST"-"$ARCH".tar.gz -qO- | \ - tar xz -C/usr/local --strip-components=1 - -# g++-10 should be used by default -if [[ "$DIST" == "bionic" ]]; then - update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-10 9999 -fi