-
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.
chore: 🚀 use cargo-chef for Dockerfile
- Loading branch information
1 parent
5abeaca
commit 00a9b51
Showing
6 changed files
with
76 additions
and
44 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 |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
.github/ | ||
.vscode/ | ||
target/ | ||
Dockerfile |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,28 +1,59 @@ | ||
FROM rust AS builder | ||
|
||
FROM rust:slim AS chef | ||
# We only pay the installation cost once, | ||
# it will be cached from the second build onwards | ||
RUN cargo install cargo-chef --locked | ||
WORKDIR /src | ||
|
||
FROM chef AS planner | ||
COPY . . | ||
RUN cargo chef prepare --recipe-path recipe.json | ||
|
||
RUN mkdir -p /root/.cargo cat >/root/.cargo/config <<EOF | ||
FROM docker.io/bufbuild/buf:latest AS buf | ||
|
||
FROM chef AS builder | ||
COPY --from=buf /usr/local/bin/buf /usr/local/bin/buf | ||
RUN <<EOF | ||
apt-get update | ||
apt-get install -y protobuf-compiler | ||
rm -rf /var/lib/apt/lists/* | ||
EOF | ||
COPY --from=planner /src/recipe.json recipe.json | ||
# Build dependencies - this is the caching Docker layer! | ||
RUN cargo chef cook --release --recipe-path recipe.json | ||
# Build application | ||
COPY . . | ||
RUN cargo build --release --bin rsjudge | ||
|
||
FROM debian:stable-slim AS rsjudge | ||
RUN <<EOF | ||
apt-get update | ||
apt-get install -y libcap2-bin | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
useradd --create-home \ | ||
--comment "Supervisor of rsjudge" \ | ||
--home /var/lib/rsjudge-supervisor/ \ | ||
--system \ | ||
--shell /sbin/nologin \ | ||
rsjudge-supervisor | ||
|
||
useradd --create-home \ | ||
--comment "Builder of rsjudge" \ | ||
--home /var/lib/rsjudge-builder/ \ | ||
--system \ | ||
--shell /sbin/nologin \ | ||
rsjudge-builder | ||
|
||
useradd --create-home \ | ||
--comment "Runner of rsjudge" \ | ||
--home /var/lib/rsjudge-runner/ \ | ||
--system \ | ||
--shell /sbin/nologin \ | ||
rsjudge-runner | ||
EOF | ||
|
||
RUN cargo build --release | ||
|
||
FROM gcr.io/distroless/base-debian12 | ||
|
||
COPY --from=builder /src/target/release/rsjudge /app | ||
COPY --from=builder /src/target/release/rsjudge /app/ | ||
RUN setcap "cap_setuid,cap_setgid,cap_dac_read_search=p" /app/rsjudge | ||
|
||
USER rsjudge-supervisor | ||
|
||
CMD ["/app/rsjudge"] | ||
|
||
# FROM rust:1 as build-env | ||
# WORKDIR /app | ||
# COPY . /app | ||
# RUN cargo build --release | ||
|
||
# FROM gcr.io/distroless/cc-debian12 | ||
# COPY --from=build-env /app/target/release/hello-world-distroless / | ||
# CMD ["./hello-world-distroless"] |
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
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