feat: Add Dockerfile and Docker Compose configuration for containerized deployment and update README with instructions.
This commit is contained in:
46
Dockerfile
Normal file
46
Dockerfile
Normal file
@@ -0,0 +1,46 @@
|
||||
# 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"]
|
||||
Reference in New Issue
Block a user