mirror of
https://github.com/kristoferssolo/tg-relay-rs.git
synced 2025-12-20 11:04:41 +00:00
feat(docker): optimize build times
This commit is contained in:
parent
e21e73f0b4
commit
e11223fa75
51
Dockerfile
51
Dockerfile
@ -1,34 +1,45 @@
|
||||
FROM rust:1.90-slim-trixie AS builder
|
||||
FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef
|
||||
WORKDIR /app
|
||||
|
||||
COPY Cargo.toml Cargo.lock ./
|
||||
|
||||
FROM chef AS planner
|
||||
COPY . .
|
||||
RUN cargo chef prepare --recipe-path recipe.json
|
||||
|
||||
|
||||
FROM chef AS builder-rs
|
||||
COPY --from=planner /app/recipe.json recipe.json
|
||||
# Build dependencies - this is the caching Docker layer!
|
||||
RUN cargo chef cook --release --recipe-path recipe.json
|
||||
# Build application
|
||||
COPY . .
|
||||
RUN cargo build --release
|
||||
|
||||
|
||||
FROM ghcr.io/astral-sh/uv:trixie-slim AS builder-py
|
||||
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
|
||||
|
||||
# Configure the Python directory so it is consistent
|
||||
ENV UV_PYTHON_INSTALL_DIR=/python
|
||||
|
||||
# Only use the managed Python version
|
||||
ENV UV_PYTHON_PREFERENCE=only-managed
|
||||
|
||||
# Install Python before the project for caching
|
||||
RUN uv python install 3.13
|
||||
|
||||
RUN apt-get update -y \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
pkg-config libssl-dev ca-certificates ffmpeg \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN cargo build --release
|
||||
|
||||
FROM python:3-slim AS runtime
|
||||
FROM python:3.12-slim-trixie
|
||||
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
|
||||
|
||||
ENV TZ=UTC
|
||||
ENV RUST_LOG=info
|
||||
ENV PATH=/home/app/.local/bin:$PATH
|
||||
|
||||
RUN useradd --create-home --shell /bin/bash app
|
||||
WORKDIR /home/app
|
||||
USER app
|
||||
RUN --mount=type=cache,target=/root/.cache/uv
|
||||
|
||||
# Intstall deps
|
||||
RUN uv tool install instaloader \
|
||||
&& instaloader --version
|
||||
|
||||
RUN uv tool install yt-dlp \
|
||||
&& instaloader --version \
|
||||
&& uv tool install yt-dlp[default] \
|
||||
&& yt-dlp --version
|
||||
|
||||
COPY --from=builder /app/target/release/tg-relay-rs /usr/local/bin/tg-relay-rs
|
||||
|
||||
COPY --from=builder-rs /app/target/release/tg-relay-rs /usr/local/bin/tg-relay-rs
|
||||
CMD ["/usr/local/bin/tg-relay-rs"]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user