EGF2 Guide - Deployment Part 2

In the previous post we've got part of the services deployed along with RethinkDB and NGINX.

Now we need to finalise our works with the addition of ElasticSearch and the rest of the services. We will have search and file related endpoints powered as a result, email notifications will be sent for the email verification and forgot password features.

Let's start with ElasticSearch.

ElasticSearch

First do RPM import:

rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch  

Create file /etc/yum.repos.d/elasticsearch.repo with content:

[elasticsearch-2.x]
name=Elasticsearch repository for 2.x packages  
baseurl=http://packages.elastic.co/elasticsearch/2.x/centos  
gpgcheck=1  
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch  
enabled=1  

Install package:

yum install -y elasticsearch  

And to start ElasticSearch please do:

  • chkconfig elasticsearch on
  • service elasticsearch start

We need to add info on ES to the config files of our deployed and running services.

This line should be added to the end of client-api and auth service configs:

"elastic": { "hosts": ["localhost:9200"] }

Restart client-api and auth services.

client-api is using ES to power the search endpoint. auth needs ES to lookup users by email.

We also need to configure one additional endpoint with our NGINX, please add the following to the /etc/nginx/api-endpoints file:

location /v1/search {  
    proxy_pass http://127.0.0.1:2019;
}

Now we have search endpoint ready!

Deploying Services

Please fork and then clone file, sync and pusher services to the /opt folder.

sync

To configure sync service please change the following parameters:

{
    ...
    "log_level": "debug",
    "client-data": "http://localhost:8000",
    "queue": "rethinkdb",
    "consumer-group": "sync",
    "rethinkdb": {
        "host": "localhost",
    "port": "28015",
    "db": "guide",
    "table": "events",
    "offsettable": "event_offset"
    }
    ...
}

With the single instance deployment we are using RethinkDB changes feed feature as a system event bus. While it works great for development and testing please note that it is not a scalable solution. For production systems please use "queue": "kafka" setup instead. "rethinkdb" parameter holds config necessary for sync to connect to RethinkDB directly.

The rest of the config we will leave intact for now. It contains system ES indexes that are used by some of the services we have. I will do a separate post on sync and ES indexes shortly.

We are ready to start sync:

  • cd /opt/sync
  • npm install
  • node index.js --config /opt/sync/config.json

sync is running!

file

Let's configure file service:

{
    "log_level": "debug",
    "port": 2018,
    "auth": "http://localhost:2016",
    “client-data”: "http://localhost:8000",
    "s3_bucket": “egf2-guide-images”,
    "queue": "rethinkdb",
    "consumer-group": "file",
        "rethinkdb": {
            "host": "localhost",
        "port": "28015",
        "db": "guide",
        "table": "events",
        "offsettable": "event_offset"
    }
}

Please note parameter "s3_bucket" - you need to use a name of an AWS S3 bucket here. Your instance should have an IAM role that allows full access to this bucket.

We will leave parameter called "kinds" intact for now. What it allows us to do is to have predefined image resize groups. When a new image is created a kind can be specified, file service will then create necessary resizes automatically.

In order to be able to resize images file service needs ImageMagick. To install the package please do yum install ImageMagick

And start the service:

  • cd /opt/file
  • npm install
  • node index.js --config /opt/file/config.json

Let's allow file service endpoints with our NGINX, please add the following to the /etc/nginx/api-endpoints file:

location /v1/new_image {  
    proxy_pass http://127.0.0.1:2018;
}

location /v1/new_file {  
    proxy_pass http://127.0.0.1:2018;
}

pusher

Let's configure pusher service:

{
    "log_level": "debug",
    "port": 2017,
    "auth": "http://localhost:2016",
    “client-data”: "http://localhost:8000",
    "web_socket_port": 80,
    "email_transport": "sendgrid",
    "template_host": "localhost",
    "ignored_domains": [],
    "queue": "rethinkdb",
    "consumer-group": "pusher",
        "rethinkdb": {
            "host": "localhost",
        "port": "28015",
        "db": "guide",
        "table": "events",
        "offsettable": "event_offset"
    }   
}

"email_transport": "sendgrid" option specifies that we will use SendGrid to send our email notifications.

It is important to note that there is no SendGrid API key in config file here. In order to simplify config file deployment we assume that configs are not private, thus we don't store any sensitive information in configs. Instead, we have a singleton object of type SecretOrganization that stores API keys etc.

Please set value for key "sendgridapikey" with your SendGrid API key. It can be done as follows:

curl -XPUT -H "Content-Type: application/json" http://localhost:8000/v1/graph/<SecretOrganization object ID> -d '{"secret_keys":[{"key":"sendgrid_api_key","value":"<sendgrid_api_token>"}]}'  

Where <SecretOrganization object ID> can be found in client-data config, "graph"/"objects"/"secret_organization" field.

After that we can start the service:

  • cd /opt/file
  • npm install
  • node index.js --config /opt/file/config.json

We now have all the services and tools in place that are necessary for the Guide system at this stage. The only services that were not deployed yet are:

  • scheduler - internal scheduling service
  • job - large task async handling

Both of them are not necessary at the moment.

The system we have deployed so far can be utilised by web and mobile system developers to create and test client apps. We find it a great help to have good part of back-end in place as soon as possible, it helps client app development a lot.

We will continue with adding ElasticSearch indexes in the next post.

comments powered by Disqus