blog/backend/Dockerfile

60 lines
1.9 KiB
Text
Raw Normal View History

2023-02-08 21:13:11 +00:00
FROM codycraven/sassc:latest as css
WORKDIR /usr/src/scss
RUN mkdir dist
WORKDIR /usr/src/scss/src
COPY ./scss .
RUN find . -name "*.scss" -type f | xargs -I % sh -c 'sassc % > ../dist/$(basename -- "%" .scss).css'
FROM tdewolff/minify:latest as static
WORKDIR /usr/src/static
COPY --from=css /usr/src/scss/dist ./css
RUN minify . -r -o .
2023-02-11 11:48:39 +00:00
FROM tdewolff/minify:latest as templates
WORKDIR /usr/src/templates
COPY ./templates .
RUN minify . -r -o .
2023-02-07 06:02:51 +00:00
FROM docker.io/lukemathwalker/cargo-chef:latest-rust-1.67.0 as chef
FROM chef as diesel
RUN cargo install diesel_cli --no-default-features --features postgres
FROM chef as planner
WORKDIR /usr/src/backend
RUN mkdir src && touch src/main.rs
COPY ./Cargo.toml ./Cargo.lock ./
RUN cargo chef prepare --recipe-path recipe.json
FROM chef as builder
WORKDIR /usr/src/backend
COPY --from=planner /usr/src/backend/recipe.json .
2023-02-08 21:13:11 +00:00
RUN cargo chef cook --recipe-path recipe.json
2023-02-07 06:02:51 +00:00
RUN rm -rf ./src
2023-02-08 21:13:11 +00:00
COPY ./build.rs .
COPY --from=static /usr/src/static ./static
2023-02-11 11:48:39 +00:00
COPY --from=templates /usr/src/templates ./templates
2023-02-07 06:02:51 +00:00
COPY ./src ./src
2023-02-08 21:13:11 +00:00
RUN cargo build
2023-02-07 06:02:51 +00:00
FROM docker.io/debian:bullseye-slim as runner
2023-02-11 11:48:39 +00:00
LABEL maintainer="Dominic Grimm <dominic@dergrimm.net>" \
org.opencontainers.image.description="Personal blog backend" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.source="https://git.dergrimm.net/dergrimm/blog" \
org.opencontainers.image.url="https://git.dergrimm.net/dergrimm/blog"
2023-02-07 06:02:51 +00:00
RUN apt update
RUN apt install -y libpq5
RUN apt install -y ca-certificates
RUN apt-get clean
RUN apt-get autoremove -y
RUN rm -rf /var/lib/{apt,dpkg,cache,log}/
WORKDIR /usr/local/bin
COPY --from=diesel /usr/local/cargo/bin/diesel .
WORKDIR /usr/src/backend
COPY ./run.sh .
RUN chmod +x ./run.sh
COPY ./migrations ./migrations
2023-02-08 21:13:11 +00:00
COPY --from=builder /usr/src/backend/target/debug/backend /usr/src/backend/target/debug/blogctl ./bin/
2023-02-07 06:02:51 +00:00
ENTRYPOINT [ "./run.sh" ]