-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
51 lines (37 loc) · 1.6 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
47
48
49
50
51
FROM rustlang/rust:nightly-bookworm 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/bin \
&& echo "fn main() {}" > src/bin/bot.rs \
&& echo "fn main() {}" > src/bin/metrics.rs \
&& echo "fn main() {}" > src/bin/track_check.rs \
&& echo "fn main() {}" > src/bin/queues.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 find src/bin/ -type f -exec touch {} + && 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/bot /usr/local/bin/rustify-bot
COPY --from=builder /usr/src/rustify/target/release/metrics /usr/local/bin/rustify-metrics
COPY --from=builder /usr/src/rustify/target/release/track_check /usr/local/bin/rustify-track-check
COPY --from=builder /usr/src/rustify/target/release/queues /usr/local/bin/rustify-queues