From ae888d094bd72696aa6c46d37874ceb0b92ad329 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Fri, 31 Dec 2021 15:34:40 -0800 Subject: [PATCH] fix(production): Adding instructions for customizing IPFS docker container --- package-lock.json | 14 +++--- package.json | 2 +- production/docker/README.md | 61 +++++++++++++++++++++++ production/docker/docker-compose.yml | 4 +- production/docker/start-production.sh | 9 ++-- shell-scripts/local-external-ipfs-node.sh | 6 ++- 6 files changed, 79 insertions(+), 17 deletions(-) create mode 100644 production/docker/README.md diff --git a/package-lock.json b/package-lock.json index 199355e..350c8ee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "bcryptjs": "2.4.3", "glob": "7.1.6", "ipfs": "0.60.0", - "ipfs-coord": "6.8.2", + "ipfs-coord": "6.8.3", "ipfs-http-client": "55.0.0", "jsonrpc-lite": "2.2.0", "jsonwebtoken": "8.5.1", @@ -9733,9 +9733,9 @@ } }, "node_modules/ipfs-coord": { - "version": "6.8.2", - "resolved": "http://94.130.170.209:4873/ipfs-coord/-/ipfs-coord-6.8.2.tgz", - "integrity": "sha512-si+qcjZxPY6Mju9/x+FYftM6TbeJh9r2ZKQEk+y6n1gfl7N1yq2KHLnWRFveiND15MZhBuztBstkC4zYqIJ3eg==", + "version": "6.8.3", + "resolved": "http://94.130.170.209:4873/ipfs-coord/-/ipfs-coord-6.8.3.tgz", + "integrity": "sha512-bN9/ChON4q0URqoucy6fuNyvjNfnshY3Nj15Z0sBZ5fOD7pBDtJ7mVjcNG4uNd70WMBdrgAYoj/5O9BAOSpnNg==", "license": "MIT", "dependencies": { "axios": "0.21.4", @@ -32897,9 +32897,9 @@ } }, "ipfs-coord": { - "version": "6.8.2", - "resolved": "http://94.130.170.209:4873/ipfs-coord/-/ipfs-coord-6.8.2.tgz", - "integrity": "sha512-si+qcjZxPY6Mju9/x+FYftM6TbeJh9r2ZKQEk+y6n1gfl7N1yq2KHLnWRFveiND15MZhBuztBstkC4zYqIJ3eg==", + "version": "6.8.3", + "resolved": "http://94.130.170.209:4873/ipfs-coord/-/ipfs-coord-6.8.3.tgz", + "integrity": "sha512-bN9/ChON4q0URqoucy6fuNyvjNfnshY3Nj15Z0sBZ5fOD7pBDtJ7mVjcNG4uNd70WMBdrgAYoj/5O9BAOSpnNg==", "requires": { "axios": "0.21.4", "bch-encrypt-lib": "2.0.0", diff --git a/package.json b/package.json index 36cc12b..4164957 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "bcryptjs": "2.4.3", "glob": "7.1.6", "ipfs": "0.60.0", - "ipfs-coord": "6.8.2", + "ipfs-coord": "6.8.3", "ipfs-http-client": "55.0.0", "jsonrpc-lite": "2.2.0", "jsonwebtoken": "8.5.1", diff --git a/production/docker/README.md b/production/docker/README.md new file mode 100644 index 0000000..fc6d9f8 --- /dev/null +++ b/production/docker/README.md @@ -0,0 +1,61 @@ +# Docker Containers + +The 'production' environment is assumed to be a set of Docker containers orchestrated with Docker Compose. The files in this directory will stand up three Docker containers: + +1 An instance of go-ipfs. +2 An instance of MongoDB. +3 The JavaScript software in this repository. + +The software in this repository depends on the first two containers, so if they aren't running correctly, the application won't run correctly either. + +## IPFS + +IPFS can be a little tricky to set up. By default, the container uses the following ports: + +- 4001 for TCP connections, exposed publicly. +- 5001 for control by the application, exposed privately. +- 8080 for an IPFS gateway, consumed by the application, exposed privately. + +If you already have an IPFS node running on a the computer, you will need to change the ports to avaid a conflict. To change the ports from the default, you'll need to perform a series of steps, and the order of the steps matter. + +1. Edit the `docker-compose.yml` file and change the ports. Then save the file. Here is an example: + +``` +ports: + - 4101:4101 + - 172.17.0.1:5101:5101 + - 172.17.0.1:8180:8180 +``` + +2. Bring the Docker containers up, and then back down. This will allow the IPFS container to create the config file that you'll need to edit. + +- `docker-compose up -d` +- Wait a few seconds. +- `docker-compose down` + +3. Update the generated config file at `../data/go-ipfs/data/config`, to update the ports in the config file, like this: + +``` +"Addresses": { + "API": "/ip4/0.0.0.0/tcp/5101", + "Announce": [], + "AppendAnnounce": [], + "Gateway": "/ip4/0.0.0.0/tcp/8180", + "NoAnnounce": [], + "Swarm": [ + "/ip4/0.0.0.0/tcp/4101", + "/ip6/::/tcp/4101", + "/ip4/0.0.0.0/udp/4101/quic", + "/ip6/::/udp/4101/quic" + ] + }, + +``` + +4. Update the port changes in the `start-production.sh` shell script. This tells the application which ports to use, in order to control the IPFS node, are are used when signaling other nodes. + +5. Quickly rebuild the containers, to add the modified `start-production.sh` shell script to the application Docker container: + +- `docker-compose build` + +6. Now start the containers, and the port changes to IPFS should be complete. diff --git a/production/docker/docker-compose.yml b/production/docker/docker-compose.yml index 5e2cc9f..328bb82 100644 --- a/production/docker/docker-compose.yml +++ b/production/docker/docker-compose.yml @@ -26,8 +26,8 @@ services: mem_limit: 2000mb ports: - 4001:4001 - - 5001:5001 - - 8080:8080 + - 172.17.0.1:5001:5001 + - 172.17.0.1:8080:8080 volumes: - ../data/go-ipfs/data:/data/ipfs - ../data/go-ipfs/export:/export diff --git a/production/docker/start-production.sh b/production/docker/start-production.sh index 92810a6..2e8bde6 100755 --- a/production/docker/start-production.sh +++ b/production/docker/start-production.sh @@ -17,7 +17,7 @@ export COORD_NAME=ipfs-service-provider-generic #export CR_DOMAIN=subdomain.yourdomain.com # Debug level. 0 = minimal info. 2 = max info. -export DEBUG_LEVEL=1 +export DEBUG_LEVEL=2 # END: Optional configuration settings @@ -25,11 +25,6 @@ export DEBUG_LEVEL=1 # Production database connection string. export DBURL=mongodb://172.17.0.1:5555/ipfs-service-prod -# Configure IPFS ports -#export IPFS_TCP_PORT=5268 -#export IPFS_WS_PORT=5269 - - # Configure REST API port export PORT=5010 @@ -37,5 +32,7 @@ export PORT=5010 export SVC_ENV=production export IPFS_HOST=172.17.0.1 export IPFS_API_PORT=5001 +export IPFS_TCP_PORT=4001 +#export IPFS_WS_PORT=5269 npm start diff --git a/shell-scripts/local-external-ipfs-node.sh b/shell-scripts/local-external-ipfs-node.sh index a81d112..5cd0171 100755 --- a/shell-scripts/local-external-ipfs-node.sh +++ b/shell-scripts/local-external-ipfs-node.sh @@ -13,7 +13,7 @@ export COORD_NAME=ipfs-service-provider-generic export MNEMONIC="churn aisle shield silver ladder swear hunt slim pen demand spoil veteran" # 0 = less verbose. 3 = most verbose -export DEBUG_LEVEL=1 +export DEBUG_LEVEL=2 # Production settings that use external IPFS node. # https://github.com/christroutner/docker-ipfs @@ -21,6 +21,10 @@ export SVC_ENV=production export IPFS_HOST=localhost export IPFS_API_PORT=5001 +# Configure IPFS ports +export IPFS_TCP_PORT=4001 +#export IPFS_WS_PORT=5269 + # MongoDB connection string. export DBURL=mongodb://localhost:27017/ipfs-service-dev