2011/04/28

CloudFoundryに触る

新サービス CloudFoundry!ということで、チュートリアルをやってみた。内容はチュートリアル動画(Youtube) の通り。

※環境は Windows7 64bit & NYAOS
NYAOS & GoW イイ!と思っていたけど、Git Bashでbinにパス通しておく方が楽でいい感じがしてきた。findとかあるし。

0. Rubyを入れる(動画見る前に準備)

RubyInstaller から Ruby 1.9.2-p180 を落としてきて入れる。インストーラー無し版はなぜか7-Zip書庫。最近はそういうものなのだろうか。

1. gemバージョン更新

gem のバージョンは 1.7.2 がよいらしい。デフォルトは古いので更新。
$ gem update --system
Updating rubygems-update
Fetching: rubygems-update-1.7.2.gem (100%)
Successfully installed rubygems-update-1.7.2
Installing RubyGems 1.7.2
RubyGems 1.7.2 installed

・ソ=== 1.7.2 / 2011-04-05

* 1 Bug Fix:
  * Warn on loading bad spec array values (ntlm-http gem has nil in its cert
    chain)


------------------------------------------------------------------------------

RubyGems installed the following executables:
        E:/Ruby/bin/gem

RubyGems system software updated

2. vmcインストール

CloudFoundry を楽しくするためのツールをインストール。VMWare Command line Client for CloudFoundry の略かどうかは分からないが、きっとどれかひとつ C は当たっている。
$ gem install vmc
Fetching: json_pure-1.5.1.gem (100%)
Fetching: rubyzip2-2.0.1.gem (100%)
Fetching: highline-1.6.1.gem (100%)
Fetching: mime-types-1.16.gem (100%)
Fetching: rest-client-1.6.1.gem (100%)
Fetching: terminal-table-1.4.2.gem (100%)
Fetching: vmc-0.3.10.gem (100%)
Successfully installed json_pure-1.5.1
Successfully installed rubyzip2-2.0.1
Successfully installed highline-1.6.1
Successfully installed mime-types-1.16
Successfully installed rest-client-1.6.1
Successfully installed terminal-table-1.4.2
Successfully installed vmc-0.3.10
7 gems installed
Installing ri documentation for json_pure-1.5.1...
Installing ri documentation for rubyzip2-2.0.1...
Installing ri documentation for highline-1.6.1...
Installing ri documentation for mime-types-1.16...
Installing ri documentation for rest-client-1.6.1...
Installing ri documentation for terminal-table-1.4.2...
Installing ri documentation for vmc-0.3.10...
Installing RDoc documentation for json_pure-1.5.1...
Installing RDoc documentation for rubyzip2-2.0.1...
Installing RDoc documentation for highline-1.6.1...
Installing RDoc documentation for mime-types-1.16...
Installing RDoc documentation for rest-client-1.6.1...
Installing RDoc documentation for terminal-table-1.4.2...
Installing RDoc documentation for vmc-0.3.10...

3. APIターゲット指定

ターゲットロックオン。ここから全てが始まる。たぶん。
$ vmc target api.cloudfoundry.com
Succesfully targeted to [http://api.cloudfoundry.com]

4. ログイン

登録したメアドと送られてきたパスワードでログイン。
$ vmc login
Email: ****@segu.jp
Password: ********
Successfully logged into [http://api.cloudfoundry.com]
ターゲットロッグイン。

5. Rubyアプリケーション作成

$ mkdir hello
$ cd hello
ここに hello.rb を作る。中身は以下。
require 'sinatra'
get "/" do
  "Hello from Cloud Foundry"
end

6. アプリケーション登録

作ったファイルがあるのを確認して、プッシュプッシュ。アプリケーション名を入れるところ以外は、デフォルトのままリターンでOK。よく聞くdeployとかいう言葉が出てくる。なるほど。
$ ls
hello.rb*
$ vmc push
Would you like to deploy from the current directory? [Yn]:
Application Name: segu-hello
Application Deployed URL: 'segu-hello.cloudfoundry.com'?
Detected a Sinatra Application, is this correct? [Yn]:
Memory Reservation [Default:128M] (64M, 128M, 256M, 512M, 1G or 2G)
Creating Application: OK
Would you like to bind any services to 'segu-hello'? [yN]:
Uploading Application:
  Checking for available resources: OK
  Packing application: OK
  Uploading (0K): OK
Push Status: OK
Staging Application: OK
Starting Application: OK
アプリケーションをアップロードして開始してくれる。当然ながらメモリは64Mでも問題なかった。

7. 見てみる

上記に登録したURLが記載されているので、そこ(segu-hello.cloudfoundry.com)にアクセス。なんか随分と簡単だ。

8. 修正したら

アップデート。勝手に再起動してくれる。
$ vmc update segu-hello
Uploading Application:
  Checking for available resources: OK
  Packing application: OK
  Uploading (0K): OK
Push Status: OK
Stopping Application: OK
Staging Application: OK
Starting Application: OK

9. vmc

$ vmc help
で色々出てくる。

自分の情報を見るには
$ vmc info

VMware's Cloud Application Platform
For support visit support@cloudfoundry.com

Target:   http://api.cloudfoundry.com (v0.999)
Client:   v0.3.10

User:     ****@segu.jp
Usage:    Memory   (128.0M of 2.0G total)
          Services (0 of 16 total)
          Apps     (1 of 20 total)
ふむふむ。アプリは 20 コまでアップ可能で、メモリは合計 2.0GB でやりくりする必要があるらしい。

メモリもったいない!アプリ消したい!ときは
$ vmc delete segu-hello

パスワード変えたい!
$ vmc passwd
Changing password for '****@segu.jp'
New Password: ********
Verify Password: ********

Successfully changed password

何をアップしたか確かめたい!URL忘れた!
$ vmc apps

+-------------+----+---------+-----------------------------+----------+
| Application | #  | Health  | URLS                        | Services |
+-------------+----+---------+-----------------------------+----------+
| segu-hello  | 1  | RUNNING | segu-hello.cloudfoundry.com |          |
+-------------+----+---------+-----------------------------+----------+

アプリ名間違った!変えたい!
$ vmc rename segu-hello segu-goodbye
Renaming Appliction:
Error 301: Application not found
あら、動かないわ!

rubyだけなの!?
$ vmc runtimes

+--------+-------------+-----------+
| Name   | Description | Version   |
+--------+-------------+-----------+
| node   | Node.js     | 0.4.5     |
| ruby18 | Ruby 1.8    | 1.8.7     |
| ruby19 | Ruby 1.9    | 1.9.2p180 |
| java   | Java 6      | 1.6       |
+--------+-------------+-----------+
あら、これはきっと Node.js に挑戦しなさいというお告げ。今度やる。

0 件のコメント:

コメントを投稿