diff --git a/production/rpi-docker/bch-dex-ui/Dockerfile b/production/rpi-docker/bch-dex-ui/Dockerfile new file mode 100644 index 0000000..694bae9 --- /dev/null +++ b/production/rpi-docker/bch-dex-ui/Dockerfile @@ -0,0 +1,73 @@ +# Create a Dockerized API server +# + +#IMAGE BUILD COMMANDS +# ct-base-ubuntu = ubuntu 18.04 + nodejs v10 LTS +#FROM christroutner/ct-base-ubuntu +FROM ubuntu:20.04 as builder +MAINTAINER Chris Troutner + +#Update the OS and install any OS packages needed. +RUN apt-get update +RUN apt-get install -y sudo git curl nano gnupg wget + +#Install Node and NPM +RUN curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh +RUN bash nodesource_setup.sh +RUN apt-get install -y nodejs build-essential + +#Create the user 'safeuser' and add them to the sudo group. +#RUN useradd -ms /bin/bash safeuser +#RUN adduser safeuser sudo + +#Set password to 'password' change value below if you want a different password +#RUN echo safeuser:password | chpasswd + +#Set the working directory to be the home directory +WORKDIR /home/safeuser + +#Setup NPM for non-root global install +#RUN mkdir /home/safeuser/.npm-global +#RUN chown -R safeuser .npm-global +#RUN echo "export PATH=~/.npm-global/bin:$PATH" >> /home/safeuser/.profile +#RUN runuser -l safeuser -c "npm config set prefix '~/.npm-global'" + +# Update to the latest version of npm. +#RUN npm install -g npm@7.23.0 +RUN npm install -g npm + +# npm mirror to prevent direct dependency on npm. +RUN npm set registry http://94.130.170.209:4873/ + +# Switch to user account. +#USER safeuser +# Prep 'sudo' commands. +#RUN echo 'abcd8765' | sudo -S pwd + +# Clone the rest.bitcoin.com repository +WORKDIR /home/safeuser +RUN git clone https://github.com/Permissionless-Software-Foundation/bch-dex-ui + +# Switch to the desired branch. `master` is usually stable, +# and `stage` has the most up-to-date changes. +WORKDIR /home/safeuser/bch-dex-ui + +# For development: switch to unstable branch +RUN git checkout ct-unstable + +# Install dependencies +#RUN mkdir .ipfsdata +#RUN npm install -g @mapbox/node-pre-gyp +RUN npm install + +# Build the site +RUN CI=true npm run build + +# Load the NGINX image. +FROM nginx +EXPOSE 80 + +# Copy the files built in the first container to the new NGINX container. +COPY --from=builder /home/safeuser/bch-dex-ui/public /usr/share/nginx/html + +#USER safeuser diff --git a/production/rpi-docker/bch-dex/Dockerfile b/production/rpi-docker/bch-dex/Dockerfile new file mode 100644 index 0000000..5e714a6 --- /dev/null +++ b/production/rpi-docker/bch-dex/Dockerfile @@ -0,0 +1,78 @@ +# Create a Dockerized API server +# + +#IMAGE BUILD COMMANDS +# ct-base-ubuntu = ubuntu 18.04 + nodejs v10 LTS +#FROM christroutner/ct-base-ubuntu +FROM ubuntu:20.04 +MAINTAINER Chris Troutner + +#Update the OS and install any OS packages needed. +RUN apt-get update +RUN apt-get install -y sudo git curl nano gnupg wget + +#Install Node and NPM +RUN curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh +RUN bash nodesource_setup.sh +RUN apt-get install -y nodejs build-essential + +#Create the user 'safeuser' and add them to the sudo group. +#RUN useradd -ms /bin/bash safeuser +#RUN adduser safeuser sudo + +#Set password to 'password' change value below if you want a different password +#RUN echo safeuser:password | chpasswd + +#Set the working directory to be the home directory +WORKDIR /home/safeuser + +#Setup NPM for non-root global install +#RUN mkdir /home/safeuser/.npm-global +#RUN chown -R safeuser .npm-global +#RUN echo "export PATH=~/.npm-global/bin:$PATH" >> /home/safeuser/.profile +#RUN runuser -l safeuser -c "npm config set prefix '~/.npm-global'" + +# Update to the latest version of npm. +#RUN npm install -g npm@7.23.0 +RUN npm install -g npm + +# npm mirror to prevent direct dependency on npm. +RUN npm set registry http://94.130.170.209:4873/ + +# Switch to user account. +#USER safeuser +# Prep 'sudo' commands. +#RUN echo 'abcd8765' | sudo -S pwd + +# Clone the rest.bitcoin.com repository +WORKDIR /home/safeuser +RUN git clone https://github.com/Permissionless-Software-Foundation/bch-dex + +# Switch to the desired branch. `master` is usually stable, +# and `stage` has the most up-to-date changes. +WORKDIR /home/safeuser/bch-dex + +# For development: switch to unstable branch +RUN git checkout ct-unstable + +# Install dependencies +#RUN mkdir .ipfsdata +#RUN npm install -g @mapbox/node-pre-gyp +RUN npm install + +# Generate the API docs +RUN npm run docs + +# Copy the wallet files +COPY wallet.json wallet.json + +#VOLUME /home/safeuser/keys + +# Expose the port the API will be served on. +#EXPOSE 5010 + +# Start the application. +COPY start-production.sh start-production.sh +CMD ["./start-production.sh"] + +#CMD ["npm", "start"] diff --git a/production/rpi-docker/bch-dex/start-production.sh b/production/rpi-docker/bch-dex/start-production.sh new file mode 100755 index 0000000..833e7ad --- /dev/null +++ b/production/rpi-docker/bch-dex/start-production.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# BEGIN: Optional configuration settings + +# The human readable name this IPFS node identifies as. +export COORD_NAME=bch-dex-generic + +# Allow this node to function as a circuit relay. It must not be behind a firewall. +#export ENABLE_CIRCUIT_RELAY=true +# For browsers to use your circuit realy, you must set up a domain, SSL certificate, +# and you must forward that subdomain to the IPFS_WS_PORT. +#export CR_DOMAIN=subdomain.yourdomain.com + +# Debug level. 0 = minimal info. 2 = max info. +export DEBUG_LEVEL=1 + +# END: Optional configuration settings + + +# Production database connection string. +export DBURL=mongodb://172.17.0.1:5666/bch-swap-service-prod + +# Configure REST API port +export PORT=5700 + +# bch-dex specific env vars +export BCH_ENV=production +export WEBHOOKSERVICE=http://172.17.0.1:5667/webhook +export WEBHOOKTARGET=http://172.17.0.1:5700/order +export APP_ID=bch-dex-test557 + +npm start diff --git a/production/rpi-docker/cleanup-images.sh b/production/rpi-docker/cleanup-images.sh new file mode 100755 index 0000000..405d9f5 --- /dev/null +++ b/production/rpi-docker/cleanup-images.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# Remove all untagged docker images. +docker rmi $(docker images | grep "^" | awk '{print $3}') + diff --git a/production/rpi-docker/docker-compose.yml b/production/rpi-docker/docker-compose.yml new file mode 100644 index 0000000..dade123 --- /dev/null +++ b/production/rpi-docker/docker-compose.yml @@ -0,0 +1,105 @@ +# Start the service with the command 'docker-compose up -d' + +version: '3.9' + +services: + mongo-p2wdb-service: + image: mongo:4.4 + container_name: mongo-p2wdb-service + ports: + - '5666:27017' # : + volumes: + - ../data/database:/data/db + command: mongod --logpath=/dev/null # -- quiet + restart: always + + ipfs: + #image: ipfs/go-ipfs:v0.12.0 + image: odanado/go-ipfs:v0.11.0 + container_name: ipfs + environment: + MY_ENV_VAR: 'placeholder' + logging: + driver: 'json-file' + options: + max-size: '10m' + max-file: '10' + mem_limit: 2000mb + ports: + - 4001:4001 + - 172.17.0.1:5001:5001 + - 172.17.0.1:8080:8080 + volumes: + - ../data/go-ipfs/data:/data/ipfs + - ../data/go-ipfs/export:/export + # https://docs.docker.com/compose/compose-file/compose-file-v3/#command + # https://github.com/ipfs/go-ipfs/blob/91c52657166bcf86f2476926e4fe56694dc26562/Dockerfile#L115 + command: + [ + 'daemon', + '--migrate=true', + '--agent-version-suffix=docker', + '--enable-pubsub-experiment' + ] + restart: always + + p2wdb: + build: + context: ./p2wdb/ + dockerfile: Dockerfile + container_name: p2wdb + logging: + driver: 'json-file' + options: + max-size: '10m' + max-file: '10' + mem_limit: 1gb + links: + - mongo-p2wdb-service + ports: + # : + - 5667:5667 # REST API + #- 5668:5668 # IPFS TCP port + #- 5669:5669 # IPFS WS Port + volumes: + - ../data/ipfsdata/p2wdb:/home/safeuser/ipfs-p2wdb-service/.ipfsdata/p2wdb + restart: always + + bch-dex: + build: + context: ./bch-dex/ + dockerfile: Dockerfile + container_name: bch-dex + logging: + driver: 'json-file' + options: + max-size: '10m' + max-file: '10' + mem_limit: 1000mb + links: + - mongo-p2wdb-service + - p2wdb + ports: + - '5700:5700' # : + # volumes: + # - ../data/ipfsdata:/home/safeuser/ipfs-service-provider/.ipfsdata + #restart: always + + dex-ui: + build: + context: ./bch-dex-ui/ + dockerfile: Dockerfile + container_name: dex-ui + logging: + driver: 'json-file' + options: + max-size: '10m' + max-file: '10' + mem_limit: 500mb + links: + - bch-dex + ports: + - '4500:80' # : + # volumes: + # - ../data/ipfsdata:/home/safeuser/ipfs-service-provider/.ipfsdata + #restart: always diff --git a/production/rpi-docker/p2wdb/Dockerfile b/production/rpi-docker/p2wdb/Dockerfile new file mode 100644 index 0000000..317fc42 --- /dev/null +++ b/production/rpi-docker/p2wdb/Dockerfile @@ -0,0 +1,71 @@ +# Create a Docker container for the P2WDB +# + +#IMAGE BUILD COMMANDS +FROM ubuntu:20.04 +MAINTAINER Chris Troutner + +#Update the OS and install any OS packages needed. +RUN apt-get update +RUN apt-get install -y sudo git curl nano gnupg wget + +#Install Node and NPM +RUN curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh +RUN bash nodesource_setup.sh +RUN apt-get install -y nodejs build-essential + +#Create the user 'safeuser' and add them to the sudo group. +RUN useradd -ms /bin/bash safeuser +RUN adduser safeuser sudo + +#Set password to 'abcd8765' change value below if you want a different password +RUN echo safeuser:abcd8765 | chpasswd + +#Set the working directory to be the users home directory +WORKDIR /home/safeuser + +#Setup NPM for non-root global install (like on a mac) +RUN mkdir /home/safeuser/.npm-global +RUN chown -R safeuser .npm-global +RUN echo "export PATH=~/.npm-global/bin:$PATH" >> /home/safeuser/.profile +RUN runuser -l safeuser -c "npm config set prefix '~/.npm-global'" + +# Update to the latest version of npm. +#RUN npm install -g npm@7.23.0 +RUN npm install -g npm + +# npm mirror to prevent direct dependency on npm. +RUN npm set registry http://94.130.170.209:4873/ + +# Switch to user account. +#USER safeuser +# Prep 'sudo' commands. +#RUN echo 'abcd8765' | sudo -S pwd + +# Clone the rest.bitcoin.com repository +RUN git clone https://github.com/Permissionless-Software-Foundation/ipfs-p2wdb-service +WORKDIR /home/safeuser/ipfs-p2wdb-service +RUN mkdir .ipfsdata +RUN git checkout ct-unstable + +#RUN npm install fsevents + +# Install dependencies +#RUN mkdir .ipfsdata +RUN npm install + +# Generate the API docs +RUN npm run docs + +# Expose the port the API will be served on. +#EXPOSE 5010 + +# Start the application. +COPY start-production.sh start-production.sh +CMD ["./start-production.sh"] + +#CMD ["npm", "start"] + +# Used for debugging +#COPY dummyapp.js dummyapp.js +#CMD ["node", "dummyapp.js"] diff --git a/production/rpi-docker/p2wdb/dummyapp.js b/production/rpi-docker/p2wdb/dummyapp.js new file mode 100644 index 0000000..8cd4613 --- /dev/null +++ b/production/rpi-docker/p2wdb/dummyapp.js @@ -0,0 +1,4 @@ +setInterval(function () { + const now = new Date() + console.log(`ping ${now.toLocaleString()}`) +}, 10000) diff --git a/production/rpi-docker/p2wdb/start-production.sh b/production/rpi-docker/p2wdb/start-production.sh new file mode 100755 index 0000000..3e80c54 --- /dev/null +++ b/production/rpi-docker/p2wdb/start-production.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +# BEGIN: Optional configuration settings + +# This mnemonic is used to set up persistent public key for e2ee +# Replace this with your own 12-word mnemonic. +export MNEMONIC="mass response fiscal world message exact series swallow forward confirm canoe festival" + +# The human readable name this IPFS node identifies as. +export COORD_NAME=generic-p2wdb-production + +# Allow this node to function as a circuit relay. It must not be behind a firewall. +#export ENABLE_CIRCUIT_RELAY=true +# For browsers to use your circuit realy, you must set up a domain, SSL certificate, +# and you must forward that subdomain to the IPFS_WS_PORT. +#export CR_DOMAIN=subdomain.yourdomain.com + +# Debug level. 0 = minimal info. 2 = max info. +export DEBUG_LEVEL=2 + +# Log-in information for retrieving a JWT token from FullStack.cash. +export FULLSTACKLOGIN=demo@demo.com +export FULLSTACKPASS=demo + +# END: Optional configuration settings + + +# Production database connection string. +export DBURL=mongodb://172.17.0.1:5666/p2wdb-service-dev + +# Configure IPFS ports +export IPFS_TCP_PORT=5668 +export IPFS_WS_PORT=5669 + +# Configure REST API port +export PORT=5667 + +export P2W_ENV=production +export IPFS_HOST=172.17.0.1 +export IPFS_API_PORT=5001 +export IPFS_TCP_PORT=4001 + +# P2WDB specific env vars +export ORBITDB_NAME=/orbitdb/zdpuAm4fPafpjs5mgbBUJV8Az7kd8Xj1ttD6M1JaAxF8RMRrw/psf-bch-p2wdb-keyvalue-v1.0.0-0004 + +npm start