Commit f976b0a0 authored by TonyFord's avatar TonyFord
Browse files

Merge branch 'faircoin.co/explorer.faircoin.co-master'

parents aec774bd b7a53f3b
*.pyc
*.pid
*.log
services/explorer/cce.conf
services/explorer/server.conf
services/faircoin/scripts/*.conf
stages:
- build
- init
- start
- status
- stop
- uninstall
- remove
......@@ -13,23 +15,26 @@ build-explorer:
refs:
- master
variables:
- $CMD =~ /build/
- $CMD =~ /build|^install/
before_script:
- export RUNNER_UID=`id -u`
- export RUNNER_GID=`id -g`
- cat ${CCE_CONF} | sed -e s/MYSQL_USER/${MYSQL_USER}/g -e s/MYSQL_PASSWORD/${MYSQL_PASSWORD}/g -e s/MYSQL_DATABASE_PORT/${MYSQL_DATABASE_PORT}/g > ./cce.conf
- export LH_PORT=${LH_PORT_explorer} && curl https://git.fairkom.net/faircoin.co/admin/-/raw/master/nginx_proxy | sed -e s/DOMAIN/${CI_PROJECT_NAME}/g -e s/LH_PORT/${LH_PORT}/g > ${CI_PROJECT_NAME}
- chmod +x setenv && . setenv
script:
- docker-compose stop
- docker-compose down -v
- docker-compose build app
- docker-compose up -d db
- sleep 20
- chmod +x create_db.sh
- docker-compose exec -T db /opt/explorer.kaana.red/create_db.sh
- docker-compose up -d app
- docker-compose exec -T app python3 dbload.py -n -l
timeout: 6h
- deploy/build
init-explorer:
stage: init
tags:
- FairCoin.Co
only:
refs:
- master
variables:
- $CMD =~ /init|^install/
before_script:
- chmod +x setenv && . setenv
script:
- deploy/init
timeout: 10h
start-explorer:
stage: start
......@@ -39,17 +44,11 @@ start-explorer:
refs:
- master
variables:
- $CMD =~ /build|start/
- $CMD =~ /start|^install/
before_script:
- export RUNNER_UID=`id -u`
- export RUNNER_GID=`id -g`
- cat ${CCE_CONF} | sed -e s/MYSQL_USER/${MYSQL_USER}/g -e s/MYSQL_PASSWORD/${MYSQL_PASSWORD}/g -e s/MYSQL_DATABASE_PORT/${MYSQL_DATABASE_PORT}/g > ./cce.conf
- export LH_PORT=${LH_PORT_explorer} && curl https://git.fairkom.net/faircoin.co/admin/-/raw/master/nginx_proxy | sed -e s/DOMAIN/${CI_PROJECT_NAME}/g -e s/LH_PORT/${LH_PORT}/g > ${CI_PROJECT_NAME}
- cat ${SERVER_CONF} | sed -e s/LH_PORT_explorer/${LH_PORT_explorer}/g > ./server.conf
- chmod +x setenv && . setenv
script:
- docker-compose stop
- docker-compose up -d
- docker-compose exec -T app python3 websrv.py
- deploy/start
stop-explorer:
stage: stop
......@@ -60,8 +59,10 @@ stop-explorer:
- master
variables:
- $CMD =~ /stop/
before_script:
- chmod +x setenv && . setenv
script:
- docker-compose stop
- deploy/stop
uninstall-explorer:
stage: uninstall
......@@ -72,6 +73,35 @@ uninstall-explorer:
- master
variables:
- $CMD =~ /uninstall/
before_script:
- chmod +x setenv && . setenv
script:
- deploy/uninstall
remove-explorer:
stage: remove
tags:
- FairCoin.Co
only:
refs:
- master
variables:
- $CMD =~ /remove/
before_script:
- chmod +x setenv && . setenv
script:
- deploy/remove
status-explorer:
stage: status
tags:
- FairCoin.Co
only:
refs:
- master
variables:
- $CMD =~ /status/
before_script:
- chmod +x ./setenv && . setenv
script:
- docker-compose stop
- docker-compose down -v
- console/status
......@@ -4,44 +4,70 @@ The service is made for/controlled by gitlab runner.
## Usage
Go into gitlab **CI/CD** -> **Pipeline** and **Run Pipeline**
### by Gitlab-Runner
Enter variable name **CMD**
1. Fork this project to your group/repositories where you have set up a gitlab-runner
1. change the gitlab-runner tags in .gitlab-ci.yml
1. add env files ( select Type = file ! ) to override defaults ./env_file , go to Gitlab **Settings** -> **CI/CD** -> **Variables**
You can read a full developer report of server preparation with gitlab-runner usage > [DEV_REPORT.md](DEV_REPORT.md)
~~~
#### env files ( examples see env_file/... / select Type = file !) ######################
CCE_CONF # config dbload.py
SERVER_CONF # config websrv.py
FAIRCHAINS_CONF # conf file to run the faircoind or fairchains daemon
#### CMD - commands
#### env vars ###########################################################################
MYSQL_USER # mysql user ( used to run the explorer )
MYSQL_PASSWORD # mysql user password
MYSQL_DATABASE_PORT # mysql database port ( default 3306 )
MYSQL_ROOT_PASSWORD # mysql root user password ( used to admin the database )
LH_PORT_explorer # port running explorer by localhost ( default 8222 / use nginx proxy to make it available by remote )
~~~
1. run command, go to Gitlab **CI/CD** -> **Pipeline** and **Run Pipeline**
Enter variable name **CMD**
~~~
build # build container ( changes of Dockerfile )
init # remove blockchain data and initialize sql database and faircoin/fairchains.conf
start # start container ( changes of scripts )
stop # stop container
uninstall # remove container
install # runs build, init, start stages
uninstall # remove container without to delete the data
remove # remove all data
~~~
#### CI/CD Settings
Go Gitlab **Settings** -> **CI/CD** -> **Variables**
### by SSH access <small>( manually without gitlab-runner )</small>
1. install docker and docker-compose ( https://docs.docker.com/compose/install/ )
1. clone this project
1. change configuration in ./env_file
1. Initialize env vars
~~~
#### group variables ######################
CCE_CONF # config dbload.py
SERVER_CONF # config websrv.py
chmod +x setenv
. setenv
~~~
## Development <small>( manual usage )</small>
1. run command from project root folder
~~~
deploy/build
deploy/init
deploy/start
deploy/stop
deploy/install
deploy/uninstall
deploy/remove
~~~
If you want create an instance manual then follow the instructions.
1. install docker and docker-compose ( https://docs.docker.com/compose/install/ )
1. clone this project
1. change configuration in ./env
1. run services by ./control.sh
#### Troubleshooting
some commands can be helpful getting shell access to container or get some status info
~~~
chmod +x ./control.sh
./control.sh build
./control.sh start
./control.sh stop
./control.sh uninstall
sudo ./control.sh nginx-install
sudo ./control.sh nginx-uninstall
console/explorer # get access to container of explorer server app
console/db # get access to container of mysql database
console/faircoin # get access to container of faircoind
console/ps # list containers status info
console/status # list all ports / processes and faircoind info
~~~
#!/bin/bash
docker-compose exec db bash
#!/bin/bash
docker-compose exec explorer bash
#!/bin/bash
docker-compose exec faircoin bash
#!/bin/bash
echo ""
echo -e "console/explorer\t\t( run container shell )"
echo -e "console/db \t( run container shell )"
echo -e "console/faircoin \t\t( run container shell )"
echo -e "console/help"
echo -e "console/ps \t\t\t( list containers )"
echo -e "console/status \t\t\t( network / processes / ... status overview )"
echo ""
#!/bin/bash
docker-compose ps
#!/bin/bash
echo ""
echo "NETWORK"
echo "======================================================================="
echo "container:faircoin"
echo ""
docker-compose exec -T faircoin netstat -tulpen
echo ""
echo "_______________________________________________________________________"
echo "container:explorer"
echo ""
docker-compose exec -T explorer netstat -tulpen
echo ""
echo "_______________________________________________________________________"
echo "container:db"
echo ""
docker-compose exec -T db netstat -tulpen
echo ""
echo ""
echo ""
echo "PROCESSES"
echo "======================================================================="
echo "container:faircoin"
echo ""
docker-compose exec -T faircoin ps aux
echo ""
echo "_______________________________________________________________________"
echo "container:explorer"
echo ""
docker-compose exec -T explorer ps aux
echo ""
echo "_______________________________________________________________________"
echo "container:db"
echo ""
docker-compose exec -T db ps aux
echo ""
echo ""
echo ""
echo "FAIRCOIND"
echo "======================================================================="
echo "container:faircoin"
echo ""
docker-compose exec -T faircoin ./faircoin-cli getinfo
#!/bin/bash
export RUNNER_UID=`id -u`
export RUNNER_GID=`id -g`
if [ -d ../${CI_PROJECT_NAME}.tmp ]; then
export `cat ./${CI_PROJECT_NAME}.tmp/*`
else
export `cat ./env/*`
fi
case $1 in
"exec")
docker-compose exec $2 $3
;;
"ps")
docker-compose ps
;;
"build")
chmod +x create_db.sh
cat ${CCE_CONF} > ./cce.conf
docker-compose down
docker-compose build
;;
"start")
cat ${CCE_CONF} > ./cce.conf
cat ${SERVER_CONF} > ./server.conf
docker-compose stop
docker-compose up -d
docker-compose exec -T app python3 websrv.py
;;
"stop")
docker-compose stop $2
;;
"uninstall")
docker-compose stop
docker-compose down
;;
"nginx-install")
cp ${CI_PROJECT_NAME} > /etc/nginx/sites-available/
certbot certonly --nginx --domain ${CI_PROJECT_NAME}
ln -s /etc/nginx/sites-available/${CI_PROJECT_NAME} /etc/nginx/sites-enabled/
nginx -s reload
;;
"nginx-uninstall")
rm /etc/nginx/sites-enabled/${CI_PROJECT_NAME}
nginx -s reload
;;
esac
#!/bin/bash
cat ${CCE_CONF} | sed -e s/MYSQL_USER/${MYSQL_USER}/g -e s/MYSQL_PASSWORD/${MYSQL_PASSWORD}/g > ./services/explorer/cce.conf
docker-compose stop
docker-compose down
chmod +x ./services/faircoin/entrypoint.sh
chmod +x ./services/explorer/entrypoint.sh
chmod +x ./services/db/create_db.sh
docker-compose build
#!/bin/bash
echo ""
echo -e "deploy/build \t\t( build container images )"
echo -e "deploy/start \t\t( start container )"
echo -e "deploy/stop \t\t( stop container )"
echo -e "deploy/install \t( run steps build + start + new_ssl )"
echo -e "deploy/uninstall \t( stop and remove container, named volumes will NOT removed )"
echo -e "deploy/remove \t\t( stop and remove container and images, named volumes WILL REMOVED )"
echo ""
#!/bin/bash
# remove containers and volumes
docker-compose down -v
# initialize database
chmod +x ./services/db/create_db.sh
docker-compose up -d db
sleep 20
docker-compose exec -T db /opt/explorer/create_db.sh
# create config files and move to correct place
cat ${FAIRCHAINS_CONF} > ./services/faircoin/scripts/fairchains.conf
cat ${FAIRCHAINS_CONF} | sed -e s/netname/\#\ netname/g > ./services/faircoin/scripts/faircoin.conf
export AUTOSTART=0
docker-compose up -d faircoin
docker-compose exec -T faircoin mv -f ./scripts/fairchains.conf .faircoin2/
docker-compose exec -T faircoin mv -f ./scripts/faircoin.conf .faircoin2/
docker-compose exec -T faircoin ./faircoind -disablewallet -daemon
sleep 180
# wait until blockchain is up-to-date
last=-1
new=0
while [ $new != $last ]
do
last=$new
echo $last
echo "wait.."
sleep 60
new=`docker-compose exec -T faircoin ./faircoin-cli getblockcount`
done
# start explorer service
cat ${CCE_CONF} | sed -e s/MYSQL_USER/${MYSQL_USER}/g -e s/MYSQL_PASSWORD/${MYSQL_PASSWORD}/g > ./services/explorer/cce.conf
cat ${SERVER_CONF} > ./services/explorer/server.conf
docker-compose up -d explorer
sleep 20
# first time run of db initialization
docker-compose exec -T explorer python3 dbload.py -n -l
#!/bin/bash
deploy/build
deploy/init
deploy/start
#!/bin/bash
docker-compose stop
docker-compose down -v --rmi all --remove-orphans
#!/bin/bash
cat ${CCE_CONF} | sed -e s/MYSQL_USER/${MYSQL_USER}/g -e s/MYSQL_PASSWORD/${MYSQL_PASSWORD}/g > ./services/explorer/cce.conf
cat ${SERVER_CONF} > ./services/explorer/server.conf
docker-compose stop
docker-compose up -d --remove-orphans
# docker-compose exec -T --workdir /home/faircoin/explorer/scripts explorer python3 websrv.py
#!/bin/bash
docker-compose stop
#!/bin/bash
docker-compose stop
docker-compose down
......@@ -2,27 +2,33 @@ version: '3.3'
services:
app:
explorer:
restart: always
build:
context: ./
context: services/explorer
args:
RUNNER_UID: ${RUNNER_UID:-1000}
RUNNER_GID: ${RUNNER_GID:-1000}
environment:
AUTOSTART: ${AUTOSTART:-1}
env_file:
- ${FAIRCOIN_CONF}
container_name: ${CI_PROJECT_NAME:-faircoinexplorer}-app
user: '${RUNNER_UID}:${RUNNER_GID}'
command: sleep inf
network_mode: host
- ${FAIRCHAINS_CONF}
container_name: explorer-app
user: '${RUNNER_UID:-1000}:${RUNNER_GID:-1000}'
# command: sleep inf
ports:
- ${LH_PORT_explorer:-8222}:8222
depends_on:
- db
- faircoin
volumes:
- .:/home/faircoin/explorer.kaana.red
- ./services/explorer:/home/faircoin/explorer
db:
image: mysql:5.7
container_name: ${CI_PROJECT_NAME:-faircoinexplorer}-mysql
restart: always
build:
context: services/db
container_name: explorer-db
environment:
MYSQL_DATABASE: explorer
# So you don't have to use root, but you can if you like
......@@ -31,12 +37,31 @@ services:
MYSQL_PASSWORD: ${MYSQL_PASSWORD:-password}
# Password for root access
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-rootpassword}
ports:
- ${MYSQL_DATABASE_PORT:-3306}:3306
volumes:
- db:/var/lib/mysql
- ./services/db:/opt/explorer
faircoin:
restart: always
build:
context: services/faircoin
args:
source_repository: "https://github.com/faircoin/faircoin.git"
RUNNER_UID: "${RUNNER_UID:-1000}"
RUNNER_GID: "${RUNNER_GID:-1000}"
environment:
AUTOSTART: ${AUTOSTART:-1}
env_file:
- ${FAIRCHAINS_CONF}
container_name: explorer-faircoind
user: "${RUNNER_UID:-1000}:${RUNNER_GID:-1000}"
stop_grace_period: 30s
volumes:
- my-db:/var/lib/mysql
- .:/opt/explorer.kaana.red
- fairchains:/home/faircoin/.faircoin2
- ./services/faircoin/scripts:/home/faircoin/scripts
- ./services/explorer:/home/faircoin/explorer
# Names our volume
volumes:
my-db:
fairchains:
db:
FAIRCHAINS_CONF=./env_file/FAIRCHAINS_CONF
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment