-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
41 lines (30 loc) · 990 Bytes
/
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
FROM rust:1.62 as build
# create a new empty shell project
RUN USER=root cargo new --bin backend
WORKDIR /backend
# copy over your manifests
COPY ./Cargo.lock ./Cargo.lock
COPY ./Cargo.toml ./Cargo.toml
# this build step will cache your dependencies
RUN cargo build --release && rm ./src/*.rs ./target/release/deps/backend*
# copy your source tree
COPY . ./
# build for release
RUN cargo build --release
# our final base
FROM debian:11-slim
# Create new user
RUN useradd --create-home backend
WORKDIR /home/backend
# Healthcheck
HEALTHCHECK --interval=5s --timeout=10s --retries=3 CMD curl -sS 127.0.0.1:8080/health || exit 1
RUN apt-get update && \
apt-get install --no-install-recommends -y curl && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Switch user
USER backend
# copy the build artifact from the build stage
COPY --from=build /backend/target/release/backend /usr/local/bin
# set the startup command to run your binary
CMD [ "/usr/local/bin/backend" ]