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