Change docker file structure and reduce image size drastically

This change reduces the generated image size of ~2.6 GB to roughly 20 MB
This commit is contained in:
Manuel 2021-02-09 11:44:33 +01:00
parent c7ad153adf
commit 139242fc30
Signed by: Manuel
GPG key ID: 4085037435E1F07A

View file

@ -1,18 +1,21 @@
FROM rustlang/rust:nightly
FROM rust:alpine as build
ENV RUSTFLAGS='-C target-feature=-crt-static'
WORKDIR /app
COPY ./site .
RUN apk add --no-cache musl-dev sqlite-dev
RUN cargo install --path .
FROM alpine:latest
COPY --from=build /usr/local/cargo/bin/crablog /app/crablog
WORKDIR /app
RUN apk add --no-cache libgcc sqlite-libs
ENV ROOT_PATH=/app/content
ENV DATABASE_URL=${ROOT_PATH}/db.sqlite3
EXPOSE 8000
ENV ROOT_PATH=/root/crablog/content
ENV DATABASE_URL=${ROOT_PATH}/db.sqlite3
RUN mkdir -p /root/crablog
COPY ./site /root/crablog
# set up database
WORKDIR /root/crablog
# install crablog
RUN cargo install --path . --root / -j $(nproc)
CMD ["crablog"]
CMD ["./crablog"]