This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
generated from clechasseur/rust-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
64 lines (53 loc) · 1.79 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# syntax=docker/dockerfile:1
ARG RUST_VERSION=1.81.0
ARG RUST_TOOLCHAIN=stable
ARG APP_NAME=pokedex_rs
ARG SEED_APP_NAME=seed_db
ARG MIGRATE_APP_NAME=run_migrations
FROM rust:${RUST_VERSION}-bookworm AS build_stable
RUN echo "Building on Rust stable toolchain (${RUST_VERSION})"
FROM rustlang/rust:nightly AS build_nightly
RUN echo "Building on Rust nightly toolchain"
FROM build_${RUST_TOOLCHAIN} AS build
ARG APP_NAME
ARG SEED_APP_NAME
ARG MIGRATE_APP_NAME
WORKDIR /app
RUN --mount=type=bind,source=migrations,target=migrations \
--mount=type=bind,source=seed,target=seed \
--mount=type=bind,source=src,target=src \
--mount=type=bind,source=build.rs,target=build.rs \
--mount=type=bind,source=Cargo.toml,target=Cargo.toml \
--mount=type=bind,source=Cargo.lock,target=Cargo.lock \
--mount=type=bind,source=diesel.toml,target=diesel.toml \
--mount=type=cache,target=/app/target/ \
--mount=type=cache,target=/usr/local/cargo/registry/ \
<<EOF
set -e
cargo build --bins --locked --release
cp ./target/release/$APP_NAME /bin/server
cp ./target/release/$SEED_APP_NAME /bin/seed_db
cp ./target/release/$MIGRATE_APP_NAME /bin/run_migrations
cp -r ./seed /bin/seed
EOF
FROM debian:bookworm-slim AS final
LABEL org.opencontainers.image.authors="Charles Lechasseur <[email protected]>"
RUN apt-get update && \
apt-get install -y --no-install-recommends libpq5 && \
rm -rf /var/lib/apt/lists/*
ARG UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
appuser
USER appuser
COPY --from=build /bin/server /bin/
COPY --from=build /bin/seed_db /bin/
COPY --from=build /bin/run_migrations /bin/
COPY --from=build /bin/seed/* /bin/seed/
EXPOSE 8080
CMD ["/bin/server"]