Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
68 lines (58 loc) · 2.27 KB
/
Copy pathDockerfile
File metadata and controls
68 lines (58 loc) · 2.27 KB
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
65
66
67
68
ARG RUST_VERSION=1
FROM rust:${RUST_VERSION}-bookworm AS builder
# Use a shell that exists whenever it encounters errors
SHELL ["/bin/bash", "-xo", "pipefail", "-c"]
# Install OS dependencies
RUN apt update \
&& apt install -y --no-install-recommends \
ca-certificates \
&& rm -rf /var/lib/apt/lists/* /tmp/*
WORKDIR /build
COPY . /build
# Run the build command.
# Note that this mounts several cache directories to speed up subsequent builds.
# After build, we move the binaries out of the target directory because that directory
# will not be available in the next steps (as it is a cached directory).
RUN --mount=type=cache,target=/usr/local/cargo/git/db \
--mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/build/target/ \
export SQLX_OFFLINE="true" \
&& cargo build --locked --release \
&& mkdir -p /build/artifacts \
&& cp target/release/nts-pool-ke /build/artifacts \
&& cp target/release/nts-pool-management /build/artifacts \
&& cp target/release/nts-pool-monitor /build/artifacts \
&& cp target/release/nts-pool-dns /build/artifacts
# Setup the final actual runner image stage
FROM debian:bookworm-slim AS runner
# Install system packages for the runner
RUN apt update \
&& apt install -y --no-install-recommends \
ca-certificates \
curl \
jq \
&& rm -rf /var/lib/apt/lists/* /tmp/*
# Copy compiled binaries from the builder stage
COPY --from=builder /build/artifacts/nts-pool-ke /usr/local/bin/nts-pool-ke
COPY --from=builder /build/artifacts/nts-pool-management /usr/local/bin/nts-pool-management
COPY --from=builder /build/artifacts/nts-pool-monitor /usr/local/bin/nts-pool-monitor
COPY --from=builder /build/artifacts/nts-pool-dns /usr/local/bin/nts-pool-dns
COPY --from=builder /build/nts-pool-management/assets /opt/nts-pool-management/assets
# Set a default assets directory
ENV NTSPOOL_ASSETS_DIR=/opt/nts-pool-management/assets
# Setup a user and group for the runner
ARG USER=nts-pool
ENV USER=${USER}
ARG UID=10001
ENV UID=${UID}
ARG GID=10001
ENV GID=${GID}
RUN addgroup --system --gid "${GID}" "${USER}" \
&& adduser \
--system \
--disabled-login \
--shell /bin/bash \
--uid "${UID}" \
--gid "${GID}" \
"${USER}"
USER ${USER}