From 08e6ba2fe5ca6bc36823ddb4c41cab3e589cae5a Mon Sep 17 00:00:00 2001 From: c0llab0rat0r <78339685+c0llab0rat0r@users.noreply.github.com> Date: Tue, 18 May 2021 11:58:04 -0500 Subject: [PATCH] Script to start IPFS daemon with Docker --- README.md | 16 +++++---------- tools/ipfs/Dockerfile | 7 +++++++ tools/ipfs/README.md | 42 +++++++++++++++++++++++++++------------- tools/ipfs/configure.sh | 12 ------------ tools/ipfs/daemon.sh | 9 +++++++++ tools/ipfs/entrypoint.sh | 15 ++++++++++++++ tools/ipfs/run.sh | 5 ----- 7 files changed, 65 insertions(+), 41 deletions(-) create mode 100644 tools/ipfs/Dockerfile delete mode 100755 tools/ipfs/configure.sh create mode 100755 tools/ipfs/daemon.sh create mode 100755 tools/ipfs/entrypoint.sh delete mode 100755 tools/ipfs/run.sh diff --git a/README.md b/README.md index 0d720378..281816d5 100644 --- a/README.md +++ b/README.md @@ -208,9 +208,8 @@ You can submit bug reports using the ### Setting up a local development environment - 1. [Install and configure a local IPFS server](tools/ipfs/README.md): - 2. Follow the instructions in the (Python) tox documentation to install the `tox` Python environment runner: - https://tox.readthedocs.io/en/latest/install.html + 1. [Install tox](https://tox.readthedocs.io/en/latest/install.html) + 2. [Install a local IPFS server](tools/ipfs/README.md): 3. Clone the GIT repository if you haven't already: `git clone https://github.com/ipfs-shipyard/py-ipfs-http-client.git` @@ -236,19 +235,14 @@ make sure that your code passes both the As well as the tests: -1. Start IPFS server (do this once in a separate terminal): - - $ ./tools/ipfs/run.sh - -2. Execute unit and functional tests: - $ tox -e py3 -e py3-httpx If you are unsure, don't hesitate to just submit your code, and a human will take a look. 🙂 -If you can, Please make sure to include new unit tests for new features or -changes in behavior. We aim to bring coverage to 100% at some point. +Please make sure to include new unit tests for new features or +changes in behavior. + #### Installing the pre-commit Hook diff --git a/tools/ipfs/Dockerfile b/tools/ipfs/Dockerfile new file mode 100644 index 00000000..34b6ed42 --- /dev/null +++ b/tools/ipfs/Dockerfile @@ -0,0 +1,7 @@ +FROM ipfs/go-ipfs:v0.8.0 + +RUN sed -i 's/exec ipfs "$@"//' /usr/local/bin/start_ipfs +ADD entrypoint.sh / + +ENTRYPOINT ["/entrypoint.sh"] +CMD ["ipfs", "daemon", "--migrate=true", "--enable-namesys-pubsub"] diff --git a/tools/ipfs/README.md b/tools/ipfs/README.md index 9ddf6d61..f96d9cd4 100644 --- a/tools/ipfs/README.md +++ b/tools/ipfs/README.md @@ -1,27 +1,43 @@ -# Local IPFS Server +# Running Tests -`py-ipfs-httpclient` requires a live local server to run its -functional tests. +Tests are primarily run from the command line using a locally installed IPFS server. -## Installation +Alternatively, you can launch the IPFS daemon with Docker and run tests from your IDE. -To install it, follow the [official instructions](https://docs.ipfs.io/install/command-line/), -then finish with some [local configuration](configure.sh): - $ ./configure.sh +## Local IPFS Server Installation -The above script is run once after installing. +To install it, follow the [official instructions](https://docs.ipfs.io/install/command-line/). -## Running Tests +Remaining configuration is applied by [run_tests.py](../../test/run-tests.py) on each run. + + +## Running Tests Using Local Installation From Command Line + +* `tox -e py3` +* `tox -e py3-httpx` + + +## Running Tests Using Docker from IDE (e.g. PyCharm) + +1. Start [daemon.sh](daemon.sh) +2. Run `pytest` tests from your IDE as your normally would + +You can keep the Docker container running across multiple +executions of the functional test suite. + + +## Running Tests Without Live Server You can run unit tests without a live server; `pytest` will skip over the functional tests when our fixtures detect the server isn't running. -In a separate terminal, start IPFS with: - $ ./run.sh +## pytest-docker Plugin + +While `pytest-docker` supports running functional tests against a +Docker container using Docker Compose, it is not supported on +Windows or Mac with Travis and IPFS. -Stop it with Ctrl+C. You can keep it running across multiple -executions of the functional test suite. diff --git a/tools/ipfs/configure.sh b/tools/ipfs/configure.sh deleted file mode 100755 index 849976d8..00000000 --- a/tools/ipfs/configure.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -# Configures, but does not start, the IPFS daemon. Run once in your environment. -# -# Description of experimental features: -# https://github.com/ipfs/go-ipfs/blob/master/docs/experimental-features.md#ipfs-filestore - -set -e - -ipfs init -ipfs config --json Experimental.FilestoreEnabled true -ipfs config --json Experimental.UrlstoreEnabled true diff --git a/tools/ipfs/daemon.sh b/tools/ipfs/daemon.sh new file mode 100755 index 00000000..b05c2cf1 --- /dev/null +++ b/tools/ipfs/daemon.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -e + +tag=py-ipfs-http-client-daemon:latest + +docker build -t $tag . +docker run --rm -p 4001:4001 -p 5001:5001 -p 8080:8080 $tag + diff --git a/tools/ipfs/entrypoint.sh b/tools/ipfs/entrypoint.sh new file mode 100755 index 00000000..52caa3f4 --- /dev/null +++ b/tools/ipfs/entrypoint.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +set -e + +# Only does configuration; doesn't start the daemon +/usr/local/bin/start_ipfs + +echo "Enabling experimental features" + +ipfs config --json Experimental.FilestoreEnabled true + +echo "Enabled experimental features" + +# Start the daemon (unless other args provided) +exec "$@" diff --git a/tools/ipfs/run.sh b/tools/ipfs/run.sh deleted file mode 100755 index 4dc91c86..00000000 --- a/tools/ipfs/run.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -# Run the IPFS server. To stop it, press Ctrl+C. - -ipfs daemon --enable-namesys-pubsub