diff --git a/.dockerignore b/.dockerignore index cede6cc78..7739a9d3d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,6 @@ .git *.egg-info deps -jmvenv \ No newline at end of file +jmvenv +compose.yml +Dockerfile \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 30779464d..bd445c5e2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,34 @@ -FROM debian:bookworm-slim - -RUN mkdir -p /jm/clientserver +ARG BITCOIN_VERSION=29.2 +ARG PYTHON_IMAGE_TAG=3.13-slim-trixie +FROM bitcoin/bitcoin:${BITCOIN_VERSION} AS bitcoin +FROM python:${PYTHON_IMAGE_TAG} AS python WORKDIR /jm/clientserver -COPY . . - -RUN apt-get update && apt-get install -y --no-install-recommends gnupg ca-certificates=* curl=* \ - python3-pip=* python3=* \ - && pip3 config set global.break-system-packages true \ - && pip3 install 'wheel>=0.35.1' \ - && ./install.sh --docker-install \ - && apt-get purge -y --autoremove python3-pip \ +FROM python AS base-deps +RUN DEBIAN_FRONTEND=noninteractive \ + apt-get update \ + && apt-get install -y --no-install-recommends \ + libsecp256k1-2 \ + libsodium23 \ + openssl \ + tor \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* +FROM base-deps AS builder +COPY . . +RUN python -m venv jmvenv \ + && . ./jmvenv/bin/activate \ + && pip install -e .[services] + +FROM base-deps AS base +COPY --from=builder /jm/clientserver /jm/clientserver +ENTRYPOINT ["./scripts/docker-entrypoint.sh"] + +FROM base AS test +ARG BITCOIN_VERSION +COPY --from=bitcoin /opt/bitcoin-${BITCOIN_VERSION}/bin /usr/local/bin/ +RUN . ./jmvenv/bin/activate \ + && pip install -e .[test] + +FROM base AS joinmarket \ No newline at end of file diff --git a/README.md b/README.md index b3caa4b0b..b78692acc 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,18 @@ Alternative to this "quickstart": follow the [install guide](docs/INSTALL.md). * [Installation guide for Qubes+Whonix](https://github.com/qubenix/qubes-whonix-bitcoin/blob/master/1_joinmarket.md). * [Youtube video installation tutorial for Ubuntu](https://www.youtube.com/watch?v=zTCC86IUzWo). +### Docker + +JoinMarket can be built and run using Docker. To build the Docker image: + + docker build -t joinmarket . + +To run tests using Docker Compose: + + docker compose up test + +This will run the full test suite in an isolated environment with all necessary dependencies including Bitcoin Core. + ### Usage If you are new, follow and read the links in the [usage guide](docs/USAGE.md). diff --git a/compose.yml b/compose.yml new file mode 100644 index 000000000..119c0a501 --- /dev/null +++ b/compose.yml @@ -0,0 +1,18 @@ +services: + x-jmbase: + build: + context: . + args: + BITCOIN_VERSION: 29.2 + PYTHON_IMAGE_TAG: 3.13-slim-trixie + volumes: + - ./src:/jm/clientserver/src + - ./test:/jm/clientserver/test + - ./scripts:/jm/clientserver/scripts + test: + extends: x-jmbase + image: joinmarket:test + build: + target: test + shm_size: '2gb' + command: ["./test/run_tests.sh", "-v"] diff --git a/docs/INSTALL.md b/docs/INSTALL.md index b8bc17d00..f57cfe6e4 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -265,14 +265,34 @@ There, you need to install the client code (without Joinmarket's bitcoin): #### Docker Installation -The [Dockerfile](../Dockerfile) provided builds a minimal Docker image which can help in getting started with a custom Docker setup. An example of building and running the [wallet-tool.py](../scripts/wallet-tool.py) script: +The [Dockerfile](../Dockerfile) provided builds an optimized multi-stage Docker image for JoinMarket. The build process is optimized for layer caching and includes all necessary dependencies. -``` -docker build -t joinmarket-test ./ -docker run --rm -it joinmarket-test bash -c "cd scripts && python3 wallet-tool.py --help" -``` +##### Building the Docker image + +To build the production image: + + docker build -t joinmarket . + +This creates a minimal production image with JoinMarket installed. + +##### Running JoinMarket scripts in Docker + +Example of running the [wallet-tool.py](../scripts/wallet-tool.py) script: + + docker run --rm -it joinmarket python ./scripts/wallet-tool.py --help" + +##### Building custom images + +The Dockerfile uses multi-stage builds with the following targets: + +* `joinmarket` (default) - Production image with JoinMarket installed +* `test` - Testing image that includes Bitcoin Core binaries + +You can build a specific target: + + docker build --target test -t joinmarket:test . -A new Docker image can be built using `joinmarket-test` as a base using `FROM joinmarket-test`. See [Docker documentation](https://docs.docker.com/engine/reference/builder/) for more details. +See [Docker documentation](https://docs.docker.com/engine/reference/builder/) for more details on multi-stage builds. #### Development (or making other changes to the code) diff --git a/docs/TESTING.md b/docs/TESTING.md index 821aa4249..8db3411e0 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -1,5 +1,22 @@ ### Test instructions (for developers): +#### Quick start: Running tests with Docker + +The easiest way to run the full test suite is using Docker Compose, which handles all dependencies automatically: + + docker compose run --rm test + +This will: + +* Build a Docker image with all dependencies (Python, Bitcoin Core 29.2, miniircd) +* Run the complete test suite in an isolated environment +* Automatically download and set up miniircd +* No need to install bitcoind or other dependencies on your host machine + +For development, the Docker setup mounts the `src`, `scripts`, and `test` directories, so you can make changes locally and re-run tests without rebuilding the image. + +#### Manual setup + Work in your `jmvenv` virtual environment as for all Joinmarket work. Make sure to have [bitcoind](https://bitcoin.org/en/full-node) 28.1 or newer installed. Also need miniircd installed to the root (i.e. in your `joinmarket-clientserver` directory): (jmvenv)$ cd /path/to/joinmarket-clientserver diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh new file mode 100755 index 000000000..f1c202725 --- /dev/null +++ b/scripts/docker-entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# shellcheck disable=SC1091 +source jmvenv/bin/activate +exec "$@" \ No newline at end of file