From a77c1fd423775eda7089385a0ac0f020b9a36a77 Mon Sep 17 00:00:00 2001 From: Thomas Orozco Date: Sat, 19 Aug 2017 13:31:47 +0200 Subject: [PATCH] Clean up multi-arch builds a bit - `ARCH_SUFFIX` should not be passed at runtime: it's already passed as a build argument, and it's consumed during the build (so it's too late to change it at runtime). - For consistency, pass `ARCH_NATIVE` and `CC` similarly at build time as well: passing `CC` and `ARCH_SUFFIX` at different times is particularly error-prone. - Accept all parameters to `ddist.sh` via environment variables. It doesn't make sense to accept exclusively `ARCH_SUFFIX` as a positional argument when `ARCH_SUFFIX` alone doesn't accomplish anything (i.e. you also need `CC`). TODO: `CC` should be derived from `ARCH_SUFFIX` in the first place. --- Dockerfile | 9 +++++++++ ddist.sh | 41 ++++++++++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4ee1a8b..8d77935 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,3 +7,12 @@ RUN /install_deps.sh # Pre-install those here for faster local builds. RUN CFLAGS="-DPR_SET_CHILD_SUBREAPER=36 -DPR_GET_CHILD_SUBREAPER=37" pip install psutil python-prctl bitmap + +ARG ARCH_NATIVE +ARG CC + +# Persist ARGs into the image + +ENV ARCH_SUFFIX="$ARCH_SUFFIX" \ + ARCH_NATIVE="$ARCH_NATIVE" \ + CC="$CC" diff --git a/ddist.sh b/ddist.sh index 0625399..eed7d46 100755 --- a/ddist.sh +++ b/ddist.sh @@ -2,35 +2,46 @@ set -o errexit set -o nounset -if [[ "$#" != 1 ]]; then - echo "Usage: $0 ARCH_SUFFIX" - exit 1 -fi -suffix="$1" - REL_HERE=$(dirname "${BASH_SOURCE}") HERE=$(cd "${REL_HERE}"; pwd) -IMG="tini-build-${suffix}" -SRC="/tini" +IMG="tini-build" + +if [[ -n "${ARCH_SUFFIX-}" ]]; then + IMG="${IMG}_${ARCH_SUFFIX}" +fi + +if [[ -n "${ARCH_NATIVE-}" ]]; then + IMG="${IMG}_native" +fi + +if [[ -n "${CC-}" ]]; then + IMG="${IMG}_${CC}" +fi # Cleanup the build dir rm -f "${HERE}/dist"/* # Create the build image -docker build --build-arg "ARCH_SUFFIX=${suffix}" -t "${IMG}" . +echo "build: ${IMG}" + +docker build \ + --build-arg "ARCH_SUFFIX=${ARCH_SUFFIX-}" \ + --build-arg "ARCH_NATIVE=${ARCH_NATIVE-}" \ + --build-arg "CC=${CC-gcc}" \ + -t "${IMG}" \ + . + +# Build new Tini +SRC="/tini" -# Run test without subreaper support, don't copy build files here docker run -it --rm \ --volume="${HERE}:${SRC}" \ -e BUILD_DIR=/tmp/tini-build \ -e SOURCE_DIR="${SRC}" \ - -e FORCE_SUBREAPER="${FORCE_SUBREAPER:="1"}" \ - -e GPG_PASSPHRASE="${GPG_PASSPHRASE:=}" \ - -e CC="${CC:=gcc}" \ + -e FORCE_SUBREAPER="${FORCE_SUBREAPER-1}" \ + -e GPG_PASSPHRASE="${GPG_PASSPHRASE-}" \ -e CFLAGS="${CFLAGS-}" \ - -e ARCH_NATIVE="${ARCH_NATIVE-}" \ - -e ARCH_SUFFIX="${suffix}" \ -e MINIMAL="${MINIMAL-}" \ -u "$(id -u):$(id -g)" \ "${IMG}" "${SRC}/ci/run_build.sh"