-
Notifications
You must be signed in to change notification settings - Fork 58
Deployment
These are scripts for deploying your own server. We currently host blockbuilder on a Google Cloud Platform n1-standard-2 (2 vCPUs, 7.5 GB memory)
VM instance running Ubuntu 16.04 LTS
This guide will list the steps required to setup a new blockbuilder server.
sudo su root
git config --global user.email "[email protected]"
git config --global user.name "Building Blocks"
(this prevents an error where git is complains about not knowing who you are when trying to save a thumbnail image)
Install node version v8.12.0
Follow this guide from Digital Ocean, starting at the How To Install Using NVM
section
once you install node & npm, you should see:
node -v
# v8.12.0
npm -v
# 6.4.1
npm install
npm run buildProd
blockbuilder uses Redis for ${some kind of caching}
TODO document what exactly we use Redis for
install Redis on Ubuntu 16.04
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make
sudo make install
you can also follow the instructions here https://redis.io/topics/quickstart
redis-server
# Import the public key used by the package management system
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
# Create a list file for MongoDB
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
# Reload local package database
sudo apt-get update
# Install the latest version of MongoDB
sudo apt-get install -y mongodb-org
you can also follow the instructions here https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
To start the MongoDB database service
sudo service mongod start
# to verify that MongoDB has started successfully
# inspect the logs
sudo vim /var/log/mongodb/mongod.log
# and look for the line
# [initandlisten] waiting for connections on port 27017
cd blockbuilder
node server.js
Make sure that that node server.js
works without errors before proceeding. It's easier to read the webserver logs and debug errors here, before we wrap it in a linux system service.
We create a linux service called blockbuilder.service
with systemd. Wrapping our nodejs + express web server in a linux service makes sure that the blockbuilder nodejs + express web server stays running, even after a host-server reboot.
to install the service, copy the service defintion from the blockbuilder repo to this systemd directory:
sudo cp /home/ubuntu/blockbuilder/deploy/blockbuilder.service /etc/systemd/system/blockbuilder.service
We can now manage the blockbuilder
service with these commands:
sudo systemctl start blockbuilder
sudo systemctl stop blockbuilder
sudo systemctl status blockbuilder
to start our new blockbuilder
service on boot:
sudo systemctl enable blockbuilder
Note that the server runs on port 8889
, so you will need to redirect port 80 traffic to port 8889 due to Ubuntu's security restrictions.
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8889
sudo iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 8443
alternately, you can setup nginx
generally, follow:
-
this guide to setup nginx https://medium.com/@jasonrigden/how-to-host-a-static-website-with-nginx-8b2dd0c5b301
-
this answer for how to forward port 80 to port 8889 with nginx https://stackoverflow.com/questions/24861311/forwarding-port-80-to-8080-using-nginx
-
setup a CRONTAB to automatically renew your ssl cert, like this https://github.com/micahstubbs/screenshot-service/blob/master/dedicated-server/deploy/crontab
crontab -e
more reading about crontabs https://askubuntu.com/questions/2368/how-do-i-set-up-a-cron-job
# enable the nginx config for your blockbuilder instance's domain
# where blockbuilder.org is your domain
sudo ln -s /etc/nginx/sites-available/blockbuilder.org /etc/nginx/sites-enabled/
SSH into server and run make update
.
This will run git pull
to update the code base. It will also run npm install
and npm run build
to ensure dependencies are up to date after a pull and to build the build artifacts.
If your server doesn't have it installed, you will need to get expect
sudo apt-get install expect
Deprecated instructions
You can install everything yourself, or use a pre-packaged AMI running Ubuntu 14.04 with everything up and running. The AMI id is ami-d52e87be
. The user is ubuntu
and the code is deployed in /home/ubuntu/Code/building-blocks
.
If you wish to roll your own server, the following steps serve as a guide for getting everything up and running.
Note that the server runs on port 8889
, so you will need to redirect port 80 traffic to port 8889. You can do this on ubuntu by using iptables-persistent
and adding the following to end of /etc/iptables/rules.v4
:
# Route ports to app
*nat
:PREROUTING ACCEPT [1:48]
:INPUT ACCEPT [13:816]
:OUTPUT ACCEPT [18:1447]
:POSTROUTING ACCEPT [18:1447]
-A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8889
-A PREROUTING -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 8443
COMMIT
#Done
The following assumes that everything is setup in /home/ubuntu/Code/building-blocks
Upstart provides a way to start / stop services.
This is the upstart script which allows us to run service building-blocks start
to startup the service. Copy to /etc/init/building-blocks.conf
.
Monit will watch processes and restart them if they stop. It is optional.
Configuration file for monit. Copy to /etc/monit/monitrc
Configuration file for watching building-blocks with monit. Copy to /etc/monit/conf.d/building-blocks