-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile.extras
76 lines (56 loc) · 1.97 KB
/
Dockerfile.extras
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
ARG BOT_PROFILE=prod
ARG BOT_TARGET=prod
# Setup.
# FROM rust:slim AS rust
FROM rustlang/rust:nightly-bookworm-slim AS rust
# Update OS and setup deps.
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
apt update && apt upgrade -y \
&& apt install -y --no-install-recommends \
pkg-config libopus-dev
# curl clang make cmake
# Compile.
FROM rust AS builder
# Use sparse registry.
ARG CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
ARG BOT_FEATURES=voice
ARG BOT_PROFILE BOT_TARGET
# Create a new empty shell project.
RUN cargo new --bin app
WORKDIR /app
# Create a temporary lib.rs to match the Cargo.toml config.
ARG TEMPLIB=./src/lib/lib.rs
RUN mkdir -p $(dirname $TEMPLIB) && touch $TEMPLIB
# Copy manifests.
# COPY ./.cargo ./.cargo
COPY ./Cargo.lock ./Cargo.toml ./
# Build only the dependencies to cache them.
RUN --mount=type=cache,target=~/.cargo,sharing=locked \
cargo build --profile=$BOT_PROFILE --features=$BOT_FEATURES
# Remove default code from deps build.
RUN rm ./src/*.rs \
&& rm ./target/$BOT_TARGET/deps/riveting_bot* \
&& rm ./target/$BOT_TARGET/deps/libriveting_bot*
# Copy the source code.
COPY ./src ./src
# Build with profile.
RUN --mount=type=cache,target=~/.cargo,sharing=locked \
cargo build --profile=$BOT_PROFILE --features=$BOT_FEATURES \
&& strip --strip-all ./target/$BOT_TARGET/riveting-bot
# Final image.
FROM debian:bookworm-slim AS final
ARG BOT_TARGET
# Update OS and setup deps.
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
apt update && apt upgrade -y \
# && apt install -y ca-certificates && update-ca-certificates \
&& apt install -y --no-install-recommends \
python3-pip libopus0
# It all just works.
RUN python3 -m pip install --break-system-packages -U yt-dlp
# Copy the build artifact from the build stage.
COPY --from=builder /app/target/$BOT_TARGET/riveting-bot /app/riveting-bot
# Run as non-root.
# USER 1000:1000
# Set the startup command.
ENTRYPOINT ["/app/riveting-bot"]