Skip to content

Commit f9ad1a2

Browse files
committed
build: multi-stage builds and testing configuration
- Introduced a new `compose.yml` file for running tests in an isolated Docker environment. - Updated `Dockerfile` to support multi-stage builds, including a dedicated test stage with Bitcoin Core. - Enhanced `install.sh` to allow installation of dependencies only, without building JoinMarket. - Updated documentation to include Docker usage instructions for building images and running tests.
1 parent 21cbc31 commit f9ad1a2

File tree

8 files changed

+172
-18
lines changed

8 files changed

+172
-18
lines changed

.dockerignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
.git
22
*.egg-info
3+
configs
34
deps
4-
jmvenv
5+
jmvenv
6+
compose.yml
7+
Dockerfile

Dockerfile

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,38 @@
1-
FROM debian:bookworm-slim
2-
3-
RUN mkdir -p /jm/clientserver
1+
ARG BITCOIN_VERSION=29.2
2+
ARG PYTHON_IMAGE_TAG=3.13-slim-trixie
3+
FROM bitcoin/bitcoin:${BITCOIN_VERSION} AS bitcoin
4+
FROM python:${PYTHON_IMAGE_TAG} AS python
45
WORKDIR /jm/clientserver
56

6-
COPY . .
7-
8-
RUN apt-get update && apt-get install -y --no-install-recommends gnupg ca-certificates=* curl=* \
9-
python3-pip=* python3=* \
10-
&& pip3 config set global.break-system-packages true \
11-
&& pip3 install 'wheel>=0.35.1' \
12-
&& ./install.sh --docker-install \
13-
&& apt-get purge -y --autoremove python3-pip \
7+
FROM python AS base-deps
8+
RUN DEBIAN_FRONTEND=noninteractive \
9+
apt-get update \
10+
&& apt-get install -y --no-install-recommends \
11+
libsecp256k1-2 \
12+
libsodium23 \
13+
openssl \
14+
tor \
1415
&& apt-get clean \
1516
&& rm -rf /var/lib/apt/lists/*
1617

18+
FROM base-deps AS builder
19+
COPY . .
20+
RUN python -m venv jmvenv \
21+
&& . ./jmvenv/bin/activate \
22+
&& pip install .[services]
23+
24+
FROM base-deps AS base
25+
COPY --from=builder /jm/clientserver /jm/clientserver
26+
ENTRYPOINT ["./scripts/docker-entrypoint.sh"]
27+
28+
FROM base AS test
29+
ARG BITCOIN_VERSION
30+
COPY --from=bitcoin /opt/bitcoin-${BITCOIN_VERSION}/bin /usr/local/bin/
31+
RUN . ./jmvenv/bin/activate \
32+
&& pip install .[test]
33+
34+
FROM base AS obwatcher
35+
RUN . ./jmvenv/bin/activate && pip install matplotlib
36+
CMD ["python", "./scripts/obwatch/ob-watcher.py"]
37+
38+
FROM base AS joinmarket

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ Alternative to this "quickstart": follow the [install guide](docs/INSTALL.md).
6262
* [Installation guide for Qubes+Whonix](https://github.com/qubenix/qubes-whonix-bitcoin/blob/master/1_joinmarket.md).
6363
* [Youtube video installation tutorial for Ubuntu](https://www.youtube.com/watch?v=zTCC86IUzWo).
6464

65+
### Docker
66+
67+
JoinMarket can be built and run using Docker. To build the Docker image:
68+
69+
docker build -t joinmarket .
70+
71+
To run tests using Docker Compose:
72+
73+
docker compose up test
74+
75+
This will run the full test suite in an isolated environment with all necessary dependencies including Bitcoin Core.
76+
6577
### Usage
6678

6779
If you are new, follow and read the links in the [usage guide](docs/USAGE.md).

compose.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
services:
2+
test:
3+
image: joinmarket:test
4+
build:
5+
context: .
6+
target: test
7+
args: &build_args
8+
BITCOIN_VERSION: 29.2
9+
PYTHON_IMAGE_TAG: 3.13-slim-trixie
10+
volumes:
11+
- ./src:/jm/clientserver/src
12+
- ./test:/jm/clientserver/test
13+
shm_size: '2gb'
14+
command: ["./test/run_tests.sh", "-v"]
15+
tor:
16+
image: leplusorg/tor
17+
environment:
18+
- SOCKS_HOSTNAME=tor
19+
volumes:
20+
- tor:/var/lib/tor
21+
obwatcher:
22+
image: joinmarket:obwatcher
23+
build:
24+
context: .
25+
target: obwatcher
26+
args: *build_args
27+
command: ["python", "./scripts/obwatch/ob-watcher.py", "-H", "0.0.0.0"]
28+
ports:
29+
- "62601:62601"
30+
configs:
31+
- source: obwatch
32+
target: /root/.joinmarket/joinmarket.cfg
33+
volumes:
34+
- tor:/var/lib/tor:ro
35+
depends_on:
36+
- tor
37+
38+
configs:
39+
obwatch:
40+
file: ./configs/obwatch.cfg
41+
42+
volumes:
43+
tor:

configs/obwatch.cfg

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[DAEMON]
2+
no_daemon = 0
3+
4+
[BLOCKCHAIN]
5+
blockchain_source = no-blockchain
6+
7+
[MESSAGING:onion]
8+
type = onion
9+
socks5_host = tor
10+
socks5_port = 9050
11+
tor_control_host = tor
12+
tor_control_port = 9051
13+
onion_serving_host = 127.0.0.1
14+
onion_serving_port = 8080
15+
directory_nodes = satoshi2vcg5e2ept7tjkzlkpomkobqmgtsjzegg6wipnoajadissead.onion:5222,jmarketxf5wc4aldf3slm5u6726zsky52bqnfv6qyxe5hnafgly6yuyd.onion:5222,coinjointovy3eq5fjygdwpkbcdx63d7vd4g32mw7y553uj3kjjzkiqd.onion:5222,nakamotourflxwjnjpnrk7yc2nhkf6r62ed4gdfxmmn5f4saw5q5qoyd.onion:5222,odpwaf67rs5226uabcamvypg3y4bngzmfk7255flcdodesqhsvkptaid.onion:5222
16+
17+
[LOGGING]
18+
console_log_level = INFO
19+
color = true

docs/INSTALL.md

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,47 @@ There, you need to install the client code (without Joinmarket's bitcoin):
265265
266266
#### Docker Installation
267267
268-
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:
268+
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.
269269
270-
```
271-
docker build -t joinmarket-test ./
272-
docker run --rm -it joinmarket-test bash -c "cd scripts && python3 wallet-tool.py --help"
273-
```
270+
##### Building the Docker image
271+
272+
To build the production image:
273+
274+
docker build -t joinmarket .
275+
276+
This creates a minimal production image with JoinMarket installed.
277+
278+
##### Running JoinMarket scripts in Docker
279+
280+
Example of running the [wallet-tool.py](../scripts/wallet-tool.py) script:
281+
282+
docker run --rm -it joinmarket bash -c "source jmvenv/bin/activate && cd scripts && python wallet-tool.py --help"
283+
284+
##### Running tests with Docker Compose
285+
286+
The repository includes a `compose.yml` file for easy testing:
287+
288+
docker compose up test
289+
290+
This will:
291+
292+
* Build a test image that includes Bitcoin Core 29.2
293+
* Mount the `src` and `test` directories for development
294+
* Run the full test suite with all dependencies configured automatically
295+
* Use shared memory for improved test performance
296+
297+
##### Building custom images
298+
299+
The Dockerfile uses multi-stage builds with the following targets:
300+
301+
* `joinmarket` (default) - Production image with JoinMarket installed
302+
* `test` - Testing image that includes Bitcoin Core binaries
303+
304+
You can build a specific target:
305+
306+
docker build --target test -t joinmarket:test .
274307
275-
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.
308+
See [Docker documentation](https://docs.docker.com/engine/reference/builder/) for more details on multi-stage builds.
276309
277310
#### Development (or making other changes to the code)
278311

docs/TESTING.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
### Test instructions (for developers):
22

3+
#### Quick start: Running tests with Docker
4+
5+
The easiest way to run the full test suite is using Docker Compose, which handles all dependencies automatically:
6+
7+
docker compose run --rm test
8+
9+
This will:
10+
11+
* Build a Docker image with all dependencies (Python, Bitcoin Core 29.2, miniircd)
12+
* Run the complete test suite in an isolated environment
13+
* Automatically download and set up miniircd
14+
* No need to install bitcoind or other dependencies on your host machine
15+
16+
For development, the Docker setup mounts the `src` and `test` directories, so you can make changes locally and re-run tests without rebuilding the image.
17+
18+
#### Manual setup
19+
320
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):
421

522
(jmvenv)$ cd /path/to/joinmarket-clientserver

scripts/docker-entrypoint.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
# shellcheck disable=SC1091
4+
source jmvenv/bin/activate
5+
exec "$@"

0 commit comments

Comments
 (0)