quoter/Dockerfile

54 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
2024-11-13 06:14:28 +00:00
FROM rust:alpine 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
2024-11-13 06:14:28 +00:00
RUN apk update && \
2024-11-13 07:24:50 +00:00
apk add git pkgconf make g++ openssl openssl-dev libheif libheif-dev tiff tiff-dev \
clang clang-dev llvm-dev llvm-static musl-dev && \
2024-11-13 06:24:10 +00:00
rustup target add x86_64-unknown-linux-musl
2023-10-02 11:33:26 +00:00
2024-11-13 07:24:50 +00:00
# Set environment variables for libclang
ENV LIBCLANG_PATH=/usr/lib
ENV BINDGEN_EXTRA_CLANG_ARGS="-I/usr/include"
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
2024-11-13 06:14:28 +00:00
FROM alpine:latest
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 06:18:41 +00:00
RUN apk update && apk add --no-cache openssl libheif tiff
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"]