Deployment of a Connector Rails Application

This article describes how to deploy a Ruby on Rails application based on the Maestrano connector framework https://github.com/maestrano/maestrano-connector-rails

The installation steps target a Linux system. If you are familiar with Docker containers, you can use the images provided by Maestrano to easily deploy the application and its dependencies.





1 - Prerequisite

Make sure these software are already installed

2 - Setup

2.1 - Database

Create a user and a database dedicated to the connector.

Execute the following commands using the MySQL root account:

CREATE USER 'connector-user'@'localhost' IDENTIFIED BY 'connector-pwd';
GRANT ALL PRIVILEGES ON `connector-db`.* TO 'connector-user'@'localhost' WITH GRANT OPTION;
CREATE DATABASE `connector-db`;

2.2 - Redis

Follow https://redis.io/topics/quickstart

2.3 - Environment variables

In order to start the connector, you will need to configure a set of environment variables.

2.3.1 - Developer platform integration

The configuration of the marketplaces the connector is listed on is dynamically retrieved from the developer platform.

Related to:

  1. MNO_DEVPL_ENV_KEY
  2. MNO_DEVPL_ENV_SECRET

Description:

  • Go to https://developer.maestrano.com/
  • Go to your application
  • Open the Production Environment
  • Retrieve the environment variable
    • Environment Key assigned to MNO_DEVPL_ENV_KEY
    • Environment Secret assigned to MNO_DEVPL_ENV_SECRET

More info: Introduction to the developer platform 

2.3.2 - Passwords

Related to:

  • encryption_key1
  • encryption_key2
  • SECRET_KEY_BASE
  • SIDEKIQ_PASSWORD

Description:

  • Go to http://randomkeygen.com/ and generate 2 256-bit WEP Keys for encryption_key1 and encryption_key2 environment variables
  • Pick a Strong password for SIDEKIQ_PASSWORD
  • Generate SECRET_KEY_BASE by calling:

    rake secret

2.3.3 - Connector specific environment variable

The connector may have specific environment variable, they are in general defined in the application.sample.yml file in the github repository.

2.3.4 - Database

Related to DATABASE_URL

The database url is supposed to have this format

DATABASE_URL=mysql://[USER_NAME]:[USER_PASSWORD]@[MY_SQL_URL]:[MY_SQL_PORT]/[MY_SQL_DATABASE_NAME]?reconnect=true

so for example

DATABASE_URL=mysql://connector-user:connector-pwd@localhost:3306/connector-db?reconnect=true

2.3.5 - Redis

If you want a local installation: set

If you want an external installation, you may have a look at https://github.com/maestrano/redis

  • REDIS_URL=redis://[USER]:[PASSWORD]@[REDIS_URL]:[REDIS_PORT]

2.3.6 - Summary

The rail application will need all the listed environment variable to run.

You may create yourself a set-env.sh file in order to setup your environment variables.

set-env.sh
# Database
# DATABASE_URL=mysql2://[USER_NAME]:[USER_PASSWORD]@[MY_SQL_URL]:[MY_SQL_PORT]/[MY_SQL_DATABASE_NAME]?reconnect=true
export DATABASE_URL=mysql2://[USER_NAME]:[USER_PASSWORD]@[MY_SQL_URL]:[MY_SQL_PORT]/[MY_SQL_DATABASE_NAME]?reconnect=true

# Connector specific environment variable
# For example
# export partner_key=[ASK_APP_PROVIDER]
# export system_base_url=[ASK_APP_PROVIDER]
# export system_url=[ASK_APP_PROVIDER]
# export wsdl_url=[ASK_APP_PROVIDER]
# export CONNECTOR_SHARED_SECRET=[ASK_APP_PROVIDER]

# 256-bit WEP Keys
# Generate using http://randomkeygen.com/
export encryption_key1=[GENERATE_ME]
export encryption_key2=[GENERATE_ME]

# generate by calling RAILS_ENV=production rake secret
export SECRET_KEY_BASE=[GENERATE_ME]

# Sidekiq Admin management
# Generate using http://randomkeygen.com/
export SIDEKIQ_PASSWORD=[GENERATE_ME]
export SIDEKIQ_USERNAME=admin

# Maestreano connector. MNO_DEVPL_ENV_KEY and MNO_DEVPL_ENV_SECRET are retrieved from the developer platform

export MNO_DEVPL_HOST=https://developer.maestrano.com
export MNO_DEVPL_API_PATH=/api/config/v1/marketplaces
export MNO_DEVPL_ENV_NAME=Production
export MNO_DEVPL_ENV_KEY=[GENERATE_ME]
export MNO_DEVPL_ENV_SECRET=[GENERATE_ME]

export RACK_ENV=production
export RAILS_ENV=production
# the port you want to expose the web application
export PORT=1234

2.4 - Setup the Connector Application

2.4.1 - Check out the code of the connector, bundle install and install foreman

installing the connector
git clone git@github.com:maestrano/connector-[name-of-the-connector].git
cd connector-[name-of-the-connector]
bundle install
gem install foreman

2.4.2 - Migrating Database

Set environment variable, for example

source set-env.sh

Migrate database

rake db:migrate

2.4.3 - Asset Precompile

rake assets:precompile

3 - Start the Connector

  1. Make sure the mysql and redis are running
  2. Start the connector with:
foreman start

Verify the connector is up and running by opening the URL http://hostname:3000

It is recommended to not access the Rails server directly but to use a Web Server such as Nginx to process client requests.
The Maestrano default Nginx configuration can be found here: https://github.com/maestrano/docker-web-ruby/blob/master/2.3/app.conf

4 - Docker Installation

You may use docker to launch the connector web applications, the mysql database and the redis cache. You will need to setup the environment variables accordingly.

  1. Docker Web Ruby -  https://github.com/maestrano/docker-web-ruby
  2. Docker Mysql - https://github.com/maestrano/docker-mysql
  3. Docker Redis - https://github.com/maestrano/redis