-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDockerfile
More file actions
103 lines (85 loc) · 3.55 KB
/
Copy pathDockerfile
File metadata and controls
103 lines (85 loc) · 3.55 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# ---- Chef Stage ----
FROM rust:1-alpine AS chef
RUN apk add --no-cache musl-dev perl build-base cmake
RUN cargo install cargo-chef
WORKDIR /app
# ---- Planner Stage ----
FROM chef AS planner
# cargo-chef needs every manifest in the workspace to build a recipe, so the
# whole crates tree is copied here. The sources are discarded with this stage.
COPY Cargo.toml Cargo.lock ./
COPY crates ./crates
RUN cargo chef prepare --recipe-path recipe.json
# ---- Builder Stage ----
FROM chef AS builder
# Declare TARGETARCH for this stage
ARG TARGETARCH
# Set up target architecture and install target
RUN if [ "$TARGETARCH" = "amd64" ]; then \
export RUST_TARGET="x86_64-unknown-linux-musl"; \
elif [ "$TARGETARCH" = "arm64" ]; then \
export RUST_TARGET="aarch64-unknown-linux-musl"; \
else \
echo "Unsupported architecture: $TARGETARCH" && exit 1; \
fi && \
rustup target add $RUST_TARGET && \
echo $RUST_TARGET > /tmp/rust_target
# Build dependencies only. This layer stays cached until Cargo.lock or one of
# the workspace manifests changes.
COPY --from=planner /app/recipe.json recipe.json
RUN RUST_TARGET=$(cat /tmp/rust_target) && \
cargo chef cook --release --target $RUST_TARGET --recipe-path recipe.json
# Copy the workspace and build the server. Only this layer rebuilds when source
# changes. `--bin vuio` skips the generate_test_media helper binary.
#
# VUIO_CARGO_FLAGS is for trimming the image. The default build is the whole
# server, including the AC-3/E-AC-3/DTS decoders — the person whose television
# plays a film silently is not going to rebuild an image to fix it. An operator
# who knows their renderers and wants the ~6 MB of decoder out can pass, e.g.:
#
# --build-arg VUIO_CARGO_FLAGS="--no-default-features \
# --features casting,dashboard,diagnostics,mcp,mediainfo,metadata,web-ui"
ARG VUIO_CARGO_FLAGS=""
COPY Cargo.toml Cargo.lock ./
COPY crates ./crates
RUN RUST_TARGET=$(cat /tmp/rust_target) && \
cargo build --release --locked --target $RUST_TARGET --package vuio-cli --bin vuio $VUIO_CARGO_FLAGS && \
cp target/$RUST_TARGET/release/vuio /tmp/vuio
# ---- Final Stage ----
FROM alpine:latest
# Install runtime dependencies including shadow for usermod/groupmod
RUN apk add --no-cache ca-certificates shadow su-exec
# Create a non-root user and group for security with default IDs
RUN addgroup -g 1000 vuio && adduser -u 1000 -G vuio -s /bin/sh -D vuio
# Create directories for the application, config, and media
RUN mkdir -p /app /config /media
# Copy the binary from the builder stage
COPY --from=builder /tmp/vuio /app/vuio
# Make sure the binary is executable
RUN chmod +x /app/vuio
# Set default environment variables for user/group IDs
ENV PUID=1000
ENV PGID=1000
# Set default environment variables for configuration
ENV VUIO_PORT=8080
# The Svelte browser interface, on its own listener beside the main port.
# VUIO_WEB_UI=0 turns it off.
ENV VUIO_WEB_PORT=8090
ENV VUIO_MEDIA_DIR=/media
ENV VUIO_BIND_INTERFACE=0.0.0.0
# Can be "Auto", "All", or a specific interface name e.g., "eth0"
ENV VUIO_SSDP_INTERFACE=Auto
ENV VUIO_SERVER_NAME=VuIO
# Copy the enhanced entrypoint script
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Expose ports for HTTP server (TCP), the web interface (TCP) and SSDP (UDP)
EXPOSE 8080/tcp
EXPOSE 8090/tcp
EXPOSE 1900/udp
# Use root for entrypoint to allow user switching
USER root
WORKDIR /app
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
# Default command to run the application
CMD ["/app/vuio", "--config", "/config/config.toml"]