Skip to content

Commit

Permalink
Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
thueske committed Oct 16, 2024
1 parent bae5031 commit 0dd59be
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 38 deletions.
54 changes: 16 additions & 38 deletions build/Dockerfile
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"]
1 change: 1 addition & 0 deletions build/recipe.json
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}}

0 comments on commit 0dd59be

Please sign in to comment.