diff --git a/.gitignore b/.gitignore index 77b73d9e3..34987d319 100644 --- a/.gitignore +++ b/.gitignore @@ -59,4 +59,4 @@ prime stage *.snap snap-constraints.txt -qemu-* \ No newline at end of file +qemu-* diff --git a/snap/local/build_and_install.sh b/snap/local/build_and_install.sh index a1197c461..3a689bb98 100755 --- a/snap/local/build_and_install.sh +++ b/snap/local/build_and_install.sh @@ -13,11 +13,13 @@ if [[ -z "${SNAP_ARCH}" ]]; then exit 1 fi -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -"${SCRIPT_DIR}/builder/prepare.sh" "${SNAP_ARCH}" +source "${DIR}/builder/common.sh" -docker run --net=host -d --rm -v "${SCRIPT_DIR}/packages:/data/packages" --name pypiserver pypiserver/pypiserver +"${DIR}/builder/prepare.sh" "${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 function cleanup() { @@ -34,3 +36,7 @@ docker run \ -e "PIP_EXTRA_INDEX_URL=http://localhost:8080/simple" \ -t "builder:${SNAP_ARCH}" \ snapcraft + +if [[ "$(arch)" == "$(GetQemuArch "${SNAP_ARCH}")" ]]; then + sudo snap install --dangerous --classic *.snap +fi diff --git a/snap/local/builder/Dockerfile b/snap/local/builder/Dockerfile index d39ab20f2..715a40064 100644 --- a/snap/local/builder/Dockerfile +++ b/snap/local/builder/Dockerfile @@ -6,7 +6,7 @@ COPY qemu-${QEMU_ARCH}-static /usr/bin/ # Grab dependencies RUN apt-get update \ - && apt-get install -y --no-install-recommends ca-certificates curl jq squashfs-tools \ + && 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 @@ -47,7 +47,7 @@ COPY --from=builder /snap/bin/snapcraft /snap/bin/snapcraft # Generate locale and add runtime dependencies RUN apt-get update \ - && apt-get install -y --no-install-recommends sudo locales git \ + && 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/* diff --git a/snap/local/builder/common.sh b/snap/local/builder/common.sh new file mode 100644 index 000000000..3416c5a5a --- /dev/null +++ b/snap/local/builder/common.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +# Returns the translation from Snap architecture to Docker architecture +# Usage: GetQemuArch [amd64|arm64|armhf] +GetDockerArch() { + SNAP_ARCH=$1 + + case "${SNAP_ARCH}" in + "amd64") + echo "amd64" + ;; + "arm64") + echo "arm64v8" + ;; + "armhf") + echo "arm32v7" + ;; + "*") + echo "Not supported build architecture '$1'." >&2 + exit 1 + esac +} + +# Returns the translation from Snap architecture to QEMU architecture +# Usage: GetQemuArch [amd64|arm64|armhf] +GetQemuArch() { + SNAP_ARCH=$1 + + case "${SNAP_ARCH}" in + "amd64") + echo "x86_64" + ;; + "arm64") + echo "aarch64" + ;; + "armhf") + echo "arm" + ;; + "*") + echo "Not supported build architecture '$1'." >&2 + exit 1 + esac +} + +# Downloads QEMU static binary file for architecture +# Usage: DownloadQemuStatic [x86_64|aarch64|arm] +DownloadQemuStatic() { + QEMU_ARCH=$1 + + if [ ! -f "${DIR}/qemu-${QEMU_ARCH}-static" ]; then + QEMU_DOWNLOAD_URL="https://github.com/multiarch/qemu-user-static/releases/download" + QEMU_LATEST_TAG=$(curl -s https://api.github.com/repos/multiarch/qemu-user-static/tags \ + | grep 'name.*v[0-9]' \ + | head -n 1 \ + | cut -d '"' -f 4) + echo "${QEMU_DOWNLOAD_URL}/${QEMU_LATEST_TAG}/x86_64_qemu-${QEMU_ARCH}-static.tar.gz" + curl -SL "${QEMU_DOWNLOAD_URL}/${QEMU_LATEST_TAG}/x86_64_qemu-${QEMU_ARCH}-static.tar.gz" \ + | tar xzv -C "${DIR}" + fi +} + +# Executes the QEMU register script +# Usage: RegisterQemuHandlers +RegisterQemuHandlers() { + docker run --rm --privileged multiarch/qemu-user-static:register --reset +} diff --git a/snap/local/builder/prepare.sh b/snap/local/builder/prepare.sh index 4356566a6..6732de804 100755 --- a/snap/local/builder/prepare.sh +++ b/snap/local/builder/prepare.sh @@ -3,70 +3,7 @@ set -e DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -# Returns the translation from Snap architecture to Docker architecture -# Usage: GetQemuArch [amd64|arm64|armhf] -GetDockerArch() { - SNAP_ARCH=$1 - - case "${SNAP_ARCH}" in - "amd64") - echo "amd64" - ;; - "arm64") - echo "arm64v8" - ;; - "armhf") - echo "arm32v7" - ;; - "*") - echo "Not supported build architecture '$1'." >&2 - exit 1 - esac -} - -# Returns the translation from Snap architecture to QEMU architecture -# Usage: GetQemuArch [amd64|arm64|armhf] -GetQemuArch() { - SNAP_ARCH=$1 - - case "${SNAP_ARCH}" in - "amd64") - echo "x86_64" - ;; - "arm64") - echo "aarch64" - ;; - "armhf") - echo "arm" - ;; - "*") - echo "Not supported build architecture '$1'." >&2 - exit 1 - esac -} - -# Downloads QEMU static binary file for architecture -# Usage: DownloadQemuStatic [x86_64|aarch64|arm] -DownloadQemuStatic() { - QEMU_ARCH=$1 - - if [ ! -f "${DIR}/qemu-${QEMU_ARCH}-static" ]; then - QEMU_DOWNLOAD_URL="https://github.com/multiarch/qemu-user-static/releases/download" - QEMU_LATEST_TAG=$(curl -s https://api.github.com/repos/multiarch/qemu-user-static/tags \ - | grep 'name.*v[0-9]' \ - | head -n 1 \ - | cut -d '"' -f 4) - echo "${QEMU_DOWNLOAD_URL}/${QEMU_LATEST_TAG}/x86_64_qemu-${QEMU_ARCH}-static.tar.gz" - curl -SL "${QEMU_DOWNLOAD_URL}/${QEMU_LATEST_TAG}/x86_64_qemu-${QEMU_ARCH}-static.tar.gz" \ - | tar xzv -C "${DIR}" - fi -} - -# Executes the QEMU register script -# Usage: RegisterQemuHandlers -RegisterQemuHandlers() { - docker run --rm --privileged multiarch/qemu-user-static:register --reset -} +source "${DIR}/common.sh" SNAP_ARCH=$1 TARGET_ARCH=$(GetDockerArch "${SNAP_ARCH}")