-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
85 lines (63 loc) · 2.42 KB
/
Copy pathDockerfile
File metadata and controls
85 lines (63 loc) · 2.42 KB
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
77
78
79
80
81
82
83
84
85
# syntax=docker/dockerfile:1
# --- Base Stage (Shared setup) ---
FROM debian:bookworm AS base
ENV DEBIAN_FRONTEND=noninteractive
RUN rm -f /etc/apt/apt.conf.d/docker-clean && \
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
--mount=type=cache,target=/var/cache/debconf \
apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
cmake \
curl \
git \
libasound2-dev \
libpulse-dev \
pkg-config \
ca-certificates
ENV PATH="/root/.cargo/bin/:${PATH}"
RUN curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain 1.85 -y && \
cargo install cargo-chef
WORKDIR /src
# --- Stage 1: Planner (Calculate recipe) ---
FROM base AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
# --- Stage 2: Builder (Compile dependencies) ---
FROM base AS builder
COPY --from=planner /src/recipe.json recipe.json
RUN --mount=type=cache,target=/root/.cargo/registry \
--mount=type=cache,target=/src/target \
cargo chef cook --release --recipe-path recipe.json \
--no-default-features \
--features "rustls-tls-webpki-roots alsa-backend with-libmdns"
# --- Stage 3: Compiler (Compileer source code) ---
COPY . .
RUN --mount=type=cache,target=/root/.cargo/registry \
--mount=type=cache,target=/src/target \
cargo build --release \
--no-default-features \
--features "rustls-tls-webpki-roots alsa-backend with-libmdns" && \
cp target/release/librespot /tmp/librespot
# --- Stage 4: Runtime (Final Image) ---
FROM debian:bookworm-slim
ENV DEBIAN_FRONTEND=noninteractive
RUN rm -f /etc/apt/apt.conf.d/docker-clean && \
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
--mount=type=cache,target=/var/cache/debconf \
apt-get update && \
apt-get install -y --no-install-recommends \
libasound2 \
libpulse0 \
ca-certificates
RUN groupadd -r librespot && useradd -r -g librespot -G audio librespot
COPY --from=builder /tmp/librespot /usr/local/bin/librespot
COPY docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
USER librespot
WORKDIR /var/lib/librespot
ENTRYPOINT ["/entrypoint.sh"]