##はじめに
OpenShiftはHerokuと同じくPaaS(Platform as a Service)の一つで、無料でWebアプリを公開したりするときによく利用されます。有料プランももちろんあります。OpenShift
の場合は、3つのアプリまで無料という感じっぽいです。
Heroku
で新料金が発表されたこともあり、移行先が検討されはじめてる感じします。
##使い方
まず、アカウントの作成からです。
アカウントを作成したら、CLIツールでアプリ開発からアップロードまでを行います。
$ ruby -v
2.2.0
$ gem install rhc
# SSH鍵などの登録を行います
$ rhc setup
If you have your own OpenShift server, you can specify it now. Just hit enter to use the server for OpenShift Online: openshift.redhat.com.
#あなたがあなた自身のOpenShiftサーバーを持っている場合は、ここで指定することができます。 openshift.redhat.com:ちょうどOpenShift Onlineのサーバーを使用するためにEnterを叩いてください。
Applications are grouped into domains - each domain has a unique name (called a namespace) that becomes part of your public application URL. You may
create your first domain here or leave it blank and use 'rhc create-domain' later. You will not be able to create an application without completing
this step.
#アプリケーションは、ドメインにグループ化されている - 各ドメインは、公開アプリケーションのURLの一部になります(名前空間と呼ばれる)は、一意の名前を持っています。
#ここにあなたの最初のドメインを作成したり、それを空白のままにして、「作成ドメインをRHC」以降を使用します。あなたが完了せずにアプリケーションを作成することができません。
Please enter a namespace (letters and numbers only) |<none>|:
#名前空間(文字と数字のみ)を入力してください|<なし>|:
#私の場合はUserNameを入力しました。ドメインの一部になるのでUserNameがお勧めです
次にアプリの作成と公開です。使用言語はドキュメントに詳しく書いてあります。
$ rhc create-app home nodejs-0.10
Cloning into 'home'...
The authenticity of host 'home-XXXX.rhcloud.com (255.255.255.1)' can't be established.
RSA key fingerprint is SHA256:Ifdiisdfid5isfdhaihgrahvuiarheUsdfsadsaDD.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'home-XXXX.rhcloud.com,255.255.255.1' (RSA) to the list of known hosts.
# 先ほど作ったアプリのルートに移動して、Gitのリモートリポジトリを一応確認しておく。
$ cd ./home/
$ git remote -v
$ echo node_modules > .gitignore
$ npm install
$ node server
--------------------------------------
$ curl 127.0.0.1:8080
$ grep -R self.ipaddress .
self.ipaddress = process.env.OPENSHIFT_NODEJS_IP;
$ grep -R self.port .
self.port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
$ git push origin master
参考