Use adferrand/snapcraft

This commit is contained in:
Adrien Ferrand 2020-05-26 21:11:59 +02:00
parent af7a7c5c51
commit d5f603c832
5 changed files with 12 additions and 93 deletions

View file

@ -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

View file

@ -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}"

View file

@ -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

View file

@ -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}"