From 5403048ce791417ee73482834905290119cc9e82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Loun=C3=A8s=20Ksouri?= Date: Sat, 16 Jul 2022 20:51:12 +0200 Subject: [PATCH 1/2] feat: add Dockerfile --- Dockerfile | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e2972da --- /dev/null +++ b/Dockerfile @@ -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} From 0f610e6dc6ee28a23e136e41a120baebc692b223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Loun=C3=A8s=20Ksouri?= Date: Sat, 16 Jul 2022 20:52:27 +0200 Subject: [PATCH 2/2] feat: add Docker instructions to README --- README.md | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 408eac5..b518a2c 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ [![Apache2 licensed](https://img.shields.io/badge/license-Apache%202-blue)](./LICENSE) Library for building descriptor-based bitcoin wallets. Everything a modern -cold and hot bitcoin wallet needs, but which is not (yet) a part of +cold and hot bitcoin wallet needs, but which is not (yet) a part of [rust-bitcoin](https://crates.io/bitcoin) library. The library clearly separates parts requiring access to private keys from @@ -23,15 +23,16 @@ command-line `btc-hot` and `btc-cold` wallets in [`bin`](bin) directory for an example of how this can be done. Library provides + - efficient manipulations with BIP-32 derivation paths, separating derivations requiring private key access from those, which will always operate without; - miniscript & classical bitcoin descriptors; -- PSBT constructor using input descriptors, which allow to specify custom +- PSBT constructor using input descriptors, which allow to specify custom information about RBFs, previous public key P2C tweaks and custom hash types on a per-input basis; - PSBT signer, supporting RBFs, relative and absolute timelocks, all sighash types, complex scripts, including witness- and taproot-based; -- script templates allowing embedding extended pubkeys into bitcoin script +- script templates allowing embedding extended pubkeys into bitcoin script assembly; - lexicographic ordering of transaction & PSBT inputs & oututs; - script type system; @@ -47,6 +48,7 @@ Library provides One may install command-line wallets with the following command (requires rust compiler and `rustup` tools to be already installed on a system): + ```console $ rustup default stable $ rustup update @@ -58,3 +60,35 @@ $ cargo install --path . --locked --all-features This will add `btc-hot` and `btc-cold` commands to the system. [bin]: https://github.com/BP-WG/descriptor-wallet/tree/master/src/bin + +### Install with Docker + +#### Build + +Clone the repository and checkout to the desired version (here `v0.8.0`): + +```console +$ git clone https://github.com/BP-WG/descriptor-wallet +$ cd descriptor-wallet +$ git checkout v0.8.0 +``` + +Build and tag the Docker image: + +```console +$ docker build -t descriptor-wallet:v0.8.0 . +``` + +#### Usage + +```console +$ docker run descriptor-wallet:v0.8.0 btc-hot --help +$ docker run descriptor-wallet:v0.8.0 btc-cold --help +``` + +#### Examples with files + +```console +$ docker run -v $PWD/data:/data descriptor-wallet:v0.8.0 btc-hot seed /data/testnet.seed +$ docker run -v $PWD/data:/data descriptor-wallet:v0.8.0 btc-hot derive --testnet /data/testnet.seed /data/testnet +```