Skip to content

Latest commit

 

History

History
370 lines (259 loc) · 9.17 KB

setup-ubuntu.md

File metadata and controls

370 lines (259 loc) · 9.17 KB

Setup local development environment on Ubuntu 16.04

Overview

  1. Install Ruby
  2. Install MySQL
  3. Install Redis
  4. Install RabbitMQ
  5. Install Bitcoind
  6. Install PhantomJS
  7. Install JavaScript Runtime
  8. Install ImageMagick
  9. Configure Peatio
  10. Configure peatio-trading-ui
  11. Setup the nginx reverse-proxy

Step 1: Install Ruby

Update

sudo apt-get update

Installing rbenv using a Installer:

  sudo apt-get install git-core curl zlib1g-dev build-essential \
                         libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 \
                         libxml2-dev libxslt1-dev libcurl4-openssl-dev \
                         python-software-properties libffi-dev

    cd
    git clone git://github.com/sstephenson/rbenv.git .rbenv
    echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
    echo 'eval "$(rbenv init -)"' >> ~/.bashrc
    exec $SHELL

    git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
    echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
    exec $SHELL

Install Ruby through rbenv:

rbenv install 2.5.0
rbenv global 2.5.0

Install bundler:

echo "gem: --no-ri --no-rdoc" > ~/.gemrc
gem install bundler
rbenv rehash

Step 2: Install MySQL

sudo apt-get install mysql-server mysql-client libmysqlclient-dev

Add the environement variable (ideally in .bashrc, and don't forget to $ source ~/.bashrc after editing the file)

echo 'export DATABASE_HOST=<localhost>' » ~/.bashrc 
echo 'export DATABASE_USER=<username for root usually>' » ~/.bashrc 
echo 'export DATABASE_PASS=<pwd for root>' » ~/.bashrc

$ source ~/.bashrc

Step 3: Install Redis

Be sure to install the latest stable Redis, as the package, the distro one can be outdated:

sudo add-apt-repository ppa:chris-lea/redis-server
sudo apt-get update
sudo apt-get install redis-server

Step 4: Install RabbitMQ

Please follow instructions here:

# add rabbitmq debian repo
    echo 'deb http://www.rabbitmq.com/debian/ testing main' |
    sudo tee /etc/apt/sources.list.d/rabbitmq.list
    wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc |
    sudo apt-key add -

# install rabbitmq
sudo apt-get update
sudo apt-get install rabbitmq-server

# start the rabbitmq serveer
sudo rabbitmq-plugins enable rabbitmq_management
sudo service rabbitmq-server restart

# download and install rabbitmqadmin
wget http://localhost:15672/cli/rabbitmqadmin
chmod +x rabbitmqadmin
sudo mv rabbitmqadmin /usr/local/sbin

Step 5: Install Bitcoind

sudo add-apt-repository ppa:bitcoin/bitcoin
sudo apt-get update
sudo apt-get install bitcoind

Configure

Prepare config files:

mkdir -p ~/.bitcoin
touch ~/.bitcoin/bitcoin.conf
vim ~/.bitcoin/bitcoin.conf

Insert the following lines into bitcoin.conf, and replce with your username and password.

server=1
daemon=1

# If run on the test network instead of the real bitcoin network
testnet=1

# You must set rpcuser and rpcpassword to secure the JSON-RPC api
# Please make rpcpassword to something secure, `5gKAgrJv8CQr2CGUhjVbBFLSj29HnE6YGXvfykHJzS3k` for example.
# Listen for JSON-RPC connections on <port> (default: 8332 or testnet: 18332)
rpcuser=USERNAME
rpcpassword=PASSWORD
rpcport=18332

# Notify when receiving coins
walletnotify=/usr/local/sbin/rabbitmqadmin publish routing_key=peatio.deposit.coin payload='{"txid":"%s", "currency":"btc"}'

Start bitcoin daemon:

bitcoind

Step 6: Install PhantomJS

Peatio uses Capybara with PhantomJS to do the feature tests, so if you want to run the tests. Install the PhantomJS is neccessary.

sudo apt-get update
sudo apt-get install build-essential chrpath git-core libssl-dev libfontconfig1-dev

cd /usr/local/share

PHANTOMJS_VERISON=1.9.8
sudo wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-$PHANTOMJS_VERISON-linux-x86_64.tar.bz2

sudo tar xjf phantomjs-$PHANTOMJS_VERISON-linux-x86_64.tar.bz2

sudo ln -s /usr/local/share/phantomjs-$PHANTOMJS_VERISON-linux-x86_64/bin/phantomjs /usr/local/share/phantomjs
sudo ln -s /usr/local/share/phantomjs-$PHANTOMJS_VERISON-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs
sudo ln -s /usr/local/share/phantomjs-$PHANTOMJS_VERISON-linux-x86_64/bin/phantomjs /usr/bin/phantomjs

Step 7: Install JavaScript Runtime

A JavaScript Runtime is needed for Asset Pipeline to work. Any runtime will do but Node.js is recommended.

curl -sL https://deb.nodesource.com/setup_8.x | sudo bash -
sudo apt-get install nodejs

Step 8: Install ImageMagick

sudo apt-get install imagemagick

Step 9: Configure Peatio

Clone the project:

mkdir code
cd code
git clone https://github.com/PeatioBlockchain/peatio.git
cd peatio
git checkout 1-8-stable  // Choose your version, but make sure you'll install the same version for peatio-trading-ui
bundle install

Prepare configuration files:

bin/init_config

Then install and run yarn:

$ npm install -g yarn
$ bundle exec rake tmp:create yarn:install assets:precompile

Setup Pusher

Peatio depends on pusher. A development key/secret pair for development/test is provided in config/application.yml. PLEASE USE IT IN DEVELOPMENT/TEST ENVIRONMENT ONLY!

Set pusher-related settings in vim config/application.yml.

You can always find more details about pusher configuration at pusher website

Setup bitcoind rpc endpoint

Edit vim config/seed/currencies.yml.

Replace username:password and port. username and password should only contain letters and numbers, do not use email as username.

Setup database:

Edit vim config/database.yml. Replace Database: Hostname, username and password.

rake db:create
rake db:migrate 
rake db:seed

Run daemons

Make sure you are in /peatio directory

Run $ god -c lib/daemons/daemons.god to start the deamon

More info about Peatio daemons at Peatio daemons.

Generate liability proof

To generate liability proof run:

bundle exec rake solvency:liability_proof

Otherwise you will get an exception at the "Solvency" page.

Setup the Google Authentication

  • By default, it ask for Google Authentication. This parameter can be changed in /config/application.yml -> OAUTH2_SIGN_IN_PROVIDER: google
  • Setup a new Web application on https://console.developers.google.com
  • Configure the Google Id, Secret and callback in /config/application.yml
  • Note: Make sure your host ISN'T an IP in the callback config. Looks like Google auth expect a callback to a DNS only
  GOOGLE_CLIENT_ID: <Google id>
  GOOGLE_CLIENT_SECRET: <Google secret>
  GOOGLE_OAUTH2_REDIRECT_URL: http://ec2-xx-xx-xx-xx.compute-1.amazonaws.com:3000/auth/google_oauth2/callback

Run Peatio

Finalize the config; open /config/application.yml Set the DNS of your host (IP won't work if you use Google Authentication)

URL_HOST: ec2-34-xxx-xxx-xx.compute-1.amazonaws.com:3000

Start the server:

$ bundle exec rails server

If you setup peatio-workbench on a server (like AWS ec2)

  • Make sure the port 3000 is open your server
  • Start the server by passing the ip in parameter
$ bundle exec rails server -b 0.0.0.0

Validate the server is working:

visit http://localhost:3000 or the public DNS of your server

Sign in with Google SSO

NOTE: At this point, the "trade" screen isn't working as you need to setup the trading server. See next step.

Step 10. Run Peatio Trading UI

Clone the repo and setup the Trading UI

cd ~/code
git clone https://github.com/rubykube/peatio-trading-ui.git
cd peatio-trading-ui
bundle install
bin/init_config

Edit the /config/application.yml and set your app DNS. Ex:

PLATFORM_ROOT_URL: http://ec2-xx-xx-xxx-xxx.compute-1.amazonaws.com

Refer to the release note here : https://github.com/rubykube/peatio/blob/master/docs/releases/1.5.0.md

Start Trading UI

$ bundle exec rails server -b 0.0.0.0 -p 4000

Step 11. Install nginx to setup a reverse proxy

sudo apt-get update
sudo apt-get install nginx
sudo ufw allow 'Nginx HTTP'
systemctl status nginx

At this point you should see nginx running

But you need to edit the default config to setup the reverse proxy. Open /etc/nginx/sites-available/default in your favorite editor

Replace the content of the file by the following

server {
  server_name http://peatio.local;
  listen      80 default_server;

  location ~ ^/(?:trading|trading-ui-assets)\/ {
    proxy_pass http://127.0.0.1:4000;
  }

  location / {
    proxy_pass http://127.0.0.1:3000;
  }
}

Make sure to replace http://peatio.local and 127.0.0.1 with your actual server DNS

Verify that the syntax of the config file is valid : $ sudo nginx -t

Restart nginx by running sudo systemctl restart nginx