From 25f2d55d7c3ab3ecf72625c3ccaa6cc9041be337 Mon Sep 17 00:00:00 2001 From: Dreista Date: Thu, 12 May 2022 01:10:54 -0400 Subject: [PATCH] Support multiarch through cross-compilation --- Dockerfile | 42 +++++++++++++--- README.md | 34 +++++++++---- azure-pipelines.yaml | 113 ++++++++++++++++++++++++++++--------------- 3 files changed, 133 insertions(+), 56 deletions(-) diff --git a/Dockerfile b/Dockerfile index fe23d0f..5be204e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,48 @@ ## builder -FROM debian:10-slim as builder +FROM --platform=$BUILDPLATFORM debian:stable-slim as builder LABEL image="ripe-atlas-builder" +ARG BUILDPLATFORM +ARG TARGETPLATFORM ARG DEBIAN_FRONTEND=noninteractive ARG GIT_URL=https://github.com/RIPE-NCC/ripe-atlas-software-probe.git -RUN apt-get update -y \ - && apt-get install -y git tar fakeroot libssl-dev libcap2-bin autoconf automake libtool build-essential python - WORKDIR /root +RUN if [ "$BUILDPLATFORM" != "$TARGETPLATFORM" ] ; then \ + case ${TARGETPLATFORM} in \ + "linux/arm64") echo 'export CROSSBUILD_ARCH=arm64 CROSS_COMPILE_TARGET=aarch64-linux-gnu' > env ;; \ + "linux/arm/v6") echo 'export CROSSBUILD_ARCH=armel CROSS_COMPILE_TARGET=arm-linux-gnueabi' > env ;; \ + "linux/arm/v7") echo 'export CROSSBUILD_ARCH=armhf CROSS_COMPILE_TARGET=arm-linux-gnueabihf' > env ;; \ + "linux/386") echo 'export CROSSBUILD_ARCH=i386 CROSS_COMPILE_TARGET=i686-linux-gnu' > env ;; \ + "linux/amd64") echo 'export CROSSBUILD_ARCH=amd64 CROSS_COMPILE_TARGET=x86_64-linux-gnu' > env ;; \ + *) echo "Unsupported platform"; exit 1 ;; \ + esac \ + && . ./env \ + && dpkg --add-architecture $CROSSBUILD_ARCH \ + && apt-get update -y \ + && apt-get install -y libssl-dev:$CROSSBUILD_ARCH crossbuild-essential-$CROSSBUILD_ARCH; \ + fi \ + && apt-get update -y \ + && apt-get install -y git tar fakeroot libssl-dev libcap2-bin autoconf automake libtool build-essential + RUN git clone --recursive "$GIT_URL" -RUN ./ripe-atlas-software-probe/build-config/debian/bin/make-deb + +RUN if [ "$BUILDPLATFORM" != "$TARGETPLATFORM" ] ; then \ + . ./env \ + && export CROSS_COMPILE="$CROSS_COMPILE_TARGET-" \ + && sed -i 's/.\/configure/.\/configure --host='$CROSS_COMPILE_TARGET'/g' ./ripe-atlas-software-probe/build-config/debian/bin/make-deb \ + && sed -i 's/ARCH=$(get_arch)/ARCH='$CROSSBUILD_ARCH'/g' ./ripe-atlas-software-probe/build-config/debian/bin/make-deb; \ + fi \ + && ./ripe-atlas-software-probe/build-config/debian/bin/make-deb + +## artifacts +FROM scratch AS artifacts +LABEL image="ripe-atlas-artifacts" + +COPY --from=builder /root/atlasswprobe-*.deb / ## the actual image -FROM debian:10-slim +FROM debian:stable-slim LABEL maintainer="dockerhub@public.swineson.me" LABEL image="ripe-atlas" ARG DEBIAN_FRONTEND=noninteractive @@ -46,4 +75,3 @@ VOLUME [ "/var/atlas-probe/etc", "/var/atlas-probe/status" ] ENTRYPOINT [ "entrypoint.sh" ] CMD [ "atlas" ] - diff --git a/README.md b/README.md index b01cb95..6d8aa6e 100644 --- a/README.md +++ b/README.md @@ -12,13 +12,6 @@ This is the [RIPE Atlas software probe](https://atlas.ripe.net/docs/software-pro * A Linux installation with Docker installed * Internet access -## Tags - -The following prebuilt tags are available at [Docker Hub](https://hub.docker.com/r/jamesits/ripe-atlas): - -* `latest`: For arm64 (x86\_64) devices -* `latest-armv7l`: For armv7l (armhf) devices, e.g. Raspberry Pi (CI donated by [@OtakuNekoP](https://github.com/OtakuNekoP)) - ## Running First we start the container: @@ -47,7 +40,9 @@ cat /var/atlas-probe/etc/probe_key.pub ### IPv6 -Docker's IPv6 support is still [like shit](https://github.com/moby/moby/issues/25407). As a workaround, you can use IPv6 NAT like this: +Docker's IPv6 support is still [like shit](https://github.com/moby/moby/issues/25407). As a workaround, you can use IPv6 NAT using either `docker-ipv6nat` or native method (experimental). + +First, edit kernel parameters. ```shell cat > /etc/sysctl.d/50-docker-ipv6.conf <