EGF2 Guide - Deployment Part 1

We've got client-data config ready, let's start deploying EGF2. I will explain how we can deploy framework and all necessary tools on a single Amazon Linux instance in AWS. Get an instance with at least 2GB of RAM, we are going to have a lot of stuff here. Also, please create an S3 bucket that will be used by the file service. An IAM role that allows full access to this S3 bucket should be configured and assigned to this instance.

But before we get to the console we need to fork necessary framework repositories. We will start with the following services (repositories):

  • client-data
  • client-api
  • auth

Once you've got them forked please apply the changes to the client-data/config.json.

Before we deploy EGF2 services we need to install and configure RethinkDB.

RethinkDB

As we are going to a single instance deployment it makes sense to use RethinkDB. Cassandra in this situation seems like a bit of an overkill :-)

To install RethinkDB from the development repo please run the following commands:

  • wget "http://download.rethinkdb.com/centos/7/`uname -m`/rethinkdb.repo" -O /etc/yum.repos.d/rethinkdb.repo

  • yum install -y rethinkdb

In order to configure RethinkDB please create a file /etc/rethinkdb/instances.d/guide-db.conf with the following content:

bind=all  
server-tag=default  
server-tag=us_west_2  
server-tag=guide_db  

Please note that server-tag=us_west_2 means that we are using an instance started in US-WEST-2 region of AWS.

And now you can start it:

  • chkconfig --add rethinkdb
  • chkconfig rethinkdb on
  • service rethinkdb start

RethinkDB is now ready.

Deploying Services

Please install the latest stable version of the Node.js.

Clone the services that we decided to deploy in /opt directory. Run npm install in every service directory.

In order to run client-data service we need to specify what port we want it to run on and configure RethinkDB parameters:

{
    ...
    "port": 8000,
    "storage": "rethinkdb",
    "log_level": "debug",
    "rethinkdb": {
        "host": "localhost",
        "db": "guide"
    }
    ...
}

You can pick another port, if you'd like to. We just need to remember it as we will point other services to client-data using it.

To configure auth service please set the following parameters:

{
    ...
    "port": 2016,
    "log_level": "debug",
    "client-data": "http://localhost:8000"
    ...
}

And client-api is configured with:

{
    ...
    "port": 2019,
    "log_level": "debug",
    "client-data": "http://localhost:8000"
    "auth": "http://localhost:2016"
    ...
}

As you can see, client-data is the only service that talks to RethinkDB. Other services are using it for all data needs.

Before we start services we need to initialise DB. We can do it easily:

node index.js --config /opt/client-data/config.json --init

Output of this task will include a line:

SecretOrganization = "<SecretOrganization object ID>"

Please use the SecretOrganization object ID string in:

"graph": {
...
    "objects": {
        "secret_organization": "<object ID>"
    }
...
}

This will let client-data know object ID of SecretOrganization singleton.

In order to start a service please do the following:

  • cd /opt/<service>
  • node index.js --config /opt/<service>/config.json

Where <service> takes values "client-data", "client-api", "auth". Please start client-data first, before other services.

NGINX

With our services started we need to do one more thing - install and configure NGINX with yum install -y nginx.

Create a file called api-endpoints in /etc/nginx folder. Add the following text to it:

#Client API
location /v1/graph {  
    proxy_pass http://127.0.0.1:2019;
}

#Auth
location /v1/register {  
    proxy_pass http://127.0.0.1:2016;
}
location /v1/verify_email {  
    proxy_pass http://127.0.0.1:2016;
}
location /v1/login {  
    proxy_pass http://127.0.0.1:2016;
}
location /v1/logout {  
    proxy_pass http://127.0.0.1:2016;
}
location /v1/forgot_password {  
    proxy_pass http://127.0.0.1:2016;
}
location /v1/change_password {  
    proxy_pass http://127.0.0.1:2016;
}
location /v1/resend_email_verification {  
    proxy_pass http://127.0.0.1:2016;
}

We also need to update /etc/nginx/nginx.conf file, add line in the following section:

server {  
        listen       80;
        server_name  localhost;
        include api-endpoints;
...

We are adding one line - include api-endpoints;.

After that we are ready to start NGINX:

  • chkconfig nginx on
  • service nginx start

That's it - the system is up!

What have we got:

  1. Full Graph API - all endpoints are functional and know about our designed model.
  2. Registration, login, logout (without verification emails).

I will continue with deployments in the next post - we will add ElasticSearch, sync, pusher and file services to the system.

comments powered by Disqus