From f3e6700458d9cb825e8d6b97e56eb80e4b96b445 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Mon, 28 Oct 2019 22:48:02 +0200 Subject: [PATCH] Init Dockerization --- .dockerignore | 5 ++ .gitignore | 3 ++ Dockerfile | 51 +++++++++++++++++++ Makefile | 10 ++++ app/package.json | 4 +- app/src/config/ipfsOptions.js | 2 +- docker-compose.yml | 92 +++++++++++++++++++++++++++++++++++ env/apella.env.example | 19 ++++++++ ganache/Dockerfile | 5 ++ ganache/docker-compose.yml | 13 +++++ migrateAndStart.sh | 9 ++++ rendezvous/Dockerfile | 4 ++ rendezvous/docker-compose.yml | 9 ++++ truffle-config.js | 4 +- 14 files changed, 225 insertions(+), 5 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 docker-compose.yml create mode 100644 env/apella.env.example create mode 100644 ganache/Dockerfile create mode 100644 ganache/docker-compose.yml create mode 100644 migrateAndStart.sh create mode 100644 rendezvous/Dockerfile create mode 100644 rendezvous/docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2fef4f0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +env/ +node_modules/ +package-lock.json +app/node_modules/ +app/package-lock.json diff --git a/.gitignore b/.gitignore index 80d0c3b..7f78998 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,6 @@ yarn-error.log* # Jetbrains .idea + +/env/*.env +/volumes \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3cdfb50 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,51 @@ +# ----- Base image ----- +FROM tarampampam/node:11-alpine as base +LABEL maintainer="apotwohd@gmail.com" + +ENV DOCKER true + +# Installs a couple (dozen) more tools like python, c++, make and others +RUN apk --no-cache add build-base + +# Installs a couple (dozen) more tools like python, c++, make and others +RUN apk --no-cache add build-base \ + python3 && \ + if [ ! -e /usr/bin/python ]; then ln -sf python3 /usr/bin/python ; fi + +# Installs truffle +RUN yarn global add truffle + +WORKDIR /usr/apella + +COPY ./package.json ./ +COPY ./app/package.json ./app/ + +# ----- Dependencies ----- +FROM base as dependencies + +# Installs node packages from ./package.json +RUN yarn install + +# Installs node packages from ./app/package.json +RUN cd app/ && yarn install + +# ----- Test ----- +#FROM dependencies AS test + +# Preps directories +#COPY . . +# Runs linters and tests +#RUN npm run lint && npm run test + +# ----- Runtime ----- +FROM base as runtime + +# Copies node_modules +COPY --from=dependencies /usr/apella/node_modules ./node_modules +COPY --from=dependencies /usr/apella/app/node_modules ./app/node_modules + +# Preps directories +COPY . . + +RUN ["chmod", "+x", "/usr/apella/migrateAndStart.sh"] +ENTRYPOINT ["/usr/apella/migrateAndStart.sh"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..900c9f5 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +build: + @docker-compose -p apella build; +run: + @docker-compose -p apella up -d +stop: + @docker-compose -p apella down +clean-data: + @docker-compose -p apella down -v +clean-images: + @docker rmi `docker images -q -f "dangling=true"` diff --git a/app/package.json b/app/package.json index fbad6b6..519fab4 100644 --- a/app/package.json +++ b/app/package.json @@ -38,8 +38,8 @@ "libp2p-websocket-star-rendezvous": "0.3.0" }, "scripts": { - "start": "react-scripts start", - "rendezvous": "rendezvous --port=9090 --host=127.0.0.1", + "start": "HOST=${APELLA_HOST} react-scripts start", + "rendezvous": "rendezvous --port=9090 --host=83.212.109.171", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" diff --git a/app/src/config/ipfsOptions.js b/app/src/config/ipfsOptions.js index e5c1d9f..b06c95e 100644 --- a/app/src/config/ipfsOptions.js +++ b/app/src/config/ipfsOptions.js @@ -10,7 +10,7 @@ const ipfsOptions = { '/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star', // Use local signaling server (see also rendezvous script in package.json) // For more information: https://github.com/libp2p/js-libp2p-websocket-star-rendezvous - '/ip4/127.0.0.1/tcp/9090/ws/p2p-websocket-star' + '/dns4/' + process.env.REACT_APP_RENDEZVOUS_HOST + '/tcp/' + process.env.REACT_APP_RENDEZVOUS_PORT + '/ws/p2p-websocket-star', ] } }, diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d6cc9d9 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,92 @@ +version: '3.7' + +services: + ganache: + build: ./ganache + container_name: ganache + restart: always + ports: + - "8545:8545" + user: root + volumes: + - ./volumes/ganache_db:/home/ganache_db + - ./volumes/ganache_keys:/home/ganache_keys + + # Simple rendezvous server image + # Reference: + # https://hub.docker.com/r/libp2p/websocket-star-rendezvous + rendezvous: + image: libp2p/websocket-star-rendezvous:release + container_name: rendezvous + restart: always + ports: + - "9090:9090" + + apella: + build: ./ + container_name: apella-app + restart: always + env_file: + - ./env/apella.env + networks: + - apella-net + volumes: + - ./volumes/node_modules:/usr/apella/node_modules + expose: + - "3000" + + # Nginx reverse proxy container + # Reference: + # https://github.com/jwilder/nginx-proxy + nginx-proxy: # TODO: maybe split this to the two underlying images? + image: jwilder/nginx-proxy + container_name: apella-nginx-proxy + restart: always + environment: + - DEFAULT_HOST=apella.tk + labels: + com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy: "true" + logging: + options: + max-size: '4m' + max-file: '10' + networks: + - apella-net + ports: + - "80:80" + - "443:443" + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + - ./volumes/nginx/conf:/etc/nginx/conf.d + - ./volumes/nginx/vhost:/etc/nginx/vhost.d + - ./volumes/nginx/html:/usr/share/nginx/html + - ./volumes/nginx/dhparam:/etc/nginx/dhparam + - ./volumes/nginx/certs:/etc/nginx/certs:ro + + # Letsencrypt automated creation, renewal and use of Let's Encrypt certificates + # Reference: + # https://github.com/JrCs/docker-letsencrypt-nginx-proxy-companion + letsencrypt: + image: jrcs/letsencrypt-nginx-proxy-companion + container_name: apella-proxy-le + restart: always + depends_on: + - nginx-proxy + logging: + options: + max-size: '4m' + max-file: '10' + networks: + - apella-net + volumes: + - ./volumes/nginx/conf:/etc/nginx/conf.d + - ./volumes/nginx/vhost:/etc/nginx/vhost.d + - ./volumes/nginx/html:/usr/share/nginx/html + - ./volumes/nginx/dhparam:/etc/nginx/dhparam + - ./volumes/nginx/certs:/etc/nginx/certs:rw + - /var/run/docker.sock:/var/run/docker.sock:ro + +# Networks in use +networks: + apella-net: + driver: bridge diff --git a/env/apella.env.example b/env/apella.env.example new file mode 100644 index 0000000..56f1372 --- /dev/null +++ b/env/apella.env.example @@ -0,0 +1,19 @@ +# Docker compose variables +VIRTUAL_HOST=apella.tk +VIRTUAL_PORT=3000 + +# If you uncomment the lines below, Apella will become available through https BUT the rendezvous +# server will stop working and IPFS initialization won't complete +#LETSENCRYPT_HOST=apella.tk +#LETSENCRYPT_EMAIL=apotwohd@gmail.com + +# Variables needed in build time +# to_never_do: change bellow to localhost +APELLA_HOST=0.0.0.0 +APELLA_PORT=3000 +GANACHE_HOST=79.103.177.105 +GANACHE_PORT=8545 + +# Variables needed in runtime (in browser) +REACT_APP_RENDEZVOUS_HOST=83.212.109.171 +REACT_APP_RENDEZVOUS_PORT=9090 diff --git a/ganache/Dockerfile b/ganache/Dockerfile new file mode 100644 index 0000000..af566eb --- /dev/null +++ b/ganache/Dockerfile @@ -0,0 +1,5 @@ +FROM trufflesuite/ganache-cli:latest + +RUN mkdir /home/ganache_db /home/ganache_keys + +ENTRYPOINT ["node", "/app/ganache-core.docker.cli.js", "-a", "10", "-e", "1000", "-d", "-m", "measure tree magic expire dad extend famous offer slight glory inherit weekend", "-p", "8545", "-i", "5778", "--db", "/home/ganache_db/", "-v", "--account_keys_path", "/home/ganache_keys/keys", "--allowUnlimitedContractSize", "--noVMErrorsOnRPCResponse"] \ No newline at end of file diff --git a/ganache/docker-compose.yml b/ganache/docker-compose.yml new file mode 100644 index 0000000..3db9052 --- /dev/null +++ b/ganache/docker-compose.yml @@ -0,0 +1,13 @@ +version: '3.7' + +services: + ganache: + build: ./ + container_name: ganache + restart: always + ports: + - "8545:8545" + user: root + volumes: + - ./volumes/ganache_db:/home/ganache_db + - ./volumes/ganache_keys:/home/ganache_keys diff --git a/migrateAndStart.sh b/migrateAndStart.sh new file mode 100644 index 0000000..a3a64db --- /dev/null +++ b/migrateAndStart.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# Migrates contracts +rm -f /usr/apella/app/src/contracts/* +cd /usr/apella/ +truffle migrate + +cd /usr/apella/app/ +yarn start \ No newline at end of file diff --git a/rendezvous/Dockerfile b/rendezvous/Dockerfile new file mode 100644 index 0000000..bed3e8a --- /dev/null +++ b/rendezvous/Dockerfile @@ -0,0 +1,4 @@ +FROM libp2p/websocket-star-rendezvous:release + +# Can't use the array form of ENTRYPOINT here because we use env vars +ENTRYPOINT /usr/local/bin/dumb-init node --max-old-space-size=8192 src/bin.js --port="$RENDEZVOUS_PORT" diff --git a/rendezvous/docker-compose.yml b/rendezvous/docker-compose.yml new file mode 100644 index 0000000..ca3d3b3 --- /dev/null +++ b/rendezvous/docker-compose.yml @@ -0,0 +1,9 @@ +version: '3.7' + +services: + rendezvous: + image: libp2p/websocket-star-rendezvous:release + container_name: rendezvous + restart: always + ports: + - "9090:9090" diff --git a/truffle-config.js b/truffle-config.js index 9b49594..054efbe 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -6,8 +6,8 @@ module.exports = { contracts_build_directory: path.join(__dirname, 'app/src/contracts'), networks: { development: { - host: 'localhost', - port: 8545, + host: process.env.GANACHE_HOST, + port: process.env.GANACHE_PORT, network_id: '*' // Match any network id } },