Skip to content

Commit

Permalink
chore: with cargo-chef
Browse files Browse the repository at this point in the history
  • Loading branch information
AsPulse committed Apr 2, 2024
1 parent cd6021b commit 603e634
Showing 1 changed file with 45 additions and 22 deletions.
67 changes: 45 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,62 @@
# syntax=docker/dockerfile:1

FROM rust:1.76.0-alpine3.19 as builder
FROM harbor.aspulse.dev/aspulse/rust-buildup:1.76.0-alpine3.19 as rust
WORKDIR /app

FROM rust as planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json


FROM rust as builder
ARG TARGETOS
ARG TARGETARCH

WORKDIR /app
RUN apk add --no-cache \
build-base libressl-dev ca-certificates sccache mold \
build-base libressl-dev ca-certificates \
&& update-ca-certificates

COPY Cargo.toml Cargo.lock ./
COPY src/ ./src/
RUN --mount=type=secret,id=SCCACHE_ENDPOINT \
--mount=type=secret,id=SCCACHE_AWS_ACCESS_KEY_ID \
--mount=type=secret,id=SCCACHE_AWS_SECRET_ACCESS_KEY \
<<EOF
set -e
SCCACHE_BUCKET=suterobot \
SCCACHE_REGION=auto \
SCCACHE_S3_KEY_PREFIX=${TARGETOS}_${TARGETARCH} \
SCCACHE_S3_USE_SSL=true \
SCCACHE_IDLE_TIMEOUT=3600 \
SCCACHE_S3_NO_CREDENTIALS=false \
SCCACHE_S3_SERVER_SIDE_ENCRYPTION=false \
SCCACHE_ENDPOINT=$(cat /run/secrets/SCCACHE_ENDPOINT) \
AWS_ACCESS_KEY_ID=$(cat /run/secrets/SCCACHE_AWS_ACCESS_KEY_ID) \
AWS_SECRET_ACCESS_KEY=$(cat /run/secrets/SCCACHE_AWS_SECRET_ACCESS_KEY) \
sccache --start-server
CARGO_INCREMENTAL=0 \
RUSTC_WRAPPER=sccache \
mold -run cargo build --locked --release
cp ./target/release/suterobot /bin/server
sccache --stop-server
set -e
export SCCACHE_BUCKET=suterobot
export SCCACHE_REGION=auto
export SCCACHE_S3_KEY_PREFIX=${TARGETOS}_${TARGETARCH}
export SCCACHE_S3_USE_SSL=true
export SCCACHE_IDLE_TIMEOUT=3600
export SCCACHE_S3_NO_CREDENTIALS=false
export SCCACHE_S3_SERVER_SIDE_ENCRYPTION=false
export SCCACHE_ENDPOINT=$(cat /run/secrets/SCCACHE_ENDPOINT)
export AWS_ACCESS_KEY_ID=$(cat /run/secrets/SCCACHE_AWS_ACCESS_KEY_ID)
export AWS_SECRET_ACCESS_KEY=$(cat /run/secrets/SCCACHE_AWS_SECRET_ACCESS_KEY)
export CARGO_INCREMENTAL=0
export RUSTC_WRAPPER=sccache
EOF

COPY --from=planner /app/recipe.json recipe.json

RUN <<EOF
set -e
sccache --start-server
mold -run cargo chef cook --release --recipe-path recipe.json
sccache --stop-server
EOF

COPY . .

RUN <<EOF
set -e
sccache --start-server
mold -run cargo build --release
cp ./target/release/suterobot /bin/server
sccache --stop-server
EOF

COPY --from=planner /app/recipe.json .


FROM alpine:3.19 as final
COPY --from=builder /bin/server /bin/
CMD ["/bin/server"]

0 comments on commit 603e634

Please sign in to comment.