From d5f603c83295ddca143558f65e3665c08c9ae39e Mon Sep 17 00:00:00 2001 From: Adrien Ferrand Date: Tue, 26 May 2020 21:11:59 +0200 Subject: [PATCH] Use adferrand/snapcraft --- snap/local/build_and_install.sh | 15 +++--- snap/local/builder.Dockerfile | 63 ------------------------ snap/local/{common_libs.sh => common.sh} | 0 snap/local/compile_native_wheels.sh | 4 +- snap/local/prepare_builder.sh | 23 --------- 5 files changed, 12 insertions(+), 93 deletions(-) delete mode 100644 snap/local/builder.Dockerfile rename snap/local/{common_libs.sh => common.sh} (100%) delete mode 100755 snap/local/prepare_builder.sh diff --git a/snap/local/build_and_install.sh b/snap/local/build_and_install.sh index 982529214..ebd36c28f 100755 --- a/snap/local/build_and_install.sh +++ b/snap/local/build_and_install.sh @@ -18,11 +18,14 @@ if [[ -z "${SNAP_ARCH}" ]]; then fi DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -CERTBOT_DIR="$(dirname $(dirname "${DIR}"))" +CERTBOT_DIR="$(dirname "$(dirname "${DIR}")")" -source "${DIR}/common_libs.sh" +# shellcheck source=common.sh +source "${DIR}/common.sh" -"${DIR}/prepare_builder.sh" "${SNAP_ARCH}" +docker run --rm --privileged multiarch/qemu-user-static:register --reset +QEMU_ARCH=$(GetQemuArch "${SNAP_ARCH}") +DOCKER_ARCH=$(GetDockerArch "${SNAP_ARCH}") docker run --net=host -d --rm -v "${DIR}/packages:/data/packages" --name pypiserver pypiserver/pypiserver tools/strip_hashes.py letsencrypt-auto-source/pieces/dependency-requirements.txt > snap-constraints.txt @@ -39,9 +42,9 @@ docker run \ -v "${CERTBOT_DIR}:${CERTBOT_DIR}" \ -w "${CERTBOT_DIR}" \ -e "PIP_EXTRA_INDEX_URL=http://localhost:8080/simple" \ - "builder:${SNAP_ARCH}" \ + "adferrand/snapcraft:${DOCKER_ARCH}-beta" \ snapcraft -if [[ "$(arch)" == "$(GetQemuArch "${SNAP_ARCH}")" ]]; then - sudo snap install --dangerous --classic *.snap +if [[ "$(arch)" == "${QEMU_ARCH}" ]]; then + sudo snap install --dangerous --classic "*.snap" fi diff --git a/snap/local/builder.Dockerfile b/snap/local/builder.Dockerfile deleted file mode 100644 index 715a40064..000000000 --- a/snap/local/builder.Dockerfile +++ /dev/null @@ -1,63 +0,0 @@ -ARG TARGET_ARCH -FROM ${TARGET_ARCH}/ubuntu:bionic as builder - -ARG QEMU_ARCH -COPY qemu-${QEMU_ARCH}-static /usr/bin/ - -# Grab dependencies -RUN apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ca-certificates curl jq squashfs-tools \ - && rm -rf /var/lib/apt/lists/* - -ARG SNAP_ARCH - -# Grab the core snap from the stable channel and unpack it in the proper place -RUN curl -L $(curl -H 'X-Ubuntu-Series: 16' -H "X-Ubuntu-Architecture: $SNAP_ARCH" 'https://api.snapcraft.io/api/v1/snaps/details/core' | jq '.download_url' -r) --output core.snap \ - && mkdir -p /snap/core \ - && unsquashfs -d /snap/core/current core.snap - -# Grab the core18 snap from the stable channel and unpack it in the proper place -RUN curl -L $(curl -H 'X-Ubuntu-Series: 16' -H "X-Ubuntu-Architecture: $SNAP_ARCH" 'https://api.snapcraft.io/api/v1/snaps/details/core18' | jq '.download_url' -r) --output core18.snap \ - && mkdir -p /snap/core18 \ - && unsquashfs -d /snap/core18/current core18.snap - -# Grab the snapcraft snap from the stable candidate and unpack it in the proper place -# TODO: move back to stable channel once snapcraft 3.10 has been pushed to it. -RUN curl -L $(curl -H 'X-Ubuntu-Series: 16' -H "X-Ubuntu-Architecture: $SNAP_ARCH" 'https://api.snapcraft.io/api/v1/snaps/details/snapcraft?channel=candidate' | jq '.download_url' -r) --output snapcraft.snap \ - && mkdir -p /snap/snapcraft \ - && unsquashfs -d /snap/snapcraft/current snapcraft.snap - -# Create a snapcraft runner (TODO: move version detection to the core of snapcraft) -RUN mkdir -p /snap/bin \ - && echo "#!/bin/sh" > /snap/bin/snapcraft \ - && snap_version="$(awk '/^version:/{print $2}' /snap/snapcraft/current/meta/snap.yaml)" && echo "export SNAP_VERSION=\"$snap_version\"" >> /snap/bin/snapcraft \ - && echo 'exec "$SNAP/usr/bin/python3" "$SNAP/bin/snapcraft" "$@"' >> /snap/bin/snapcraft \ - && chmod +x /snap/bin/snapcraft - -# Multi-stage build, only need the snaps from the builder. Copy them one at a time so they can be cached. -FROM ${TARGET_ARCH}/ubuntu:bionic - -ARG QEMU_ARCH -COPY qemu-${QEMU_ARCH}-static /usr/bin/ - -COPY --from=builder /snap/core /snap/core -COPY --from=builder /snap/core18 /snap/core18 -COPY --from=builder /snap/snapcraft /snap/snapcraft -COPY --from=builder /snap/bin/snapcraft /snap/bin/snapcraft - -# Generate locale and add runtime dependencies -RUN apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends sudo locales git \ - && locale-gen en_US.UTF-8 \ - && rm -rf /var/lib/apt/lists/* - -# Set the proper environment -ENV LANG="en_US.UTF-8" -ENV LANGUAGE="en_US:en" -ENV LC_ALL="en_US.UTF-8" -ENV PATH="/snap/bin:$PATH" -ENV SNAP="/snap/snapcraft/current" -ENV SNAP_NAME="snapcraft" - -ARG SNAP_ARCH -ENV SNAP_ARCH="${SNAP_ARCH}" diff --git a/snap/local/common_libs.sh b/snap/local/common.sh similarity index 100% rename from snap/local/common_libs.sh rename to snap/local/common.sh diff --git a/snap/local/compile_native_wheels.sh b/snap/local/compile_native_wheels.sh index 08db0d0f5..047877fe1 100755 --- a/snap/local/compile_native_wheels.sh +++ b/snap/local/compile_native_wheels.sh @@ -8,7 +8,9 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" TARGET_ARCHS="arm64 armhf" rm -f "${DIR}/packages/*" -source "${DIR}/builder/common_libs.sh" + +# shellcheck source=common.sh +source "${DIR}/builder/common.sh" RegisterQemuHandlers diff --git a/snap/local/prepare_builder.sh b/snap/local/prepare_builder.sh deleted file mode 100755 index 02b852d15..000000000 --- a/snap/local/prepare_builder.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -# Build a snapcraft docker suitable for cross-compilation of snaps on foreign architectures. -set -ex - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" - -source "${DIR}/common_libs.sh" - -SNAP_ARCH=$1 -TARGET_ARCH=$(GetDockerArch "${SNAP_ARCH}") -QEMU_ARCH=$(GetQemuArch "${SNAP_ARCH}") - -RegisterQemuHandlers -echo "QEMU_ARCH is ${QEMU_ARCH}" -DownloadQemuStatic "${QEMU_ARCH}" "${DIR}" - -docker build \ - --build-arg "SNAP_ARCH=${SNAP_ARCH}" \ - --build-arg "TARGET_ARCH=${TARGET_ARCH}" \ - --build-arg "QEMU_ARCH=${QEMU_ARCH}" \ - -f "${DIR}/builder.Dockerfile" \ - -t "builder:${SNAP_ARCH}" \ - "${DIR}"