From 9f9e0272ea167762e2c8999e538877b132bea3d0 Mon Sep 17 00:00:00 2001 From: Tpt Date: Sun, 11 Jun 2023 15:29:27 +0200 Subject: [PATCH] Enables docker cross compilation to arm64 --- .github/workflows/artifacts.yml | 1 + server/Dockerfile | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml index 430a1c6e..e71b1df8 100644 --- a/.github/workflows/artifacts.yml +++ b/.github/workflows/artifacts.yml @@ -286,6 +286,7 @@ jobs: with: context: . file: server/Dockerfile + platforms: linux/amd64,linux/arm64 pull: true push: true tags: ${{ steps.docker_meta.outputs.tags }} diff --git a/server/Dockerfile b/server/Dockerfile index 77d6bece..92a6f4d4 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -1,11 +1,25 @@ -FROM rust:1-bullseye as builder +FROM --platform=$BUILDPLATFORM rust:1-bullseye as builder +ARG BUILDARCH TARGETARCH RUN apt-get update && \ - apt-get install -y libclang-dev clang + apt-get install -y libclang-dev clang && \ + if [ "$BUILDARCH" != "$TARGETARCH" ] && [ "$TARGETARCH" = "arm64" ] ; \ + then \ + apt-get install -y g++-aarch64-linux-gnu && \ + rustup target add aarch64-unknown-linux-gnu ; \ + fi COPY . /oxigraph -WORKDIR /oxigraph/server -RUN cargo build --release +WORKDIR /oxigraph/server +RUN if [ "$BUILDARCH" != "$TARGETARCH" ] && [ "$TARGETARCH" = "arm64" ] ; \ + then \ + export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc && \ + export BINDGEN_EXTRA_CLANG_ARGS="--sysroot /usr/aarch64-linux-gnu" && \ + cargo build --release --target aarch64-unknown-linux-gnu && \ + mv /oxigraph/target/aarch64-unknown-linux-gnu/release/oxigraph_server /oxigraph/target/release/oxigraph_server ; \ + else \ + cargo build --release ; \ + fi -FROM gcr.io/distroless/cc-debian11 +FROM --platform=$TARGETPLATFORM gcr.io/distroless/cc-debian11 COPY --from=builder /oxigraph/target/release/oxigraph_server /usr/local/bin/oxigraph_server ENTRYPOINT [ "/usr/local/bin/oxigraph_server" ] CMD [ "serve", "--location", "/data", "--bind", "0.0.0.0:7878" ]