Files
tuliprox/docker/Dockerfile
T

225 lines
8.0 KiB
Docker
Raw Normal View History

2025-06-13 02:01:38 +02:00
# =================================================================
#
2025-12-15 17:54:19 +01:00
# Dockerfile for local build (nativ, without Cross-Compilation)
2025-06-13 02:01:38 +02:00
#
# =================================================================
# -----------------------------------------------------------------
# Stage 1: Build the Rust binary for production
# -----------------------------------------------------------------
FROM rust:bookworm AS rust-build
2025-04-22 19:43:23 +02:00
# Get target architecture from build argument
ARG RUST_TARGET=x86_64-unknown-linux-musl
2023-10-17 10:27:37 +02:00
# Install build dependencies for Debian (bookworm)
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
pkg-config libssl-dev musl-tools && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
2025-03-14 16:09:07 +01:00
# Set Rust compiler flags for static linking against musl
ENV RUSTFLAGS='-C target-feature=+crt-static'
2024-03-27 12:04:54 -05:00
# Copy dependency files and the full 'shared' crate for dependency caching
2024-03-27 12:04:54 -05:00
WORKDIR /src
2025-04-22 19:43:23 +02:00
COPY Cargo.toml Cargo.lock ./
COPY shared ./shared/
COPY backend/Cargo.toml ./backend/
COPY frontend/Cargo.toml ./frontend/
# Create dummy main.rs for other crates to allow dependency build
RUN mkdir -p backend/src frontend/src && \
echo "fn main() {}" > backend/src/main.rs && \
echo "fn main() {}" > frontend/src/main.rs
2025-04-22 19:43:23 +02:00
# Build dependencies (this layer will be cached unless dependencies or 'shared' change)
RUN rustup target add ${RUST_TARGET}
RUN cargo build -p tuliprox --target ${RUST_TARGET} --release || true
2025-07-25 12:50:10 +02:00
# Now copy the rest of the source code and build the project
COPY backend ./backend/
COPY frontend ./frontend/
RUN cargo build -p tuliprox --target ${RUST_TARGET} --release
2024-03-27 12:04:54 -05:00
2025-06-13 02:01:38 +02:00
# -----------------------------------------------------------------
2025-07-25 12:50:10 +02:00
# Stage 2: Build the rust frontend
2025-06-13 02:01:38 +02:00
# -----------------------------------------------------------------
FROM rust:bookworm AS trunk-build
2025-07-25 12:50:10 +02:00
# Install dependencies for Trunk and WebAssembly
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
pkg-config libssl-dev curl binaryen && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
2025-07-25 12:50:10 +02:00
# Add wasm target & install trunk
RUN rustup target add wasm32-unknown-unknown
RUN cargo install --locked trunk wasm-bindgen-cli
2025-04-22 19:43:23 +02:00
# Set working directory
WORKDIR /src
# Copy dependency files and the full 'shared' crate for dependency caching
COPY Cargo.toml Cargo.lock ./
COPY shared ./shared/
COPY backend/Cargo.toml ./backend/
COPY frontend/Cargo.toml frontend/Trunk.toml ./frontend/
# Create dummy main.rs for BOTH frontend AND backend to satisfy workspace requirements
RUN mkdir -p frontend/src backend/src && \
echo "fn main() {}" > frontend/src/main.rs && \
echo "fn main() {}" > backend/src/main.rs
# Pre-build dependencies
WORKDIR /src/frontend
RUN cargo build --target wasm32-unknown-unknown --release || true
2025-04-22 19:43:23 +02:00
# Now copy the rest of the source code and build the project
WORKDIR /src
COPY frontend ./frontend/
2025-07-25 12:50:10 +02:00
2025-08-07 19:46:49 +02:00
WORKDIR /src/frontend
2025-04-22 19:43:23 +02:00
2025-07-25 12:50:10 +02:00
# Run Trunk build
RUN trunk build --release
2024-03-27 12:04:54 -05:00
2025-06-13 02:01:38 +02:00
# -----------------------------------------------------------------
# Stage 3: Build video resources with ffmpeg
# -----------------------------------------------------------------
2025-04-22 19:43:23 +02:00
FROM linuxserver/ffmpeg:latest AS resource-build
2025-05-22 18:49:47 +02:00
WORKDIR /src
COPY resources ./resources
2025-04-22 19:43:23 +02:00
# Combine ffmpeg commands into a single layer to reduce image size
2025-03-16 17:08:00 +01:00
RUN ffmpeg -loop 1 -i ./resources/channel_unavailable.jpg -t 10 -r 1 -an \
2025-04-22 19:43:23 +02:00
-vf "scale=1920:1080" \
-c:v libx264 -preset veryfast -crf 23 -pix_fmt yuv420p \
./resources/channel_unavailable.ts && \
ffmpeg -loop 1 -i ./resources/user_connections_exhausted.jpg -t 10 -r 1 -an \
-vf "scale=1920:1080" \
-c:v libx264 -preset veryfast -crf 23 -pix_fmt yuv420p \
./resources/user_connections_exhausted.ts && \
ffmpeg -loop 1 -i ./resources/provider_connections_exhausted.jpg -t 10 -r 1 -an \
-vf "scale=1920:1080" \
-c:v libx264 -preset veryfast -crf 23 -pix_fmt yuv420p \
2025-05-26 13:57:29 +02:00
./resources/provider_connections_exhausted.ts && \
ffmpeg -loop 1 -i ./resources/user_account_expired.jpg -t 10 -r 1 -an \
-vf "scale=1920:1080" \
-c:v libx264 -preset veryfast -crf 23 -pix_fmt yuv420p \
./resources/user_account_expired.ts
2025-05-22 17:39:06 +02:00
2025-06-13 02:01:38 +02:00
# -----------------------------------------------------------------
# Stage 4: Prepare timezone data
# -----------------------------------------------------------------
2025-05-22 17:39:06 +02:00
FROM alpine:latest AS tz-prep
2025-05-22 18:49:47 +02:00
2025-05-22 17:39:06 +02:00
ARG TZ=UTC
2025-05-22 18:49:47 +02:00
ENV TZ=${TZ}
2025-05-22 17:39:06 +02:00
RUN apk add --no-cache tzdata \
&& mkdir -p /output/etc \
&& mkdir -p /output/usr/share \
&& cp -r /usr/share/zoneinfo /output/usr/share/zoneinfo \
2025-05-22 18:49:47 +02:00
&& ln -sf /usr/share/zoneinfo/${TZ} /output/etc/localtime
2025-05-22 17:39:06 +02:00
2025-06-13 02:01:38 +02:00
# =================================================================
#
# Part 2: Final Image Stages
#
# =================================================================
# -----------------------------------------------------------------
# Final Image #1: Debugging Environment (Alpine-based)
# -----------------------------------------------------------------
FROM rust:alpine AS debug
# Make the build-time argument available as a run-time environment variable
2025-06-13 02:01:38 +02:00
ARG RUST_TARGET=x86_64-unknown-linux-musl
ARG TZ=UTC
# Make the build-time argument available as a run-time environment variable
ENV RUST_TARGET=${RUST_TARGET}
ENV TZ=${TZ}
# Install build dependencies and debugger for Alpine.
# 'build-base' contains gcc, make, etc.
# 'gdb' is required for the debugger (lldb is often more complicated in Alpine repos)
RUN apk add --no-cache bash build-base openssl-dev perl lldb gdb
2025-06-13 02:01:38 +02:00
# Update Rust toolchain and add the necessary target
RUN rustup update && rustup target add $RUST_TARGET
# Create the app layout to simulate the production environment
2025-06-13 02:01:38 +02:00
WORKDIR /app
2025-08-07 19:46:49 +02:00
COPY --from=trunk-build /src/frontend/dist ./web
COPY --from=resource-build /src/resources ./resources
2025-06-13 02:01:38 +02:00
# Create a separate directory for the source code
WORKDIR /usr/src/tuliprox
COPY . .
# Copy the entrypoint script and set it as the entry point for the container
2025-06-13 02:01:38 +02:00
COPY ./docker/debug/debug-entrypoint.sh /usr/local/bin/entrypoint.sh
2025-06-13 02:01:38 +02:00
# Ensure the script is executable
RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
# The CMD is passed as an argument to the Entrypoint script.
# This keeps the container running indefinitely for interactive debugging.
2025-06-13 02:01:38 +02:00
CMD ["tail", "-f", "/dev/null"]
# -----------------------------------------------------------------
# Final Image #2: Production image based on scratch
# -----------------------------------------------------------------
2025-04-18 16:12:38 +02:00
FROM scratch AS scratch-final
2025-04-22 19:43:23 +02:00
ARG RUST_TARGET=x86_64-unknown-linux-musl
2025-04-22 19:43:23 +02:00
2025-05-22 17:39:06 +02:00
# Copy timezone data and localtime from tz-prep
COPY --from=tz-prep /output/usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=tz-prep /output/etc/localtime /etc/localtime
# Copy SSL certificates from a builder stage that has them
2024-03-27 12:04:54 -05:00
COPY --from=rust-build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
2025-05-22 17:39:06 +02:00
# App
WORKDIR /app
COPY --from=rust-build /src/target/${RUST_TARGET}/release/tuliprox ./tuliprox
2025-08-07 19:46:49 +02:00
COPY --from=trunk-build /src/frontend/dist ./web
COPY --from=resource-build /src/resources ./resources
2025-05-22 17:39:06 +02:00
2025-05-10 17:59:50 +02:00
ENTRYPOINT ["/app/tuliprox"]
2025-04-14 15:51:16 +02:00
CMD ["-s", "-p", "/app/config"]
2024-10-21 19:41:17 +02:00
2025-06-13 02:01:38 +02:00
# -----------------------------------------------------------------
# Final Image #3: Production image based on Alpine
# -----------------------------------------------------------------
2025-04-18 16:12:38 +02:00
FROM alpine:latest AS alpine-final
2025-04-22 19:43:23 +02:00
ARG RUST_TARGET=x86_64-unknown-linux-musl
2025-05-22 18:49:47 +02:00
ARG TZ=UTC
ENV TZ=${TZ}
2025-04-22 19:43:23 +02:00
2024-12-29 11:36:44 +01:00
RUN apk add --no-cache bash curl ca-certificates tini
2025-04-22 19:43:23 +02:00
# Copy timezone data and localtime from tz-prep
COPY --from=tz-prep /output/usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=tz-prep /output/etc/localtime /etc/localtime
# Copy SSL certificates `ca-certificates` from Alpine-based Stage (tz-prep ist Alpine)
COPY --from=tz-prep /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
2025-05-22 17:39:06 +02:00
# Default timezone fallback
RUN ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime
2024-10-21 19:41:17 +02:00
WORKDIR /app
COPY --from=rust-build /src/target/${RUST_TARGET}/release/tuliprox ./tuliprox
2025-08-07 19:46:49 +02:00
COPY --from=trunk-build /src/frontend/dist ./web
COPY --from=resource-build /src/resources ./resources
2025-06-13 02:01:38 +02:00
2025-05-10 17:59:50 +02:00
ENTRYPOINT ["/sbin/tini", "--", "/app/tuliprox"]
CMD ["-s", "-p", "/app/config"]