-
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
2 changed files
with
17 additions
and
38 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,42 +1,20 @@ | ||
# Der Build-Stage | ||
FROM rust:1-slim AS builder | ||
FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef | ||
WORKDIR /app | ||
|
||
# Kopiere die Cargo.toml und den Quellcode ins Arbeitsverzeichnis | ||
COPY Cargo.toml . | ||
COPY src ./src | ||
FROM chef AS planner | ||
COPY . . | ||
RUN cargo chef prepare --recipe-path recipe.json | ||
|
||
# Installiere notwendige Tools | ||
RUN apt-get update && apt-get install -y musl-tools | ||
FROM chef AS builder | ||
COPY --from=planner /app/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 cronjoblistener | ||
|
||
# Setze das Target Triple basierend auf der Architektur | ||
ARG TARGETARCH | ||
ENV RUST_TARGET_TRIPLE="" | ||
|
||
# Mapping der Architektur zu den korrekten Rust Triple | ||
RUN if [ "$TARGETARCH" = "amd64" ]; then \ | ||
export RUST_TARGET_TRIPLE=x86_64-unknown-linux-musl; \ | ||
elif [ "$TARGETARCH" = "arm64" ]; then \ | ||
export RUST_TARGET_TRIPLE=aarch64-unknown-linux-musl; \ | ||
fi && \ | ||
rustup target add ${RUST_TARGET_TRIPLE} && \ | ||
cargo build --release --target ${RUST_TARGET_TRIPLE} | ||
|
||
# Der finale Stage, der das Ergebnis des Builds verwendet | ||
FROM scratch | ||
# Verwende das gleiche ARG wie im Build-Stage | ||
ARG TARGETARCH | ||
ENV RUST_TARGET_TRIPLE="" | ||
|
||
# Setze das Triple erneut, damit es auch im finalen Stage verfügbar ist | ||
RUN if [ "$TARGETARCH" = "amd64" ]; then \ | ||
export RUST_TARGET_TRIPLE=x86_64-unknown-linux-musl; \ | ||
elif [ "$TARGETARCH" = "arm64" ]; then \ | ||
export RUST_TARGET_TRIPLE=aarch64-unknown-linux-musl; \ | ||
fi | ||
|
||
# Kopiere das gebaute Binary aus dem Build-Stage in das finale Image | ||
COPY --from=builder /app/target/${RUST_TARGET_TRIPLE}/release/cronjoblistener /app/cronjoblistener | ||
|
||
# Setze das Entry Point für den Container | ||
ENTRYPOINT ["/app/cronjoblistener"] | ||
# We do not need the Rust toolchain to run the binary! | ||
FROM debian:bookworm-slim AS runtime | ||
WORKDIR /app | ||
COPY --from=builder /app/target/release/cronjoblistener /usr/local/bin | ||
ENTRYPOINT ["/usr/local/bin/cronjoblistener"] |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
{"skeleton":{"manifests":[{"relative_path":"Cargo.toml","contents":"bench = []\ntest = []\nexample = []\n\n[[bin]]\npath = \"src/main.rs\"\nname = \"cronjoblistener\"\nplugin = false\nproc-macro = false\nedition = \"2021\"\nrequired-features = []\n\n[package]\nname = \"cronjoblistener\"\nedition = \"2021\"\nversion = \"0.0.1\"\n\n[dependencies]\nbollard = \"0.17\"\ndotenv = \"0.15\"\nenv_logger = \"0.11\"\nfutures-util = \"0.3\"\nlog = \"0.4\"\nserde_json = \"1.0\"\n\n[dependencies.serde]\nversion = \"1\"\nfeatures = [\"derive\"]\n\n[dependencies.tokio]\nversion = \"1\"\nfeatures = [\"full\"]\n\n[profile.release]\nopt-level = \"z\"\nlto = true\nstrip = true\n\n[profile.release.package]\n","targets":[{"path":"src/main.rs","kind":"Bin","name":"cronjoblistener"}]}],"config_file":null,"lock_file":null,"rust_toolchain_file":null}} |