good, but totally useless new Dockerfile

This commit is contained in:
Pavel 2024-05-26 13:56:00 +03:00
parent 3772c0ecb9
commit c4deff8386
2 changed files with 76 additions and 1 deletions

View File

@ -16,4 +16,4 @@ tower-http = { version = "0.5.2", features = ["trace"] }
num_cpus = "1.16.0" num_cpus = "1.16.0"
ffmpeg-next = "7.0.1" ffmpeg-next = "7.0.1"
ureq = { version = "*", features = ["json", "charset"] } ureq = { version = "*", features = ["json", "charset"] }
mime_guess = "2.0.4" mime_guess = "2.0.4"

75
Dockerfile.scratch Normal file
View File

@ -0,0 +1,75 @@
# Initially I wanted to build a slim image using this Dockerfile and static linking.
# It would use something like this in Cargo.toml:
#
# [build-dependencies.clang]
# version = "2.0.0"
# default-features = false
# features = ["static"]
#
# [build-dependencies.clang-sys]
# version = "1.7.0"
# default-features = false
# features = ["clang_16_0", "static"]
#
# But there are a lot of problems with static linking and clang & clang-sys crates:
# - https://github.com/KyleMayes/clang-sys/issues/174
# - https://github.com/KyleMayes/clang-rs/issues/17
# - https://github.com/KyleMayes/clang-sys/issues/148 (this is the one I *like* the most!)
#
# So, no static linking for now, but I don't wanna erase all this gorgeous Dockerfile code, so... I'll let it linger
# in the repo for now.
# Stage 1: Build the Rust application
FROM rust:1.78-alpine AS builder
# Set the working directory
WORKDIR /usr/src/
# Install necessary packages
RUN apk add --no-cache \
ffmpeg-libs \
ffmpeg-dev \
pkgconf \
musl-dev \
clang16-static \
llvm-dev \
zlib-dev \
libffi-dev \
ncurses-dev \
gcc \
g++ \
git \
build-base
# Add target for musl
RUN rustup target add x86_64-unknown-linux-musl
# Create a new Rust project
RUN USER=root cargo new atranscoder-rpc
WORKDIR /usr/src/atranscoder-rpc
# Copy the manifest and lock files
COPY Cargo.toml Cargo.lock ./
# Set the environment variable for libclang path
ENV LIBCLANG_PATH=/usr/lib/llvm16/lib
ENV PKG_CONFIG_PATH=/usr/lib/pkgconfig
# Build dependencies to cache them
RUN cargo build --release --target x86_64-unknown-linux-musl
# Copy the source code
COPY src ./src
# Build the project and install the binary
RUN cargo install --target x86_64-unknown-linux-musl --path . && \
mkdir -p /result/{tmp,bin} && \
mv /usr/local/cargo/bin/atranscoder-rpc /result/bin
# Stage 2: Create the final minimal image
FROM scratch
COPY --from=builder /usr/bin/dumb-init /bin/
COPY --from=builder /result/bin /bin
COPY --from=builder /result/tmp /tmp
EXPOSE 8090
ENTRYPOINT ["/bin/dumb-init", "--", "/bin/atranscoder-rpc"]