コマンドラインツールのインストール
- コマンドラインツールは Ruby の gem パッケージとして提供されています。
- gem はインストール済みだったので以下のコマンドだけでインストールできました。
gem install af
ログイン
- コマンドラインから AppFog にログインします。
- メールアドレスとパスワードを求められるので入力してください。
af login
ユーザー情報表示
af info
AppFog Free Your Cloud Edition
For support visit http://support.appfog.com
Target: https://api.appfog.com (v0.999)
Client: v0.3.18.12
User: **********
Usage: Memory (192.0M of 2.0G total)
Services (1 of 8 total)
Apps (2 of 9999 total)
- さっそく CakePHP アプリケーションを AppFog 上にデプロイします。
- まずはアプリケーションのルートディレクトリに cd してください。
- その後 `af push` コマンドで AppFog アプリケーションの作成と CakePHP アプリケーションのアップロードが行われます。
% af push
Would you like to deploy from the current directory? [Yn]: Y
Application Name: APP_NAME
Detected a PHP Application, is this correct? [Yn]: Y
1: AWS US East - Virginia
2: AWS EU West - Ireland
3: AWS Asia SE - Singapore
4: Rackspace AZ 1 - Dallas
5: HP AZ 2 - Las Vegas
Select Infrastructure: 3
Application Deployed URL [APP_NAME.ap01.aws.af.cm]:
Memory reservation (128M, 256M, 512M, 1G, 2G) [128M]:
How many instances? [1]:
Create services to bind to 'APP_NAME'? [yN]: Y
1: mongodb
2: mysql
3: postgresql
4: rabbitmq
5: redis
What kind of service?: 2
Specify the name of the service [mysql-*****]:
Create another? [yN]: N
Would you like to save this configuration? [yN]: Y
Manifest written to manifest.yml.
Creating Application: OK
Creating Service [mysql-*****]: OK
Binding Service [mysql-*****]: OK
Uploading Application:
Checking for available resources: OK
Processing resources: OK
Packing application: OK
Uploading (63K): OK
Push Status: OK
Staging Application 'APP_NAME': OK
Starting Application 'APP_NAME': OK
* アプリケーション一覧の表示
- コマンドラインからアプリケーション一覧を表示してアプリが作成できたか確認できます。
>|sh|
af apps
DB設定ファイルを AppFog に対応
<?php
class DATABASE_CONFIG {
public $default;
public $test;
function __construct() {
if (getenv("VCAP_SERVICES")) {
$services_json = json_decode(getenv("VCAP_SERVICES"),true);
$mysql_config = $services_json["mysql-5.1"][0]["credentials"];
$this->default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => $mysql_config["hostname"],
'login' => $mysql_config["username"],
'password' => $mysql_config["password"],
'database' => $mysql_config["name"],
'prefix' => '',
'encoding' => 'utf8',
);
$this->test = array();
} else {
$this->default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => '*****',
'password' => '*****',
'database' => '*****',
'prefix' => '',
'encoding' => 'utf8',
);
$this->test = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => '*****',
'password' => '*****',
'database' => '*****',
'prefix' => '',
'encoding' => 'utf8',
);
}
}
}
DB設定ファイルの更新
- 変更した database.php は `af update` で AppFog にアップロードします。
af update
開発DBのデータをMySQLサービスに入れる
必要ライブラリのインストール
- `af tunnel` コマンドに必要なライブラリをインストールします。
gem install caldecott
MySQLサービスにトンネルを張る
% af tunnel
1: mysql-*****
Which service to tunnel to?: 1
Getting tunnel connection info: OK
Service connection info:
username : **********
password : **********
name : **********
infra : ap-aws
Starting tunnel to mysql-***** on port 10000.
1: none
2: mysql
3: mysqldump
Which client would you like to start?: 1
Open another shell to run command-line clients or
use a UI tool to connect using the displayed information.
Press Ctrl-C to exit...
** 別の端末で接続確認
- `af tunnel` 実行時に表示された接続情報を使って MySQL サービスに接続します。
>|sh|
mysql --protocol=TCP --host=localhost --port=10000 --user="ユーザー名" --password="パスワード" "DB名"
開発DBのデータをダンプ
mysqldump -uroot DB_NAME > DB_NAME.out
MySQLサービスにデータを入れる
mysql --protocol=TCP --host=localhost --port=10000 --user="ユーザー名" --password="パスワード" "DB名" < DB_NAME.out
さいごに
- 登録から公開まで、特にはまることなく作業することができたので、とても扱いやすいサービスだと感じました。
- 無料でもいろいろできそうなので、とりあえずの実験的なアプリの公開先に使っていきたいです。