From 1ca1194688960db7f46987f3dc3c17a545c63e78 Mon Sep 17 00:00:00 2001 From: Vivek Teega Date: Sat, 24 Apr 2021 15:20:27 +0530 Subject: [PATCH] Uploading edited files --- Dockerfile | 41 ++++++++++++++++++++ README.md | 1 + flocore-node.json | 32 ++++++++++++++++ http-proxy.conf | 14 +++++++ nginx.conf | 21 +++++++++++ start.sh | 96 +++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 205 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 flocore-node.json create mode 100644 http-proxy.conf create mode 100644 nginx.conf create mode 100644 start.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..185c50f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +FROM node:10-stretch-slim + +# Install Dependencies +RUN apt-get update && \ + apt-get install --no-install-recommends -y build-essential git libzmq3-dev python nginx curl && \ + rm -rf /var/lib/apt/lists/* +RUN apt-get update +RUN apt-get install ca-certificates -y +RUN update-ca-certificates + +# Install flosight +WORKDIR /flosight +ADD https://api.github.com/repos/oipwg/flocore-node/git/refs/heads/master flocore-node-version.json +RUN git clone https://github.com/ranchimall/flocore-node +ADD https://api.github.com/repos/oipwg/flosight-ui/git/refs/heads/master flosight-ui-version.json +ADD https://api.github.com/repos/oipwg/flosight-api/git/refs/heads/master flosight-api-version.json +RUN npm install ./flocore-node/ +RUN npm install flosight-ui flosight-api + +# Setup Nginx +RUN service nginx stop && rm /etc/nginx/nginx.conf +WORKDIR /etc/nginx +COPY nginx.conf . +RUN service nginx start + +WORKDIR /nginx +COPY http-proxy.conf . + +# Add flosight configs +WORKDIR /flosight +COPY start.sh . +COPY flocore-node.json . + +RUN mkdir /data +RUN chmod 755 /flosight/start.sh + +# Expose used ports +EXPOSE 80 443 3001 7312 7313 17312 17313 17413 41289 + +HEALTHCHECK CMD curl --fail http://localhost:3001/api/sync || exit 1 +CMD ["/flosight/start.sh"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..52cce59 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# Flosight Docker files diff --git a/flocore-node.json b/flocore-node.json new file mode 100644 index 0000000..ab4e348 --- /dev/null +++ b/flocore-node.json @@ -0,0 +1,32 @@ +{ + "version": "5.0.0-beta.44", + "network": "livenet", + "port": 3001, + "services": [ + "address", + "block", + "db", + "fee", + "header", + "mempool", + "p2p", + "timestamp", + "transaction", + "flosight-api", + "flosight-ui", + "web" + ], + "datadir": "/data", + "servicesConfig": { + "flosight-api": { + "disableRateLimiter": true, + "routePrefix": "api", + "cwdRequirePath": "node_modules/flosight-api" + }, + "flosight-ui": { + "routePrefix": "", + "apiPrefix": "api", + "cwdRequirePath": "node_modules/flosight-ui" + } + } +} diff --git a/http-proxy.conf b/http-proxy.conf new file mode 100644 index 0000000..f9a687f --- /dev/null +++ b/http-proxy.conf @@ -0,0 +1,14 @@ +server { + listen 80; + listen [::]:80; + + location / { + proxy_pass http://localhost:3001; + proxy_read_timeout 90; + proxy_connect_timeout 90; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Proxy ""; + } +} \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..dfed4dc --- /dev/null +++ b/nginx.conf @@ -0,0 +1,21 @@ +events { + worker_connections 768; +} + +http { + ## + # SSL Settings + ## + + ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE + ssl_prefer_server_ciphers on; + + ## + # Logging Settings + ## + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + include /data/nginx/*.conf; +} \ No newline at end of file diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..a2569ee --- /dev/null +++ b/start.sh @@ -0,0 +1,96 @@ +#!/bin/bash +cd /flosight + +# Use Env variables in Config +## Change Network Config if needed +echo "Setup configs..." +if [ "$NETWORK" == "testnet" ] +then + sed -i 's/livenet/testnet/g' flocore-node.json +fi +if [ "$NETWORK" == "regtest" ] +then + sed -i 's/livenet/regtest/g' flocore-node.json +fi +## Add Seednode config for fcoin if needed +if ! [ -z "$ADDNODE" ] +then + echo nodes="$ADDNODE" > /data/fcoin.conf +fi +## Add any custom config values +if [ ! -z "$CUSTOM_FCOIN_CONFIG" ] +then + echo -e "${CUSTOM_FCOIN_CONFIG}" >> /data/fcoin.conf +fi + +## Download the Blockchain Bootstrap if set +if [ ! -z "$BLOCKCHAIN_BOOTSTRAP" ] && [ "$(cat /data/bootstrap-url.txt)" != "$BLOCKCHAIN_BOOTSTRAP" ] +then + # download and extract a Blockchain boostrap + echo 'Downloading Blockchain Bootstrap...' + RUNTIME="$(date +%s)" + curl -L $BLOCKCHAIN_BOOTSTRAP -o /data/bootstrap.tar.gz --progress-bar | tee /dev/null + RUNTIME="$(($(date +%s)-RUNTIME))" + echo "Blockchain Bootstrap Download Complete (took ${RUNTIME} seconds)" + echo 'Extracting Bootstrap...' + RUNTIME="$(date +%s)" + tar -xzf /data/bootstrap.tar.gz -C /data + RUNTIME="$(($(date +%s)-RUNTIME))" + echo "Blockchain Bootstrap Extraction Complete! (took ${RUNTIME} seconds)" + rm -f /data/bootstrap.tar.gz + echo 'Erased Blockchain Bootstrap `.tar.gz` file' + echo "$BLOCKCHAIN_BOOTSTRAP" > /data/bootstrap-url.txt + ls /data +fi + +# Currently fcoin requires us to create these directories +echo "Pregenerate fcoin directories" +mkdir /data/blocks +mkdir /data/testnet +mkdir /data/testnet/blocks +mkdir /data/regtest +mkdir /data/regtest/blocks + +# Nginx http config +mkdir -p /data/nginx/ +cp /nginx/http-proxy.conf /data/nginx/http-proxy.conf + +echo "Config setup complete!" + +# Startup Nginx (since docker has it stopped at startup) +echo "Starting Nginx..." +service nginx start +echo "Nginx Started." + +# Initial Startup of Flosight +echo "Starting FLO Explorer $NETWORK" +./node_modules/flocore-node/bin/flocore-node start > /data/latest.log & +# Store PID for later +echo $! > /data/flosight.pid + +# Allow to startup +timeout 1m tail -n 100 -f /data/latest.log + +# Initialize block sync check file +curl --silent http://localhost:3001/api/status?q=getBestBlockHash > currentHealthCheck.log +echo 'different' > previousHealthCheck.log + +# Every 5 minutes +while true; do + # Check to see if the most recent block hash is the same as the last time we checked. + if [ "$(cat previousHealthCheck.log)" == "$(cat currentHealthCheck.log)" ] + then + # Restart instance + echo "NO NEW BLOCKS IN 5+ MINUTES - RESTARTING PROCESS" + kill -2 $(cat /data/flosight.pid) + wait $(cat /data/flosight.pid) + ./node_modules/flocore-node/bin/flocore-node start >> /data/latest.log & + # Store PID for later + echo $! > /data/flosight.pid + fi + # Wait 5 minutes before checking again + timeout 5m tail -f /data/latest.log + + mv currentHealthCheck.log previousHealthCheck.log + curl --silent http://localhost:3001/api/status?q=getBestBlockHash > currentHealthCheck.log +done; \ No newline at end of file