76 lines
2.1 KiB
Docker
76 lines
2.1 KiB
Docker
|
# 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"]
|