Browse Source

Init Dockerization

develop
Apostolos Fanakis 5 years ago
parent
commit
f3e6700458
  1. 5
      .dockerignore
  2. 3
      .gitignore
  3. 51
      Dockerfile
  4. 10
      Makefile
  5. 4
      app/package.json
  6. 2
      app/src/config/ipfsOptions.js
  7. 92
      docker-compose.yml
  8. 19
      env/apella.env.example
  9. 5
      ganache/Dockerfile
  10. 13
      ganache/docker-compose.yml
  11. 9
      migrateAndStart.sh
  12. 4
      rendezvous/Dockerfile
  13. 9
      rendezvous/docker-compose.yml
  14. 4
      truffle-config.js

5
.dockerignore

@ -0,0 +1,5 @@
env/
node_modules/
package-lock.json
app/node_modules/
app/package-lock.json

3
.gitignore

@ -34,3 +34,6 @@ yarn-error.log*
# Jetbrains # Jetbrains
.idea .idea
/env/*.env
/volumes

51
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"]

10
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"`

4
app/package.json

@ -38,8 +38,8 @@
"libp2p-websocket-star-rendezvous": "0.3.0" "libp2p-websocket-star-rendezvous": "0.3.0"
}, },
"scripts": { "scripts": {
"start": "react-scripts start", "start": "HOST=${APELLA_HOST} react-scripts start",
"rendezvous": "rendezvous --port=9090 --host=127.0.0.1", "rendezvous": "rendezvous --port=9090 --host=83.212.109.171",
"build": "react-scripts build", "build": "react-scripts build",
"test": "react-scripts test", "test": "react-scripts test",
"eject": "react-scripts eject" "eject": "react-scripts eject"

2
app/src/config/ipfsOptions.js

@ -10,7 +10,7 @@ const ipfsOptions = {
'/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star', '/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star',
// Use local signaling server (see also rendezvous script in package.json) // Use local signaling server (see also rendezvous script in package.json)
// For more information: https://github.com/libp2p/js-libp2p-websocket-star-rendezvous // 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',
] ]
} }
}, },

92
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

19
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

5
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"]

13
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

9
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

4
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"

9
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"

4
truffle-config.js

@ -6,8 +6,8 @@ module.exports = {
contracts_build_directory: path.join(__dirname, 'app/src/contracts'), contracts_build_directory: path.join(__dirname, 'app/src/contracts'),
networks: { networks: {
development: { development: {
host: 'localhost', host: process.env.GANACHE_HOST,
port: 8545, port: process.env.GANACHE_PORT,
network_id: '*' // Match any network id network_id: '*' // Match any network id
} }
}, },

Loading…
Cancel
Save