• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

 名前は聞いたことがあったもののどんなものかよく分かってなかったので、下記チュートリアルページを参考にCloud Foundryを触ってみました。

VMware Cloud Foundry入門 - Getting Started (Japanese)

 Cloud FoundryはVMwareが提供しているオープンソースのPaaSフレームワークで、ソースコードを取得してPaaS環境を構築できるほか、VMwareがvSphereデータセンター内で運営しているCloud Foundryのホステッド環境に接続することができます。現在はβ版ということで、無料で利用できるようです。

 まずは http://www.cloudfoundry.com/ でメールアドレスを登録してサインアップ。すぐに「Welcome to Cloud Foundry」という件名のメールが届きますが、これは登録を受け付けたというだけで、実際にアカウントが用意されて使用可能になるのはしばらくして「Welcome to Cloud Foundry - Your signup is approved!」という件名のメールでパスワードが届いてからになります。私の場合は2日ほどで届きました。

 とりあえず自宅PCのWindows環境で試してみました。まず http://www.rubyinstaller.org/ から rubyinstaller-1.9.3-p0.exe をダウンロードしてRubyをインストールします。

sh>>
C:\Users\akanuma>ruby -version
ruby 1.9.3p0 (2011-10-30) [i386-mingw32]
-e:1:in <main>': undefined local variable or method rsion' for main:Object (NameError)
<<--

なにやらエラーが出ていますが、とりあえず続行。

Cloud FoundryのCLIであるvmcをインストールします。

sh>>
C:\Users\akanuma>gem install vmc
Fetching: spruz-0.2.13.gem (100%)
Fetching: json_pure-1.5.4.gem (100%)
Fetching: rubyzip2-2.0.1.gem (100%)
Fetching: mime-types-1.17.2.gem (100%)
Fetching: rest-client-1.6.7.gem (100%)
Fetching: terminal-table-1.4.4.gem (100%)
Fetching: interact-0.2.gem (100%)
Fetching: vmc-0.3.13.gem (100%)
Successfully installed spruz-0.2.13
Successfully installed json_pure-1.5.4
Successfully installed rubyzip2-2.0.1
Successfully installed mime-types-1.17.2
Successfully installed rest-client-1.6.7
Successfully installed terminal-table-1.4.4
Successfully installed interact-0.2
Successfully installed vmc-0.3.13
8 gems installed
Installing ri documentation for spruz-0.2.13...
Installing ri documentation for json_pure-1.5.4...
Installing ri documentation for rubyzip2-2.0.1...
Installing ri documentation for mime-types-1.17.2...
Installing ri documentation for rest-client-1.6.7...
unable to convert "\xE2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for README.rdoc, skipping
Installing ri documentation for terminal-table-1.4.4...
Installing ri documentation for interact-0.2...
Installing ri documentation for vmc-0.3.13...
Installing RDoc documentation for spruz-0.2.13...
Installing RDoc documentation for json_pure-1.5.4...
Installing RDoc documentation for rubyzip2-2.0.1...
Installing RDoc documentation for mime-types-1.17.2...
Installing RDoc documentation for rest-client-1.6.7...
unable to convert "\xE2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for README.rdoc, skipping
Installing RDoc documentation for terminal-table-1.4.4...
Installing RDoc documentation for interact-0.2...
Installing RDoc documentation for vmc-0.3.13...
<<--

vmcのtargetコマンドでデプロイ対象を api.cloudfoundry.com に設定します。

sh>>
C:\Users\akanuma>vmc target api.cloudfoundry.com
Succesfully targeted to [http://api.cloudfoundry.com]
<<--

続けてログインコマンドを実行します。

sh>>
C:\Users\akanuma>vmc login
Email: xxxxxxxxxx@xxxxx.xxx
Password: ********
Successfully logged into [http://api.cloudfoundry.com]
<<--

そしてアプリケーションを作成するためのディレクトリを作成して移動します。

sh>>
C:\Users\akanuma>mkdir hello
C:\Users\akanuma>cd hello
C:\Users\akanuma\hello>
<<--

次にhllo.rbという名前で下記内容のファイルを作成します。文字コードはUTF-8で、改行コードはLFにしないと失敗するようです。

ruby>>
require 'sinatra'
get '/' do
"Hello from Cloud Foundry!"
end
<<--

アプリケーションをデプロイします。vmc pushコマンドを実行すると追加の情報入力用のプロンプトが表示されますので、それぞれ下記のように入力します。

sh>>
C:\Users\akanuma\hello>vmc push
Would you like to deploy from the current directory? [Yn]:
Application Name: akanumahello
Application Deployed URL ["akanumahello.cloudfoundry.com"]:
Detected a Sinatra Application, is this correct? [Yn]:
Memory Reservation ("64M", "128M", "256M", "512M", "1G", "2G") ["128M"]:
Creating Application: OK
Would you like to bind any services to 'akanumahello'? [yN]:
Uploading Application:
Checking for available resources: OK
Packing application: OK
Uploading (0K): OK
Push Status: OK
Staging Application: OK
Starting Application: OK
<<--

無事デプロイされたようです。ブラウザで http://akanumahello.cloudfoundry.com/ にアクセスして「Hello from Cloud Foundry!」と表示されればひとまず成功です。

続けて変更を加えてみます。hello.rbの "Hello from Cloud Foundry!" を "Hello from Cloud Foundry and VMware!" に変更して保存します。そして下記コマンドでサーバ上に変更を反映します。

sh>>
C:\Users\akanuma\hello>vmc update akanumahello
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
<<--

ブラウザで再度表示を確認して、変更が反映されていれば成功です。

このチュートリアルを試す限りは簡単にアプリケーションを公開できそうです。メモリも2GBまでは使えるようですので、あまり負荷の高くないアプリケーションであれば十分に使えそうです。

posted by akanuma akanuma on Sun 11 Dec 2011 at 18:58 with 0 comments
Contents rssrss
[Rails]to_travel は DateTime.now に対応してない
[Rails]RailsアプリにPassengerから環境変数を渡す
[Rails]Rails4 で datetimepicker を使う
[Vagrant] VM上のUbuntuから名前解決できない
[Rails]Passengerがgitからinstallしたgemを認識しない
[Rails][MessagePack] APIレスポンスとしてのMessagePack検証
[mongodb][couchbase] MongoDBとCouchbaseを比べてみました
[Rails][MySQL] RailsでMySQLを使う
[MySQL] MacにMySQLをインストール
[Rails] APサーバの比較検証(Puma, Unicorn, Passenger)
Tags
railsPassengermysqlRails,Ruby,bootstrapChefCouchbasedatetimepickerMessagePackMongoDBnginxPuma,RSpecrubyubuntuUnicorn,Vagrant
Comments rssrss
yoku0825 yoku0825: nkfの方が使いやすいですが、glibcに含まれているiconvの方が 確実にどの環境にも入っている... 06/11 07:03
Hiroaki Akanuma Hiroaki Akanuma: ご指摘ありがとうございます。「嗜好度は大きい値がより嗜好度が強いことを意味すればどのような値でもよい... 11/08 12:50
akr akr: 初めての推薦エンジンのところ 「属性データはどんなものでも可能。」 は preference val... 11/08 11:18
Services from s21g
YOMU Web小説リーダー
Web小説を音声で楽しむ読み上げリーダー
補助探
公開されている補助金・助成金情報を集約し、条件に合う制度を探しやすくするサービスです。
jotter.me
個人開発者のためのホスティング一体型ノートサービス
ハンドミラー
iPhone向けの手鏡アプリ
ツイプロ(twpro)
Twitterプロフィールの高速検索エンジン