-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
45 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |