-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Dockerfile
64 lines (45 loc) · 1.68 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
# This image uses cargo-chef to build the application in order to compile
# the dependencies apart from the main application. This allows the compiled
# dependencies to be cached in the Docker layer and greatly reduce the
# build time when there isn't any dependency changes.
#
# https://github.com/LukeMathWalker/cargo-chef
ARG SRC_DIR=/usr/local/src/bp-descriptor-wallet
ARG BUILDER_DIR=/srv/bp-descriptor-wallet
# Base image
FROM rust:1.59.0-slim-bullseye as chef
ARG SRC_DIR
ARG BUILDER_DIR
RUN rustup default stable
RUN rustup update
RUN cargo install cargo-chef --locked
WORKDIR $SRC_DIR
# Cargo chef step that analyzes the project to determine the minimum subset of
# files (Cargo.lock and Cargo.toml manifests) required to build it and cache
# dependencies
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
ARG SRC_DIR
ARG BUILDER_DIR
COPY --from=planner "${SRC_DIR}/recipe.json" recipe.json
# Build dependencies - this is the caching Docker layer
RUN cargo chef cook --release --recipe-path recipe.json --target-dir "${BUILDER_DIR}"
# Copy all files and build application
COPY . .
RUN cargo build --release --target-dir "${BUILDER_DIR}" --bins --all-features
# Final image with binaries
FROM debian:bullseye-slim as final
ARG BUILDER_DIR
ARG BIN_DIR=/usr/local/bin
ARG DATA_DIR=/var/lib/bp-descriptor-wallet
ARG USER=bp
RUN adduser --home "${DATA_DIR}" --shell /bin/bash --disabled-login \
--gecos "${USER} user" ${USER}
COPY --from=builder --chown=${USER}:${USER} \
"${BUILDER_DIR}/release" "${BIN_DIR}"
WORKDIR "${BIN_DIR}"
# Remove build artifacts in order to keep only the binaries
RUN rm -rf */ *.d .[^.] .??*
USER ${USER}