Skip to content

Commit

Permalink
Modernize and fix build system
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAssassin committed Nov 24, 2024
1 parent 4acb54c commit 4b56dc1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 80 deletions.
9 changes: 4 additions & 5 deletions ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
26 changes: 8 additions & 18 deletions ci/build-docker-image.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,30 +14,21 @@ 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")
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"
Expand All @@ -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
46 changes: 33 additions & 13 deletions ci/build-in-docker.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
47 changes: 3 additions & 44 deletions ci/install-deps.sh
Original file line number Diff line number Diff line change
@@ -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=(
Expand All @@ -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

0 comments on commit 4b56dc1

Please sign in to comment.