-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from louneskmt/docker
feat: add Dockerfile
- Loading branch information
Showing
2 changed files
with
101 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters