summaryrefslogtreecommitdiff
path: root/Dockerfile
diff options
context:
space:
mode:
authorMatthieu Pignolet <matthieu@matthieu-dev.xyz>2023-01-20 16:38:10 +0400
committerGitHub <noreply@github.com>2023-01-20 16:38:10 +0400
commitea1d345147759a4e2822c4145a87485f10d56a69 (patch)
tree5e152f2cd776babea7ad9a6c87b84d8012a39ea4 /Dockerfile
parent98420c50a81fccab924f646b1f8dd1e55988a4a5 (diff)
Draft: New cross building for docker images (#37)
* Add .circleci/config.yml * base * base * add architectures and cross build * fix clippy warnings
Diffstat (limited to 'Dockerfile')
-rw-r--r--Dockerfile46
1 files changed, 20 insertions, 26 deletions
diff --git a/Dockerfile b/Dockerfile
index 3eba9a0..3a3c34c 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,33 +1,27 @@
-FROM rust AS chef
-USER root
-COPY .cargo .cargo
-RUN cargo install cargo-chef
-RUN apt-get update && apt-get install -y protobuf-compiler
-WORKDIR /app
-
-# Planning install
-FROM chef AS planner
+# syntax=docker/dockerfile:1
+FROM --platform=$BUILDPLATFORM tonistiigi/xx:master AS xx
+FROM --platform=$BUILDPLATFORM rust:alpine as alpine_rbuild
+RUN apk add clang lld protobuf-dev build-base git
+# Copy the xx scripts
+COPY --from=xx / /
+# Copy source code
COPY . .
-RUN cargo chef prepare --recipe-path recipe.json
-
-# Building all targets
-FROM chef AS builder
-COPY --from=planner /app/recipe.json recipe.json
-# Notice that we are specifying the --target flag!
-RUN cargo chef cook --release --recipe-path recipe.json
-COPY . .
-RUN cargo build --release
+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 --mount=type=cache,target=/root/.cargo/git/db \
+ --mount=type=cache,target=/root/.cargo/registry/cache \
+ --mount=type=cache,target=/root/.cargo/registry/index \
+ xx-cargo build --release --target-dir ./build
-# Base os
-FROM debian:latest AS runtime-base
-# RUN addgroup -S nova && adduser -S nova -G nova
-RUN apt-get update && apt-get install ca-certificates -y
+#Copy from the build/<target triple>/release folder to the out folder
+RUN mkdir ./out && cp ./build/*/release/* ./out || true
-# Final os
-FROM runtime-base AS runtime
+FROM alpine AS runtime
ARG COMPONENT
ENV COMPONENT=${COMPONENT}
-COPY --from=builder /app/target/release/${COMPONENT} /usr/local/bin/
-# USER nova
+COPY --from=alpine_rbuild /out/${COMPONENT} /usr/local/bin/
ENTRYPOINT /usr/local/bin/${COMPONENT}