-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
455b89b
commit ed4b2b8
Showing
1 changed file
with
19 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,28 @@ | ||
# syntax=docker/dockerfile:1.3.1 | ||
FROM rust:1.75-slim-buster as builder | ||
# https://github.com/LukeMathWalker/cargo-chef?tab=readme-ov-file#without-the-pre-built-image | ||
FROM rust:alpine AS chef | ||
RUN apk add --no-cache musl-dev | ||
RUN cargo --version | ||
RUN cargo install cargo-chef | ||
|
||
# Cache apt-get dependencies | ||
# https://stackoverflow.com/a/72851168/4875161 | ||
RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked \ | ||
--mount=target=/var/cache/apt,type=cache,sharing=locked \ | ||
rm -f /etc/apt/apt.conf.d/docker-clean \ | ||
&& apt-get update \ | ||
&& apt-get -y --no-install-recommends install \ | ||
libsqlite3-dev | ||
RUN mkdir -p /app | ||
WORKDIR /app | ||
|
||
# https://stackoverflow.com/a/58474618 | ||
# cache dependencies by building first with an empty main | ||
RUN echo "fn main() {}" > dummy.rs | ||
COPY .cargo/ .cargo/ | ||
COPY vendor/ vendor/ | ||
FROM chef AS planner | ||
COPY . . | ||
RUN cargo chef prepare --recipe-path recipe.json | ||
|
||
FROM chef AS builder | ||
COPY --from=planner /app/recipe.json recipe.json | ||
|
||
COPY macros/ macros/ | ||
COPY macros-impl/ macros-impl/ | ||
COPY Cargo.toml Cargo.lock . | ||
|
||
RUN sed -i 's#src/main.rs#dummy.rs#' Cargo.toml | ||
RUN cargo build --bin citadels | ||
# RUN cargo build --bin citadels --release | ||
RUN sed -i 's#dummy.rs#src/main.rs#' Cargo.toml | ||
COPY .env .env | ||
COPY templates/ templates/ | ||
COPY src/ src/ | ||
RUN cargo build --bin citadels | ||
# RUN cargo build --bin citadels --release | ||
RUN cargo chef cook --release --recipe-path recipe.json | ||
# Build application | ||
COPY . . | ||
RUN cargo build --release --bin citadels | ||
|
||
# new layer for smaller image | ||
FROM debian:buster-slim as runner | ||
RUN apt-get update && apt-get install libsqlite3-0 -y | ||
FROM alpine AS runtime | ||
WORKDIR /app | ||
# COPY --from=builder /app/target/release/citadels /app/citadels | ||
COPY --from=builder /app/target/debug/citadels /app/citadels | ||
COPY public/ public/ | ||
CMD ["/app/citadels"] | ||
|
||
COPY --from=builder /app/target/release/citadels /usr/local/bin | ||
ENTRYPOINT ["/usr/local/bin/citadels"] |