Bluemix Question and Answer アプリをデプロイしてみよう
この記事は1年以上前に投稿されました。情報が古い可能性がありますので、ご注意ください。
前回はCLIの導入まででしたので、引き続きデモアプリのデプロイを進めていきます。
まずはこちらからデモアプリのコードアーカイブをダウンロードし解凍します。今回はNode.jsで書かれたものを対象とします。ドキュメントページにはJava版とRuby版もそれぞれありますので、お好みのものをお使いください。
ディレクトリ構造は以下となっています。
qa-nodejs.git
├── NOTICE.txt
├── README.txt
├── app.js
├── manifest.yml
├── package.json
├── public
│   ├── css
│   │   ├── browser-compatibility.css
│   │   ├── style.css
│   │   ├── watson-bootstrap-dark.css
│   │   └── watson-documentation.css
│   ├── images
│   │   ├── app.png
│   │   └── favicon.ico
│   └── js
│       ├── css_browser_selector.js
│       ├── example_input.js
│       └── jquery-1.11.1.min.js
└── views
    ├── index.jade
    └── layout.jade
このうち"app.js"がExpressを用いたWeb Server機能と、QAAPIへの問合せなどの主な処理を担っています。次に"manifest.yml"ですが、こちらがBluemixへデプロイする際のアプリケーション設定ファイルになります。ダウンロードした時点では以下の内容となっていますが、デプロイに合わせて変更します。
applications:
- services:
  - qa-service
  name: qa-nodejs
  command: node app.js
  path: .
  memory: 128M
まず"applications - services"配下の "qa-service" は、Question and Answerサービスに対する名称です。このままでも構いませんし、任意の名前に変更することも可能ですが、この後サービスの登録の際に使用しますので覚えておいてください。次に"applications"の"name"にある"qa-nodejs" ですが、こちらは"mybluemix.net"ドメインにて一意となる名称である必要がありますので変更しましょう。今回は"qa-nodejs-cl"とします。また"memory"については最小の"64M"としておきます。
それではBluemixにデプロイしましょう。まずAPIエンドポイントを確認しておきます。
$ cf api
API endpoint: https://api.eu-gb.bluemix.net (API version: 2.19.0)
例のように英国を指していた場合もコマンドで変更が可能ですが、今回はログイン時に指定する方法でログインします。
$ cf login -a https://api.ng.bluemix.net -u bluemix@creationline.com
API endpoint: https://api.ng.bluemix.net
Password>
Authenticating...
OK
Targeted org bluemix-org
Targeted space US-South
API endpoint:   https://api.ng.bluemix.net (API version: 2.19.0)
User:           bluemix@creationline.com
Org:            bluemix-org
Space:          US-South
-a がエンドポイント指定オプション、-u がユーザ名指定オプションです。
次にサービスの一覧を表示します。多少時間がかかるかもしれません。
$ cf marketplace
Getting services from marketplace in org bluemix-org / space US-South as bluemix@creationline.com...
OK
service                     plans                                                                               description
API Management              APImFreePlan                                                                        Publish, manage, and consume APIs.
AdvancedMobileAccess        Free                                                                                Tune iOS 8 apps with operational analytics, and ensure communications with back end systems are secure.
AlchemyAPI                  user-provided*                                                                      Build smart apps that leverage natural language processing and computer vision to deeply understand the world's conversations, documents and photos.
...(中略)...
question_and_answer         question_and_answer_free_plan                                                       Direct responses to users inquiries fueled by primary document sources
...(中略)...
* The denoted service plans have specific costs associated with them. If a service instance of this type is created, a cost will be incurred.
TIP:  Use 'cf marketplace -s SERVICE' to view descriptions of individual plans of a given service.
ここにQuestion and Anserサービスの名称とプランが表示されますのでこれらを指定して先ほどのサービス名を指定してサービスを作成します。
$ cf create-service question_and_answer question_and_answer_free_plan qa-service
Creating service qa-service in org bluemix-org / space US-South as bluemix@creationline.com...
OK
サービスがまだアプリケーションにバインドされていない状態であることが確認できます。
$ cf services
Getting services in org bluemix-org / space US-South as bluemix@creationline.com...
OK
name         service               plan                            bound apps   last operation
qa-service   question_and_answer   question_and_answer_free_plan                 succeeded
続けて解凍した"qa-nodejs.git"ディレクトリからアプリケーションをデプロイします。
$ cf push qa-nodejs-cl
Using manifest file /Users/bluemix/qa-nodejs.git/manifest.yml
Creating app qa-nodejs-cl in org bluemix-org / space US-South as bluemix@creationline.com...
OK
Creating route qa-nodejs-cl.mybluemix.net...
OK
Binding qa-nodejs-cl.mybluemix.net to qa-nodejs-cl...
OK
Uploading qa-nodejs-cl...
Uploading app files from: /Users/bluemix/qa-nodejs.git
Uploading 20.3K, 19 files
Done uploading
OK
Binding service qa-service to app qa-nodejs-cl in org bluemix-org / space US-South as bluemix@creationline.com...
OK
Starting app qa-nodejs-cl in org bluemix-org / space US-South as bluemix@creationline.com...
-----> Downloaded app package (72K)
-----> Node.js Buildpack Version: v1.13-20150206-1347
-----> Requested node range:  0.10.26
-----> Resolved node version: 0.10.26
-----> Installing IBM SDK for Node.js from cache
...(中略)...
0 of 1 instances running, 1 starting
1 of 1 instances running
App started
OK
App qa-nodejs-cl was started using this command `node app.js`
Showing health and status for app qa-nodejs-cl in org bluemix-org / space US-South as bluemix@creationline.com...
OK
requested state: started
instances: 1/1
usage: 64M x 1 instances
urls: qa-nodejs-cl.mybluemix.net
package uploaded: Wed Mar 11 07:06:17 +0000 2015
     state     since                    cpu    memory         disk          details
#0   running   2015-03-11 04:07:29 PM   0.0%   21.7M of 64M   33.9M of 1G
"manifest.yml"の内容に合わせてアプリケーションとサービスのバインドまで含めてデプロイされアプリが起動しました。コマンドでも確認可能です。
$ cf services
Getting services in org bluemix-org / space US-South as bluemix@creationline.com...
OK
name         service               plan                            bound apps     last operation
qa-service   question_and_answer   question_and_answer_free_plan   qa-nodejs-cl    succeeded
$ cf apps
Getting apps in org bluemix-org / space US-South as bluemix@creationline.com...
OK
name           requested state   instances   memory   disk   urls
qa-nodejs-cl   started           1/1         64M      1G     qa-nodejs-cl.mybluemix.net
それではデプロイしたアプリにアクセスしてみましょう。
http://qa-nodejs-cl.mybluemix.net/
いかがでしたか?アプリを1から書くのも良いですが、他のサービスのデモアプリや、developerWorksなどで多数紹介されているアプリを試すところから始めるのも良いかもしれません。
そして、Bluemixについてより広く深く知りたいという方々へ、第0回 Bluemixユーザー会が開催されます。空席が残り僅かですので、気になる方はお早めに。
