Deploying Nodejs apps on dotcloud

    Intro

    Dotcloud is a cloud-based application deployment platform. Stack on DotCloud includes more than 10 different services, among which there are Node.JS .

    My first impressions of DotCloud were very positive. You can almost forget about how to deploy the application and completely focus on the code. The deployment work comes down to installing the DotCloud CLI and setting up the dotcloud.yml environment file . Client installation under Linux / MacOS is trivial:
    sudo easy_install pip && sudo pip install dotcloud

    Deployment Prep

    To deploy the application needs a file Dotcloud dotcloud.yml , which describes the services to which the application will have access to. A complete list of applications can be found here . To access the stack Node.JS + Redis file dotcloud.yml might look like this:
    www:
     type: nodejs

    data:
     type: redis

    If the application on Node.JS uses additional packages, then you can use the package.json file , in which you can specify dependencies on other packages. Packages will be automatically installed during deployment. Example package.json file :
    {
     "engines": {
      "node": ">=v0.4.5"
     },
     "dependencies": {
      "redis": ">=0.6.6",
      "express": ">=2.4.2"
     }
    }

    To automatically launch applications on Node.JS, you need to create a third file called supervisord.conf and specify the start path in it
    [program:node]
    command = node index.js
    directory = /home/dotcloud/current

    Using environment.json

    Accessing the stack of services that were specified in the dotcloud.yml file is very simple. After the application is deployed to the home directory, an environment.json file is created containing information for accessing the services. Using this file, you can configure the application to automatically use the settings for the databases without worrying about manual settings. Since I specified Redis as the database in the dotcloud.yml file and named it data , to get the settings for Redis from the application on Node.JS, just write:
    var envfilepath = '/home/dotcloud/environment.json',
      environment = JSON.parse(require('fs').readFileSync(envfilepath));

    var host = environment['DOTCLOUD_DATA_REDIS_HOST'],
      port = environment['DOTCLOUD_DATA_REDIS_PORT'],
      pass = environment['DOTCLOUD_DATA_REDIS_PASSWORD'];

    Deployment

    To create an application on Dotcloud you need to write in the console:
    dotcloud create appname
    ( appname - in this case, the name of the application, which can be anything)
    Well, directly push applications on Dotcloud
    dotcloud push appname ~/path-to-node-app/
    If the deployment is successful, they will issue a www address for accessing the application
    Deployment finished successfully. Your application is available at the following URLs
    www: d07c100d.dotcloud.com

    What else can be done

    Using your own domain name.
    To do this, you need to register a DNS record CNAME gateway.dotcloud.com. for the corresponding domain. And add an alias to your Dotcloud application:
    dotcloud alias add appname.www www.example.com
    You can also connect via SSH
    dotcloud ssh appname.www

    A full list of commands can be obtained in the detailed documentation on the official website

    Also popular now: