dotCloud is a cloud-based platform for hosting web applications. Free account is well suited for training.
Its advantages:
- You can use two services for free. Unlike heroku , you can make a full-fledged database application.
- file system is available for writing - it will be more convenient to keep logs
- good documentation .
But there are also disadvantages:
- free services “fall asleep” if no one has used them for the last half hour. This means that such a situation is possible: you go to your site and instead see the standard service page asking you to wait. After some time (up to several minutes) the service “wakes up” and starts working as it should be.
- the default version is
node 0.4.10
. But it can be fixed.
Warning: Most of what is written below is a brief retelling of official documentation . Of course, it would be better to read the full version.
')
Terms
When working with DotCloud, the word
application (application) means a set of
services (services) that you use. The service can be a single node.js process (php, python, ruby, etc.) or a single database instance. For example, from the php and mysql services, you can make a “wordpress blog” application.
When you register on the site, in the Settings section you will see the so-called
API Key - a randomly generated sequence of letters and numbers. She will need to continue to work with the platform.
All actions with DotCloud are performed using a special
dotcloud
utility (in the documentation it is called the CLI - Command-Line Interface).
CLI Installation
The CLI is written in Python and uses the EasyInstall package manager, so you first need to
install it :
sudo apt-get install python-setuptools python-dev build-essential
and then
sudo easy_install pip && sudo pip install dotcloud
As a result, the
dotcloud utility will appear on your system. When you first start you will need to enter your
API Key .
Application installation
The simplest example of the application was found
here . But it does nothing, and therefore not very interesting.
Source preparation
Suppose you already have some kind of running node.js application. You can use the
example from this
article . It will be necessary to make one change:
dotCloud applications are required to listen to port 8080 . After deployment, it will be available as usual, on port 80, but in the source code it should be exactly 8080.
Application Description
For deployment, you need to create and put in the right places on the file system three files:
dotcloud.yml
,
supervisord.conf
and
package.json
. As a result, you should get this structure:
ninja_on_dotcloud/ |_ dotcloud.yml |_ ninja-store/ |_ supervisord.conf |_ package.json |_ app.js |_ ...
The
dotcloud.yml
file describes the set of services that our application uses. We have one service, so
dotcloud.yml
looks like this:
www: type: nodejs approot: ninja-store
Here
www
is the name of the service (theoretically it can be any),
ninja-store
is our source folder.
supervisord.conf
also simple:
[program:node] command = node app.js directory = /home/dotcloud/current
In this case,
app.js
is the main file of our application.
package.json is a standard
npm file. For placement on dotCloud, only the
dependencies section is important in which the packages used by your application are listed.
Deployment
To get it all to the server, you need to run two commands.
First create an application
dotcloud create -f sandbox nstore
The
-f
key sets the
application flavor - roughly speaking, the tariff plan and hosting options.
nstore
- the name of our application, will be needed for further management.
And finally, send the code of our site to the server
dotcloud push nstore ./ninja_on_dotcloud
As a result, if everything goes well, then the console will write the address at which the application will be available. In my case, it is
http://nstore-beardog.dotcloud.com/ . The rules by which this URL is formed may change: a year ago, a random sequence of characters was simply generated, and the name of the application and account is now combined. You cannot use your own domain with a free account.
And if it is bad, you will have to watch the logs.
View logs
If the application is successfully launched, you can see the logs with the
command
dotcloud logs _._
It happens that an application cannot be started (for example, if you forget to specify a dependency in package.json). Then you need to use something like very truncated
ssh access . For example, this is how I discovered that in version 0.4.10 there is a shortage of the
zlib module, which is necessary for the work of express.js:
user@u5$ dotcloud ssh ninjastore.www
The names of files with logs can change with the release of the new version of the platform, so you will not be able to give clear instructions. Most likely, somewhere in
/var/log/
there is a file with the necessary information.
Installing other versions of node
Thanks to the hack shown in
this repository , any version of node.js can be installed on dotCloud.
Need to:
- Copy repository
- In the dotcloud.yml file in the
node_version
field indicate the version you want - Naturally, replace
hellonode
with your sources - Run
dotcloud push
as usual.
Important: delete the .git folder after cloning. If dotcloud notices it, it will try to pick up the source from github , instead of using the local version.
As a result, during the installation,
dotcloud
downloads and
dotcloud
sources of the specified node version. The following calls to
push
will not compile.
Perhaps there will be problems with the logs, then you can try
this version.
Another possible problem is the port that the application should listen to. For some reason, in that example, it is defined
like this :
}).listen(process.env['PORT_WWW'] || 8080);
All thanks for your attention.
Here there was another article about dotcloud, mongodb and node. And a year ago,
an article with the same title appeared on Habré (unfortunately, I found it after I wrote my own)