Skip to content

Commit

Permalink
Cross-compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
rimrakhimov committed Jan 22, 2024
1 parent 9bf1024 commit 2677cdf
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions visualizer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM lukemathwalker/cargo-chef:0.1.62-rust-1.74-buster as chef
FROM --platform=$BUILDPLATFORM lukemathwalker/cargo-chef:0.1.62-rust-1.74-buster as chef

WORKDIR /app
RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v21.12/protoc-21.12-linux-x86_64.zip -O ./protoc.zip \
Expand All @@ -16,11 +16,38 @@ RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS build
COPY --from=plan /app/recipe.json recipe.json
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --recipe-path recipe.json

ARG BUILDPLATFORM
ARG BUILDOS
ARG BUILDARCH
ARG BUILDVARIANT
ARG TARGETPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT

RUN echo "BUILDPLATFORM=$BUILDPLATFORM"
RUN echo "BUILDOS=$BUILDOS"
RUN echo "BUILDARCH=$BUILDARCH"
RUN echo "BUILDVARIANT=$BUILDVARIANT"
RUN echo "TARGETPLATFORM=$TARGETPLATFORM"
RUN echo "TARGETOS=$TARGETOS"
RUN echo "TARGETARCH=$TARGETARCH"
RUN echo "TARGETVARIANT=$TARGETVARIANT"

ARG TARGETARCH
RUN case ${TARGETARCH} in \
"arm64") TARGETARCH=aarch64-unknown-linux-gnu ;; \
"amd64") TARGETARCH=x86_64-unknown-linux-gnu ;; \
esac \
&& echo "target=$TARGETARCH" \
&& rustup target add $TARGETARCH \
&& cargo chef cook --release --target $TARGETARCH --recipe-path recipe.json
# Build application
COPY . .
RUN cargo build --release
RUN cargo build --release --target $TARGET

RUN echo $(ls /app/target)

FROM node:16-bullseye-slim
WORKDIR /usr/src/
Expand Down

0 comments on commit 2677cdf

Please sign in to comment.