quoter/Dockerfile

52 lines
1.3 KiB
Docker
Raw Normal View History

2024-11-13 06:08:34 +00:00
# Use a specific Rust version that is compatible with your dependencies
FROM rust:1.81-slim-buster AS build
2023-09-27 23:08:48 +00:00
2024-11-13 06:08:34 +00:00
# Print system information for debugging
2024-11-13 06:00:11 +00:00
RUN uname -a
2024-11-13 06:08:34 +00:00
RUN cat /etc/os-release
2024-11-13 06:00:11 +00:00
2024-11-13 06:08:34 +00:00
# Install necessary packages
2023-09-27 23:08:48 +00:00
RUN apt-get update -y && \
2024-11-13 05:56:18 +00:00
apt-get install -y git pkg-config make g++ libssl-dev wget \
2024-11-13 06:08:34 +00:00
libheif-dev libtiff-dev && \
2023-09-27 23:08:48 +00:00
rustup target add x86_64-unknown-linux-gnu
2023-10-02 11:33:26 +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 06:08:34 +00:00
# Use a minimal runtime image for the final stage
FROM debian:buster-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
RUN apt-get update && apt-get install -y openssl libssl-dev \
libheif1 libtiff5 && \
apt-get clean && 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"]