-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Dockerfile
75 lines (51 loc) · 1.8 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
65
66
67
68
69
70
71
72
73
74
75
# 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/lnp
ARG BUILDER_DIR=/srv/lnp
# Base image
FROM rust:1.59.0-slim-bullseye as chef
ARG SRC_DIR
ARG BUILDER_DIR
RUN apt-get update && apt-get install -y build-essential
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/lnpd
ARG USER=lnp
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}
VOLUME "$DATA_DIR"
EXPOSE 9735
EXPOSE 62962
ENTRYPOINT ["lnpd"]
CMD ["-vvv", "--data-dir", "/var/lib/lnpd"]