Skip to content

Commit

Permalink
decrease docker image size
Browse files Browse the repository at this point in the history
  • Loading branch information
ayrat555 committed Sep 12, 2021
1 parent c8c9ea3 commit c93b022
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
58 changes: 47 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,57 @@
FROM rustlang/rust:nightly-bullseye

WORKDIR /app

COPY ./. .
####################################################################################################
## Builder
####################################################################################################
FROM rustlang/rust:nightly-bullseye AS builder
RUN apt update && apt install -y libssl-dev pkg-config libz-dev libcurl4 postgresql
RUN update-ca-certificates

# Create appuser
ENV USER=bot
ENV UID=10001

RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"

WORKDIR /bot

COPY ./ .

RUN cargo install diesel_cli --no-default-features --features postgres

RUN cargo build --release

RUN cp ./target/release/cleaner ./cleaner
####################################################################################################
## Final image
####################################################################################################
FROM debian:bullseye-slim

RUN apt update && apt install -y postgresql

# Import from builder.
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group

WORKDIR /bot

# Copy our build
COPY --from=builder /bot/target/release/el_monitorro ./
COPY --from=builder /bot/target/release/deliver ./
COPY --from=builder /bot/target/release/sync ./
COPY --from=builder /bot/target/release/cleaner ./

RUN cp ./target/release/sync ./sync
COPY --from=builder /bot/docker/start.sh ./

RUN cp ./target/release/el_monitorro ./el_monitorro
COPY --from=builder /usr/local/cargo/bin/diesel ./
COPY --from=builder /bot/migrations/ ./migrations/

RUN cp ./target/release/deliver ./deliver

RUN rm -rf ./target
# Use an unprivileged user.
USER bot:bot

CMD ["bash", "/app/docker/start.sh"]
CMD ["bash", "/bot/start.sh"]
2 changes: 1 addition & 1 deletion docker/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ then
echo "Proceeding without setting the database"
else
echo "Setting the database"
diesel database setup
./diesel database setup
fi


Expand Down

0 comments on commit c93b022

Please sign in to comment.