p4bl0t/Dockerfile
Lucien Cartier-Tilet 60a81f66a8
All checks were successful
Create and publish a Docker image / build-and-push-image (push) Successful in 8m1s
feat: Enable Docker deployment and CD
Closes #8, partially addresses #6
2023-11-26 04:22:56 +01:00

47 lines
1.2 KiB
Docker

ARG RUST_VERSION=1.73.0
FROM rust:${RUST_VERSION}-slim-bullseye AS build
RUN --mount=type=cache,target=/usr/local/cargo/registry \
cargo install sqlx-cli --no-default-features --features rustls,sqlite && \
cp /usr/local/cargo/bin/sqlx /bin/sqlx
ENV DATABASE_URL=sqlite:/var/p4bl0t.db
WORKDIR /app
RUN --mount=type=bind,source=src,target=src \
--mount=type=bind,source=Cargo.toml,target=Cargo.toml \
--mount=type=bind,source=Cargo.lock,target=Cargo.lock \
--mount=type=bind,source=migrations,target=migrations \
--mount=type=cache,target=/app/target/ \
--mount=type=cache,target=/usr/local/cargo/registry \
<<EOF
set -e
sqlx database create
sqlx migrate run
cargo build --locked --release
cargo install --path .
EOF
FROM debian:bullseye-slim AS final
RUN apt-get update && apt-get install -qqy ca-certificates
ARG UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
appuser
USER appuser
ENV DATABASE_URL=sqlite:/var/p4bl0t.db
ENV DISCORD_TOKEN=changeme
COPY --from=build /usr/local/cargo/bin/p4bl0t /bin
COPY --chown=appuser --from=build /var/p4bl0t.db /var/p4bl0t.db
CMD [ "p4bl0t" ]