Skip to content

Commit 91875d3

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 5246c1c commit 91875d3

File tree

8 files changed

+139
-44
lines changed

8 files changed

+139
-44
lines changed

.dockerignore

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

Dockerfile

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
1-
FROM debian:bookworm-slim
1+
ARG BITCOIN_VERSION=29.2
2+
ARG PYTHON_IMAGE_TAG=3.12-slim-trixie
3+
FROM bitcoin/bitcoin:${BITCOIN_VERSION} AS bitcoin
4+
FROM python:${PYTHON_IMAGE_TAG} AS joinmarket
25

3-
RUN mkdir -p /jm/clientserver
46
WORKDIR /jm/clientserver
7+
COPY ./pubkeys ./pubkeys
8+
COPY ./install.sh ./install.sh
9+
10+
RUN apt-get update \
11+
&& apt-get install -y --no-install-recommends \
12+
gnupg \
13+
ca-certificates \
14+
curl \
15+
&& ./install.sh --docker-install --only-deps \
16+
&& apt-get clean \
17+
&& rm -rf /var/lib/apt/lists/*
518

619
COPY . .
720

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 \
21+
RUN apt-get update \
22+
&& ./install.sh --docker-install --without-deps \
1423
&& apt-get clean \
1524
&& rm -rf /var/lib/apt/lists/*
1625

26+
FROM joinmarket AS test
27+
ARG BITCOIN_VERSION
28+
COPY --from=bitcoin /opt/bitcoin-${BITCOIN_VERSION}/bin /usr/local/bin/
29+
RUN ./install.sh --docker-install --without-deps --develop
30+
31+
FROM joinmarket AS final
32+
ENTRYPOINT ["./scripts/docker-entrypoint.sh"]

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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
services:
2+
test:
3+
image: joinmarket
4+
build:
5+
context: .
6+
target: test
7+
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+
entrypoint: ["/bin/sh", "-c"]
15+
command: [". ./jmvenv/bin/activate && exec ./test/run_tests.sh -v"]

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

install.sh

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,9 @@ CookieAuthentication 1
415415

416416
joinmarket_install ()
417417
{
418+
if [[ ${without_jm} == 1 ]]; then
419+
return 0
420+
fi
418421
reqs='services'
419422

420423
if [[ ${with_qt} == "1" ]]; then
@@ -424,8 +427,7 @@ joinmarket_install ()
424427
reqs+=',test'
425428
fi
426429

427-
if [ "$with_jmvenv" == 1 ]; then pip_command=pip; else pip_command=pip3; fi
428-
$pip_command install -e ".[${reqs}]" || return 1
430+
pip install -e ".[${reqs}]" || return 1
429431

430432
if [[ ${with_qt} == "1" ]]; then
431433
if [[ -d ~/.local/share/icons ]] && [[ -d ~/.local/share/applications ]]; then
@@ -484,7 +486,9 @@ parse_flags ()
484486
;;
485487
--docker-install)
486488
with_sudo='0'
487-
with_jmvenv='0'
489+
;;
490+
--deps)
491+
without_jm='1'
488492
;;
489493
"")
490494
break
@@ -507,6 +511,7 @@ Options:
507511
--with-local-tor build Tor locally and autostart when needed
508512
--with-qt build the Qt GUI
509513
--without-qt don't build the Qt GUI
514+
--deps install dependencies only, do not build or install Joinmarket
510515
"
511516
return 1
512517
;;
@@ -568,22 +573,18 @@ main ()
568573
use_os_deps_check='1'
569574
use_secp_check='1'
570575
with_qt=''
571-
with_jmvenv='1'
572576
with_sudo='1'
577+
without_jm='0'
573578
reinstall='false'
574579
if ! parse_flags "${@}"; then
575580
return 1
576581
fi
577582

578583
jm_source="$PWD"
579-
if [ "$with_jmvenv" == 1 ]; then
580-
jm_root="${jm_source}/jmvenv"
581-
export PKG_CONFIG_PATH="${jm_root}/lib/pkgconfig:${PKG_CONFIG_PATH}"
582-
export LD_LIBRARY_PATH="${jm_root}/lib:${LD_LIBRARY_PATH}"
583-
export C_INCLUDE_PATH="${jm_root}/include:${C_INCLUDE_PATH}"
584-
else
585-
jm_root=""
586-
fi
584+
jm_root="${jm_source}/jmvenv"
585+
export PKG_CONFIG_PATH="${jm_root}/lib/pkgconfig:${PKG_CONFIG_PATH}"
586+
export LD_LIBRARY_PATH="${jm_root}/lib:${LD_LIBRARY_PATH}"
587+
export C_INCLUDE_PATH="${jm_root}/include:${C_INCLUDE_PATH}"
587588

588589
# os check
589590
install_os="$( install_get_os )"
@@ -595,16 +596,12 @@ main ()
595596

596597
MAKEFLAGS="-j $(num_cores)" && export MAKEFLAGS
597598

598-
if [ "$with_jmvenv" == 1 ]; then
599-
if ! venv_setup; then
600-
echo "Joinmarket Python virtual environment could not be setup. Exiting."
601-
return 1
602-
fi
603-
# shellcheck source=/dev/null
604-
source "${jm_root}/bin/activate"
605-
else
606-
upgrade_setuptools
599+
if ! venv_setup; then
600+
echo "Joinmarket Python virtual environment could not be setup. Exiting."
601+
return 1
607602
fi
603+
# shellcheck source=/dev/null
604+
source "${jm_root}/bin/activate"
608605
if [[ ${build_local_tor} == "1" ]]; then
609606
if ! tor_deps_install; then
610607
echo "Tor dependencies could not be installed. Exiting."
@@ -634,17 +631,15 @@ main ()
634631
popd || return 1
635632
if ! joinmarket_install; then
636633
echo "Joinmarket was not installed. Exiting."
637-
if [ "$with_jmvenv" == 1 ]; then deactivate; fi
634+
deactivate
638635
return 1
639636
fi
640-
if [ "$with_jmvenv" == 1 ]; then
641-
deactivate
642-
echo "Joinmarket successfully installed
643-
Before executing scripts or tests, run:
637+
deactivate
638+
echo "Joinmarket successfully installed
639+
Before executing scripts or tests, run:
644640
645-
\`source jmvenv/bin/activate\`
641+
\`source jmvenv/bin/activate\`
646642
647-
from this directory, to activate the virtual environment."
648-
fi
643+
from this directory, to activate the virtual environment."
649644
}
650645
main "${@}"

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)