Files
quoter/Dockerfile

61 lines
1.6 KiB
Docker
Raw Normal View History

2024-11-13 10:31:24 +03:00
# Use Debian-based Rust image instead of Alpine
FROM rust:slim-bookworm AS build
2024-11-13 09:00:11 +03:00
2024-11-13 09:08:34 +03:00
# Install necessary packages
2024-11-13 10:31:24 +03:00
RUN apt-get update && \
2024-11-13 10:41:13 +03:00
apt-get install -y git pkg-config make g++ libssl-dev libheif-dev libheif1 libtiff-dev \
2024-11-13 11:26:30 +03:00
clang libclang-dev pkg-config libde265-dev libx265-dev libjpeg-dev && \
2024-11-13 10:31:24 +03:00
rustup target add x86_64-unknown-linux-gnu
2023-10-02 14:33:26 +03:00
2024-11-13 10:24:50 +03:00
# Set environment variables for libclang
2024-11-13 10:31:24 +03:00
ENV LIBCLANG_PATH=/usr/lib/llvm-14/lib
2024-11-13 10:24:50 +03:00
ENV BINDGEN_EXTRA_CLANG_ARGS="-I/usr/include"
2024-11-13 10:46:44 +03:00
ENV PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/share/pkgconfig
2024-11-13 11:26:30 +03:00
ENV PKG_CONFIG_ALLOW_SYSTEM_LIBS=1
ENV PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1
2024-11-13 10:24:50 +03:00
2024-11-13 09:08:34 +03:00
# Create a new Rust binary project
2024-08-30 21:05:51 +03:00
RUN USER=root cargo new --bin quoter
WORKDIR /quoter
2023-10-02 14:33:26 +03:00
2024-11-13 09:08:34 +03:00
# Copy Cargo files to cache dependencies
2023-09-28 02:08:48 +03:00
COPY ./Cargo.lock ./Cargo.lock
COPY ./Cargo.toml ./Cargo.toml
2023-10-02 14:33:26 +03:00
2024-11-13 09:08:34 +03:00
# Cache dependencies
2023-09-28 02:08:48 +03:00
ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
RUN cargo build --release
2024-11-13 09:08:34 +03:00
# Remove the default source file created by cargo new
2023-09-28 02:08:48 +03:00
RUN rm src/*.rs
2023-10-02 14:33:26 +03:00
2024-11-13 09:08:34 +03:00
# Copy your source code into the container
2023-09-28 02:08:48 +03:00
COPY ./src ./src
2023-10-02 14:33:26 +03:00
2024-11-13 09:08:34 +03:00
# Build the application for release
2023-09-28 02:08:48 +03:00
RUN cargo build --release
2024-11-13 10:31:24 +03:00
# Use Debian slim for the final stage
FROM debian:bookworm-slim
2023-09-28 02:08:48 +03:00
ENV RUST_BACKTRACE=full
2024-10-02 19:59:24 +03:00
ENV RUST_LOG=warn
2024-10-02 18:55:38 +03:00
2024-11-13 09:08:34 +03:00
# Install runtime dependencies
2024-11-13 10:31:24 +03:00
RUN apt-get update && \
2024-11-13 11:14:53 +03:00
apt-get install -y --no-install-recommends \
libssl3 \
2024-11-13 11:18:59 +03:00
libheif1 \
2024-11-13 11:14:53 +03:00
libtiff6 \
2024-11-13 11:26:30 +03:00
libde265-0 \
libx265-199 \
libjpeg62-turbo \
2024-11-13 11:14:53 +03:00
&& rm -rf /var/lib/apt/lists/*
2023-09-28 02:08:48 +03:00
2024-11-13 09:08:34 +03:00
# Copy the compiled binary from the build stage
2024-08-30 21:05:51 +03:00
COPY --from=build /quoter/target/release/quoter .
2023-10-11 23:06:27 +03:00
2024-10-02 18:55:38 +03:00
ENV PORT=8080
2023-10-12 08:53:28 -03:00
EXPOSE 8080
2024-11-13 09:08:34 +03:00
CMD ["./quoter"]