Skip to content

Commit

Permalink
Add container environment for running blackbox tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
rndhouse committed Apr 21, 2022
1 parent 20ae458 commit 9b73b2f
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
venv
target
.git
88 changes: 88 additions & 0 deletions tests/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Build bitcoind.
# Copied (MIT License) from: https://github.com/kylemanna/docker-bitcoind/blob/5b51b7a168ae6d209b6b8afc91e3cc54ea5dab22/Dockerfile

# Smallest base image, latests stable image
# Alpine would be nice, but it's linked again musl and breaks the bitcoin core download binary
#FROM alpine:latest
FROM ubuntu:latest as builder_bitcoind

# Testing: gosu
#RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing/" >> /etc/apk/repositories \
# && apk add --update --no-cache gnupg gosu gcompat libgcc
RUN apt update \
&& apt install -y --no-install-recommends \
ca-certificates \
wget \
gnupg \
&& apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ARG VERSION=22.0
ARG ARCH=x86_64
ARG BITCOIN_CORE_SIGNATURE=71A3B16735405025D447E8F274810B012346C9A6

# Don't use base image's bitcoin package for a few reasons:
# 1. Would need to use ppa/latest repo for the latest release.
# 2. Some package generates /etc/bitcoin.conf on install and that's dangerous to bake in with Docker Hub.
# 3. Verifying pkg signature from main website should inspire confidence and reduce chance of surprises.
# Instead fetch, verify, and extract to Docker image
RUN cd /tmp \
&& gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys ${BITCOIN_CORE_SIGNATURE} \
&& wget https://bitcoincore.org/bin/bitcoin-core-${VERSION}/SHA256SUMS.asc \
https://bitcoincore.org/bin/bitcoin-core-${VERSION}/SHA256SUMS \
https://bitcoincore.org/bin/bitcoin-core-${VERSION}/bitcoin-${VERSION}-${ARCH}-linux-gnu.tar.gz \
&& gpg --verify --status-fd 1 --verify SHA256SUMS.asc SHA256SUMS 2>/dev/null | grep "^\[GNUPG:\] VALIDSIG.*${BITCOIN_CORE_SIGNATURE}\$" \
&& sha256sum --ignore-missing --check SHA256SUMS \
&& tar -xzvf bitcoin-${VERSION}-${ARCH}-linux-gnu.tar.gz -C /opt \
&& ln -sv bitcoin-${VERSION} /opt/bitcoin \
&& /opt/bitcoin/bin/test_bitcoin --show_progress \
&& rm -v /opt/bitcoin/bin/test_bitcoin /opt/bitcoin/bin/bitcoin-qt

# Build revaultd and associated tools.
FROM docker.io/rust:1.58-buster as builder_revaultd
WORKDIR /revaultd
COPY . .
RUN cargo install --path . \
&& (cd contrib/tools/mscompiler && cargo install --path .) \
&& (cd tests/servers/coordinatord && cargo install --path .) \
&& (cd tests/servers/cosignerd && cargo install --path .) \
&& (cd tests/servers/miradord && cargo install --path .)

# Setup and run blackbox tests.
FROM ubuntu:latest
COPY --from=builder_revaultd /usr/local/cargo/bin/revaultd /usr/local/bin/revaultd
COPY --from=builder_revaultd /usr/local/cargo/bin/mscompiler /usr/local/bin/mscompiler
COPY --from=builder_revaultd /usr/local/cargo/bin/coordinatord /usr/local/bin/coordinatord
COPY --from=builder_revaultd /usr/local/cargo/bin/cosignerd /usr/local/bin/cosignerd
COPY --from=builder_revaultd /usr/local/cargo/bin/miradord /usr/local/bin/miradord

# Setup bitcoind.
ARG GROUP_ID=1000
ARG USER_ID=1000
RUN groupadd -g ${GROUP_ID} bitcoin \
&& useradd -u ${USER_ID} -g bitcoin -d /bitcoin bitcoin
COPY --from=builder_bitcoind /opt/ /opt/
RUN ln -sv /opt/bitcoin/bin/* /usr/local/bin
RUN apt update \
&& apt install -y --no-install-recommends gosu

# Setup revaultd integration tests.
WORKDIR /test-revaultd
COPY ./tests ./tests
RUN apt update \
&& DEBIAN_FRONTEND=noninteractive apt install -y --no-install-recommends \
python3 python3-venv \
postgresql python3-psycopg2 libpq-dev \
build-essential libssl-dev libffi-dev python-dev
RUN python3 -m venv venv \
&& . venv/bin/activate \
&& pip install -r tests/requirements.txt

# Cleanup.
RUN apt clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ENV REVAULTD_PATH=revaultd
ENV MSCOMPILER=mscompiler
ENV MIRADORD_PATH=miradord
ENV COORDINATORD_PATH=coordinatord
ENV COSIGNERD_PATH=cosignerd
47 changes: 47 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,53 @@ To run the server-requiring tests, pass the postgres credentials to the framewor
POSTGRES_USER="test" POSTGRES_PASS="test" TEST_DEBUG=1 pytest -vvv -n8 --timeout=1800
```

#### Using the containerized testing environment

Ensure that all git submodules are included in the repository:

```bash
git submodule update --init --recursive
```

Build the container image using podman (docker can also build the container):

```bash
podman build -t revault_blackbox_tests -f ./tests/Containerfile .
```

Start a podman pod to simplify inter-container communication:

```bash
podman pod create --name=revault_test_pod
```

Start postgres within the pod:

```bash
podman run --pod=revault_test_pod --rm -d --name postgres-coordinatord -e POSTGRES_PASSWORD=revault -e POSTGRES_USER=revault -e POSTGRES_DB=coordinator_db postgres:alpine
```

Run the test environment container within the pod:

```bash
podman run --pod=revault_test_pod -it revault_blackbox_tests /bin/bash
```

Activate the Python environment:

```bash
. venv/bin/activate
```

Run the tests:

```bash
pytest tests/ -vvv -n4 --ignore tests/servers/
```

```bash
POSTGRES_USER=revault POSTGRES_PASS=revault pytest -vvv -n8 --timeout=1800
```

### Tips and tricks
#### Logging
Expand Down

0 comments on commit 9b73b2f

Please sign in to comment.