-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
46 lines (31 loc) · 1.17 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
FROM rust:1.83.0 AS builder
# Set the working directory inside the container
WORKDIR /usr/src/rustify
# copy over your manifests
COPY ./rust-toolchain.toml ./
# for installing toolchain
RUN rustup show
# Cache dependencies. First, copy the Cargo.toml and Cargo.lock
COPY Cargo.toml Cargo.lock ./
# Create a dummy main.rs to ensure `cargo build` can succeed for dependencies
RUN mkdir -p src && echo "fn main() {}" > src/main.rs
# Fetch dependencies without building the actual project (this will be cached)
RUN cargo fetch
RUN cargo build --release
# Copy the rest of the source code and build
COPY . .
ARG GIT_COMMIT_TIMESTAMP
ENV GIT_COMMIT_TIMESTAMP=${GIT_COMMIT_TIMESTAMP}
ARG GIT_SHA
ENV GIT_SHA=${GIT_SHA}
RUN touch src/main.rs && cargo build --release
# Use a minimal base image for the runtime
FROM debian:bookworm-slim
RUN \
--mount=type=cache,target=/var/cache/apt \
apt-get update && apt-get install --no-install-recommends -y ca-certificates \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Copy the compiled binary from the build stage
COPY --from=builder /usr/src/rustify/target/release/rustify /usr/local/bin/rustify
ENTRYPOINT [ "/usr/local/bin/rustify" ]