From faa4c8d5070f11d73b30200a81fdb0f2fcaad480 Mon Sep 17 00:00:00 2001 From: strophy Date: Fri, 25 Nov 2022 15:48:46 +1100 Subject: [PATCH 1/5] feat: use xx-cargo for rust build --- Dockerfile | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7c42f285..c9c68756 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ ARG RUST_VERSION ARG SWIFT_VERSION -FROM --platform=$BUILDPLATFORM tonistiigi/xx AS xx +FROM --platform=$BUILDPLATFORM tonistiigi/xx:master AS xx FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} as go_host @@ -180,34 +180,37 @@ RUN make -j$(nproc) install-plugin RUN install -Ds /usr/local/bin/protoc-gen-grpc-web /out/usr/bin/protoc-gen-grpc-web -FROM rust:${RUST_VERSION}-alpine${ALPINE_VERSION} as rust_target +FROM --platform=$BUILDPLATFORM rust:${RUST_VERSION}-alpine${ALPINE_VERSION} as rust_target COPY --from=xx / / WORKDIR / RUN mkdir -p /out RUN apk add --no-cache \ build-base \ - curl + clang \ + curl \ + lld -FROM rust_target as protoc_gen_rust +FROM --platform=$BUILDPLATFORM rust_target as protoc_gen_rust RUN mkdir -p /rust-protobuf ARG PROTOC_GEN_RUST_VERSION RUN curl -sSL https://api.github.com/repos/stepancheg/rust-protobuf/tarball/v${PROTOC_GEN_RUST_VERSION} | tar xz --strip 1 -C /rust-protobuf WORKDIR /rust-protobuf/protobuf-codegen -RUN cargo build --release -RUN install -Ds /rust-protobuf/target/release/protoc-gen-rust /out/usr/bin/protoc-gen-rust ARG TARGETPLATFORM +RUN xx-cargo build --release +RUN ls -lha /rust-protobuf/target/release +RUN install -Ds /rust-protobuf/target/release/protoc-gen-rust /out/usr/bin/protoc-gen-rust RUN xx-verify /out/usr/bin/protoc-gen-rust -FROM rust_target as grpc_rust +FROM --platform=$BUILDPLATFORM rust_target as grpc_rust RUN mkdir -p /grpc-rust ARG GRPC_RUST_VERSION RUN curl -sSL https://api.github.com/repos/stepancheg/grpc-rust/tarball/v${GRPC_RUST_VERSION} | tar xz --strip 1 -C /grpc-rust WORKDIR /grpc-rust/grpc-compiler -RUN cargo build --release -RUN install -Ds /grpc-rust/target/release/protoc-gen-rust-grpc /out/usr/bin/protoc-gen-rust-grpc ARG TARGETPLATFORM +RUN xx-cargo build --release +RUN install -Ds /grpc-rust/target/release/protoc-gen-rust-grpc /out/usr/bin/protoc-gen-rust-grpc RUN xx-verify /out/usr/bin/protoc-gen-rust-grpc From 64c4f3d7e61528ab772fa23b87b9aeac6ecb3442 Mon Sep 17 00:00:00 2001 From: strophy Date: Fri, 25 Nov 2022 16:15:12 +1100 Subject: [PATCH 2/5] fix: protoc-gen-rust: No such file or directory --- Dockerfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2b21091c..dfe4ee3f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -198,8 +198,7 @@ RUN curl -sSL https://api.github.com/repos/stepancheg/rust-protobuf/tarball/v${P WORKDIR /rust-protobuf/protobuf-codegen ARG TARGETPLATFORM RUN xx-cargo build --release -RUN ls -lha /rust-protobuf/target/release -RUN install -Ds /rust-protobuf/target/release/protoc-gen-rust /out/usr/bin/protoc-gen-rust +RUN install -Ds /rust-protobuf/target/$(xx-cargo --print-target)/release/protoc-gen-rust /out/usr/bin/protoc-gen-rust RUN xx-verify /out/usr/bin/protoc-gen-rust @@ -210,7 +209,7 @@ RUN curl -sSL https://api.github.com/repos/stepancheg/grpc-rust/tarball/v${GRPC_ WORKDIR /grpc-rust/grpc-compiler ARG TARGETPLATFORM RUN xx-cargo build --release -RUN install -Ds /grpc-rust/target/release/protoc-gen-rust-grpc /out/usr/bin/protoc-gen-rust-grpc +RUN install -Ds /grpc-rust/target/$(xx-cargo --print-target)/release/protoc-gen-rust-grpc /out/usr/bin/protoc-gen-rust-grpc RUN xx-verify /out/usr/bin/protoc-gen-rust-grpc From b62bb9c3ba5ce4e5b343245767296291821b199c Mon Sep 17 00:00:00 2001 From: strophy Date: Fri, 25 Nov 2022 16:55:11 +1100 Subject: [PATCH 3/5] chore: enable cache for faster repeat builds --- Dockerfile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Dockerfile b/Dockerfile index dfe4ee3f..3e563594 100644 --- a/Dockerfile +++ b/Dockerfile @@ -196,6 +196,10 @@ RUN mkdir -p /rust-protobuf ARG PROTOC_GEN_RUST_VERSION RUN curl -sSL https://api.github.com/repos/stepancheg/rust-protobuf/tarball/v${PROTOC_GEN_RUST_VERSION} | tar xz --strip 1 -C /rust-protobuf WORKDIR /rust-protobuf/protobuf-codegen +RUN --mount=type=cache,target=/root/.cargo/git/db \ + --mount=type=cache,target=/root/.cargo/registry/cache \ + --mount=type=cache,target=/root/.cargo/registry/index \ + cargo fetch ARG TARGETPLATFORM RUN xx-cargo build --release RUN install -Ds /rust-protobuf/target/$(xx-cargo --print-target)/release/protoc-gen-rust /out/usr/bin/protoc-gen-rust @@ -207,6 +211,10 @@ RUN mkdir -p /grpc-rust ARG GRPC_RUST_VERSION RUN curl -sSL https://api.github.com/repos/stepancheg/grpc-rust/tarball/v${GRPC_RUST_VERSION} | tar xz --strip 1 -C /grpc-rust WORKDIR /grpc-rust/grpc-compiler +RUN --mount=type=cache,target=/root/.cargo/git/db \ + --mount=type=cache,target=/root/.cargo/registry/cache \ + --mount=type=cache,target=/root/.cargo/registry/index \ + cargo fetch ARG TARGETPLATFORM RUN xx-cargo build --release RUN install -Ds /grpc-rust/target/$(xx-cargo --print-target)/release/protoc-gen-rust-grpc /out/usr/bin/protoc-gen-rust-grpc From ca1844252ef27fd628bb0d3c8347e9d9ce962111 Mon Sep 17 00:00:00 2001 From: strophy Date: Fri, 25 Nov 2022 16:55:41 +1100 Subject: [PATCH 4/5] fix: strip: Unable to recognise the format of the input file --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3e563594..50864f7a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -202,7 +202,7 @@ RUN --mount=type=cache,target=/root/.cargo/git/db \ cargo fetch ARG TARGETPLATFORM RUN xx-cargo build --release -RUN install -Ds /rust-protobuf/target/$(xx-cargo --print-target)/release/protoc-gen-rust /out/usr/bin/protoc-gen-rust +RUN install -D /rust-protobuf/target/$(xx-cargo --print-target)/release/protoc-gen-rust /out/usr/bin/protoc-gen-rust RUN xx-verify /out/usr/bin/protoc-gen-rust @@ -217,7 +217,7 @@ RUN --mount=type=cache,target=/root/.cargo/git/db \ cargo fetch ARG TARGETPLATFORM RUN xx-cargo build --release -RUN install -Ds /grpc-rust/target/$(xx-cargo --print-target)/release/protoc-gen-rust-grpc /out/usr/bin/protoc-gen-rust-grpc +RUN install -D /grpc-rust/target/$(xx-cargo --print-target)/release/protoc-gen-rust-grpc /out/usr/bin/protoc-gen-rust-grpc RUN xx-verify /out/usr/bin/protoc-gen-rust-grpc From 1682bb04879374bc20fb1c4063fb903165331c69 Mon Sep 17 00:00:00 2001 From: strophy Date: Fri, 25 Nov 2022 17:22:29 +1100 Subject: [PATCH 5/5] chore: use cargo to produce stripped binaries --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 50864f7a..5d1f4150 100644 --- a/Dockerfile +++ b/Dockerfile @@ -201,7 +201,7 @@ RUN --mount=type=cache,target=/root/.cargo/git/db \ --mount=type=cache,target=/root/.cargo/registry/index \ cargo fetch ARG TARGETPLATFORM -RUN xx-cargo build --release +RUN xx-cargo --config profile.release.strip=true build --release RUN install -D /rust-protobuf/target/$(xx-cargo --print-target)/release/protoc-gen-rust /out/usr/bin/protoc-gen-rust RUN xx-verify /out/usr/bin/protoc-gen-rust @@ -216,7 +216,7 @@ RUN --mount=type=cache,target=/root/.cargo/git/db \ --mount=type=cache,target=/root/.cargo/registry/index \ cargo fetch ARG TARGETPLATFORM -RUN xx-cargo build --release +RUN xx-cargo --config profile.release.strip=true build --release RUN install -D /grpc-rust/target/$(xx-cargo --print-target)/release/protoc-gen-rust-grpc /out/usr/bin/protoc-gen-rust-grpc RUN xx-verify /out/usr/bin/protoc-gen-rust-grpc