これからのPaaS注目株であるDotCloudを遅ればせながら少し試してみました。つい最近ベータ期間を終了し、正式サービスを開始したとのことです。ヒゲのおじさまカッコイイ。
* [追記] 各ミドルウェアも使ってみました。続きの記事はこちら。
DotCloudでのMySQL,Redis,MongoDBの使い方
DotCloudの特徴としては上のビデオや下の図を見て分かるように、プログラミング言語やミドルウェアを選択できるという点です。つまりユーザーはこれらの技術を自由に組み合わせてシステムを構築することができます。これはGAEやHerokuなど利用技術に制限のあるPaaSとの大きな違いです。
公式のチュートリアルを読めば使い方はすぐわかるのですが、一応ここでもデプロイまでの手順を簡単に追ってみます。先日のRubyKaigiの興奮冷めやらぬ今、利用言語はRubyで。
と言いつつ、DotCloudのコマンドラインツールはPythonで書かれているのでまずそれをインストールします。アカウントは先に作成しておいてください。DotCloud – Sign Up Free
[shell]
## pip導入済みの場合は sudo pip install dotcloud のみでOK
$ sudo easy_install pip && sudo pip install dotcloud
## 初めて実行したときにapi keyを入力する
## http://www.dotcloud.com/account/settings で確認して入力
$ dotcloud
Enter your api key (You can find it at http://www.dotcloud.com/account/settings):
## ヘルプ表示
$ dotcloud -h
Command line tool to interact with dotcloud
positional arguments:
{info,status,run,logs,versions,url,setup,list,rollback,alias,ssh,push,destroy,create,restart}
setup setup your api key
create create an application
push push your application
list list your applications
versions list the versions of your application
run run a remote command
logs read logs
alias bind a custom domain name to a service
destroy destroy your application
url display URL(s) of your application
info get information about your application or service
status check the status
rollback rollback your service to the previous pushed version
ssh open an SSH session
restart restart your service
optional arguments:
-h, –help show this help message and exit
[/shell]
ここではRackアプリケーションをデプロイするところまで。
[shell]
$ mkdir helloworld
$ cd helloworld
$ dotcloud create helloworld
Created application “helloworld”
[/shell]
dotcloud.yml という設定ファイルに利用言語などを記述します。環境を選べるDotCloudの特徴的なところですね。必要に応じてデータベースやサービスのエントリーポイントなどの指定もこのファイルに記述します。
* dotcloud.yml
[shell]
www:
type: ruby
[/shell]
ここでは言語を選んでいるだけなのでこれだけです。次にRackアプリ本体をRubyで普通に書きます。実際にアプリ開発するときはSinatraなどのフレームワークを利用することになると思います。
* config.ru
[ruby]
run proc{|env| [200, {‘Content-Type’=>’text/plain’}, ‘Hello World!’]}
[/ruby]
残るはデプロイ。これも簡単。
[shell]
## 必要なファイルを確認
$ ls
config.ru dotcloud.yml
## 作成したアプリケーションをpush
$ dotcloud push helloworld
Pseudo-terminal will not be allocated because stdin is not a terminal.
building file list … done
./
config.ru
dotcloud.yml
sent 295 bytes received 70 bytes 42.94 bytes/sec
total size is 88 speedup is 0.24
Deployment for “helloworld” triggered. Will be available in a few seconds.
2011-07-24 03:36:36 [api] Waiting for the build. (It may take a few minutes)
2011-07-24 03:36:36 [www.0] Deploying…
2011-07-24 03:37:05 [www.0] Service booted
2011-07-24 03:37:05 [www.0] The build started
2011-07-24 03:37:06 [www.0] Fetched code revision rsync-1311478595.13
2011-07-24 03:37:16 [www.0] nginx start/running, process 1412
2011-07-24 03:37:17 [www.0] The build finished successfully
2011-07-24 03:37:17 [api] Deploy finished
Deployment finished. Your application is available at the following URLs
www: http://9c79afdc.dotcloud.com/ ## URLが表示されるのでここにアクセス
## サービスの情報を確認
$ dotcloud info helloworld
www:
config:
rack-env: production
ruby-version: 1.9.2
instances: 1
type: ruby
url: http://9c79afdc.dotcloud.com/
[/shell]
あとはブラウザから表示されたURLにアクセスして Hello World! と表示されたら成功です。
Deployment made simpleを謳うとおり本当に簡単でした。ここまで5分かからない。コマンドラインツールの使い方も dotcloud.yml の書き方も簡単なのですぐに覚えられます。他の言語やミドルウェア(MongoDB, Redis)もいくつか試してみたのですが、特につまづくところはなかったです。ドキュメントもこれから充実してくるはず。また、料金ですが2サービスまで無料とのことです。DotCloud – Pricing
GAEなどの従来のPaaSを利用していて窮屈に感じていた人はDotCloudを新しい遊び場に選ぶといいかもしれません。
雲は縛られない。
* 参考
プログラミング言語やデータベースが選べる新世代PaaS「DotCloud」が正式サービス開始 - Publickey