47 lines
1008 B
Docker
47 lines
1008 B
Docker
# Build Stage
|
|
FROM rust:1.85-bookworm AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Cache dependencies
|
|
# We create a dummy project to build only dependencies
|
|
RUN cargo new --bin blog_cms
|
|
COPY Cargo.toml Cargo.lock ./
|
|
RUN cargo build --release
|
|
RUN rm src/*.rs
|
|
|
|
# Copy real source
|
|
COPY src ./src
|
|
COPY templates ./templates
|
|
|
|
# The templates are needed during compilation by askama
|
|
# Rebuild the real source
|
|
RUN touch src/main.rs && cargo build --release
|
|
|
|
# Final Stage
|
|
FROM debian:bookworm-slim
|
|
|
|
WORKDIR /app
|
|
|
|
# Install runtime dependencies (like SSL certificates and sqlite)
|
|
RUN apt-get update && apt-get install -y \
|
|
ca-certificates \
|
|
libsqlite3-0 \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy the binary from the builder
|
|
COPY --from=builder /app/target/release/blog_cms .
|
|
|
|
# Create directory for attachments and database
|
|
RUN mkdir -p attachments
|
|
|
|
# Default environment variables
|
|
ENV PORT=3000
|
|
ENV DATABASE_URL=sqlite:///app/data.db
|
|
|
|
# Expose the application port
|
|
EXPOSE 3000
|
|
|
|
# Start the application
|
|
CMD ["./blog_cms"]
|