diff --git a/Dockerfile b/Dockerfile index c734d16ec..43e05864a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -44,11 +44,18 @@ ENV CGO_ENABLED=1 GOOS=linux ENV GOARCH=arm64 CGO_CFLAGS="-I/work/libpcap" +### Builder image for AArch64 to x86-64 cross-compilation +FROM up9inc/linux-x86_64-musl-go-libpcap AS builder-from-arm64v8-to-amd64 +ENV CGO_ENABLED=1 GOOS=linux +ENV GOARCH=amd64 CGO_CFLAGS="-I/libpcap" + + ### Final builder image where the build happens # Possible build strategies: # BUILDARCH=amd64 TARGETARCH=amd64 # BUILDARCH=arm64v8 TARGETARCH=arm64v8 # BUILDARCH=amd64 TARGETARCH=arm64v8 +# BUILDARCH=arm64v8 TARGETARCH=amd64 ARG BUILDARCH=amd64 ARG TARGETARCH=amd64 FROM builder-from-${BUILDARCH}-to-${TARGETARCH} AS builder diff --git a/devops/linux-x86_64-musl-go-libpcap/Dockerfile b/devops/linux-x86_64-musl-go-libpcap/Dockerfile new file mode 100644 index 000000000..b82454453 --- /dev/null +++ b/devops/linux-x86_64-musl-go-libpcap/Dockerfile @@ -0,0 +1,31 @@ +FROM messense/rust-musl-cross:x86_64-musl AS builder-from-arm64v8-to-amd64 + +ENV CROSS_TRIPLE x86_64-unknown-linux-musl +ENV CROSS_ROOT /usr/local/musl + +ENV AS=${CROSS_ROOT}/bin/${CROSS_TRIPLE}-as \ + AR=${CROSS_ROOT}/bin/${CROSS_TRIPLE}-ar \ + CC=${CROSS_ROOT}/bin/${CROSS_TRIPLE}-gcc \ + CPP=${CROSS_ROOT}/bin/${CROSS_TRIPLE}-cpp \ + CXX=${CROSS_ROOT}/bin/${CROSS_TRIPLE}-g++ \ + LD=${CROSS_ROOT}/bin/${CROSS_TRIPLE}-ld \ + FC=${CROSS_ROOT}/bin/${CROSS_TRIPLE}-gfortran + +# Install Go +WORKDIR / +RUN curl https://go.dev/dl/go1.17.6.linux-arm64.tar.gz -Lo ./go.linux-arm64.tar.gz \ + && curl https://go.dev/dl/go1.17.6.linux-arm64.tar.gz.asc -Lo ./go.linux-arm64.tar.gz.asc \ + && curl https://dl.google.com/dl/linux/linux_signing_key.pub -Lo linux_signing_key.pub \ + && gpg --import linux_signing_key.pub && gpg --verify ./go.linux-arm64.tar.gz.asc ./go.linux-arm64.tar.gz \ + && rm -rf /usr/local/go && tar -C /usr/local -xzf go.linux-arm64.tar.gz +ENV PATH "$PATH:/usr/local/go/bin" + +# Compile libpcap from source +RUN curl https://www.tcpdump.org/release/libpcap-1.10.1.tar.gz -Lo ./libpcap.tar.gz \ + && curl https://www.tcpdump.org/release/libpcap-1.10.1.tar.gz.sig -Lo ./libpcap.tar.gz.sig \ + && curl https://www.tcpdump.org/release/signing-key.asc -Lo ./signing-key.asc \ + && gpg --import signing-key.asc && gpg --verify libpcap.tar.gz.sig libpcap.tar.gz \ + && tar -xzf libpcap.tar.gz && mv ./libpcap-* ./libpcap +WORKDIR /libpcap +RUN ./configure --host=x86_64 && make \ + && cp /libpcap/libpcap.a /usr/local/musl/lib/gcc/x86_64-unknown-linux-musl/*/ diff --git a/devops/linux-x86_64-musl-go-libpcap/build-push.sh b/devops/linux-x86_64-musl-go-libpcap/build-push.sh new file mode 100755 index 000000000..725366a64 --- /dev/null +++ b/devops/linux-x86_64-musl-go-libpcap/build-push.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e + +docker build . -t up9inc/linux-x86_64-musl-go-libpcap && docker push up9inc/linux-x86_64-musl-go-libpcap