Refactor Docker setup: consolidate Dockerfile stages, add entrypoint script, and update .gitignore and .dockerignore
This commit is contained in:
52
dockerfile
52
dockerfile
@@ -1,17 +1,51 @@
|
||||
FROM rust:1.88-slim as builder
|
||||
# =================================================================
|
||||
# Stage 1: Build the Rust application
|
||||
# =================================================================
|
||||
FROM rust:1.89-slim-bookworm AS builder
|
||||
|
||||
WORKDIR /usr/src/
|
||||
RUN apt-get update && apt-get install -y libsqlite3-dev pkg-config build-essential
|
||||
|
||||
COPY . .
|
||||
WORKDIR /app
|
||||
|
||||
COPY Cargo.toml Cargo.lock ./
|
||||
COPY .cargo ./.cargo/
|
||||
COPY migration ./migration
|
||||
|
||||
RUN mkdir -p src/bin && \
|
||||
echo "fn main() {}" > src/bin/main.rs && \
|
||||
echo "fn main() {}" > src/bin/tool.rs
|
||||
RUN cargo build --release
|
||||
|
||||
FROM debian:bookworm-slim
|
||||
COPY src ./src
|
||||
COPY assets ./assets
|
||||
COPY config ./config
|
||||
RUN cargo build --release
|
||||
|
||||
WORKDIR /usr/app
|
||||
# =================================================================
|
||||
# Stage 2: Create the final, lightweight runtime image
|
||||
# =================================================================
|
||||
FROM debian:bookworm-slim AS runtime
|
||||
|
||||
COPY --from=builder /usr/src/assets /usr/app/assets
|
||||
COPY --from=builder /usr/src/config /usr/app/config
|
||||
COPY --from=builder /usr/src/target/release/gabrielkaszewski_rs-cli /usr/app/gabrielkaszewski_rs-cli
|
||||
RUN apt-get update && apt-get install -y libsqlite3-0 libssl3 gosu && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ENTRYPOINT ["/usr/app/gabrielkaszewski_rs-cli", "start"]
|
||||
RUN addgroup --system nonroot && adduser --system --ingroup nonroot nonroot
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=builder /app/target/release/gabrielkaszewski_rs-cli ./server
|
||||
|
||||
COPY assets ./assets
|
||||
COPY config ./config
|
||||
|
||||
RUN mkdir -p /app/db /app/uploads && chown -R nonroot:nonroot /app/db /app/uploads
|
||||
|
||||
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||
RUN chmod +x /usr/local/bin/entrypoint.sh
|
||||
|
||||
ENV LOCO_ENV=production
|
||||
ENV DATABASE_URL=sqlite:///app/db/production.db?mode=rwc
|
||||
|
||||
EXPOSE 5150
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
||||
CMD ["./server", "start"]
|
Reference in New Issue
Block a user