このビックウェーブに乗るしかないということで、やってみました。
ottoの設置
適当なディレクトリにダウンロードしてきて解凍してあげれば大丈夫です。
$ cd ~/bin
$ wget -qO- -O tmp.zip https://dl.bintray.com/mitchellh/otto/otto_0.1.1_darwin_amd64.zip && unzip tmp.zip && rm -rf tmp.zip
symfony2のインストール
今回はsymfonyコマンドでインストールします。
$ symfony new otto_symfony2
ottoを使ってみる
ottoを使うときにAppfileが必要らしいので配置する
$ cd otto_symfony2
$ vi Appfile
application {
  name = "otto-symfony2"
  type = "php"
}
そして、compliteコマンドを実行するだけ
otto compile
==> Loading Appfile...
==> Fetching all Appfile dependencies...
==> Compiling...
    Application:    otto-symfony2 (php)
    Project:        otto_symfony2
    Infrastructure: aws (simple)
    Compiling infra...
    Compiling foundation: consul
==> Compiling main application...
==> Compilation success!
    This means that Otto is now ready to start a development environment,
    deploy this application, build the supporting infastructure, and
    more. See the help for more information.
    Supporting files to enable Otto to manage your application from
    development to deployment have been placed in the output directory.
開発環境を作る
devコマンドだけで、開発環境がつくれちゃうなんて素晴らしいい!!!
$ otto dev
==> Creating local development environment with Vagrant if it doesn't exist...
    Raw Vagrant output will begin streaming in below. Otto does
    not create this output. It is mirrored directly from Vagrant
    while the development environment is being created.
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'hashicorp/precise64' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'hashicorp/precise64'
.
.
.
(略)
==> Development environment successfully created!
    IP address: 172.16.1.35
    A development environment has been created for writing a PHP app.
    Edit files locally on your machine, the file changes will be synced
    to the development environment automatically.
    To run and view your application, run 'otto dev ssh' to enter the
    development environment. You'll be placed directly into the working
    directory where you can run "composer", "php", etc.
    You can access the environment from this machine using the IP address above.
    For example, if you start your app with 'php -S 0.0.0.0:5000', then you can
    access it using the above IP at port 5000.
そして、ビルトインサーバーで動かすので、sshで接続します。
$ otto dev ssh 
$ app/console server:start 0.0.0.0:8000
アドレスを確認する
$ otto dev address
172.16.1.35
ちゃんとsymfony2のページが表示されました!
めっちゃ簡単w
停止
dev環境のvagrantを停止する場合は
$ otto dev vagrant halt
って書きます。
つーか、otto dev vagrantでvagrantコマンド使えます。
削除
削除したいって時は次のコマンド実行すればいいです
$ otto dev destroy
バージョン指定
customizationでバージョン指定すればいけるかなぁーとおもったんですが、devだと無理ぽい。。。
あとで調べます。
mysqlが使いたいんです
dependencyで指定すれば、動かすことができます。
ミドルウェア的なものはどうやらdependencyで解決できるようです。
dockerのイメージ使えるし結構便利です。
application {
  name = "otto-symfony2"
  type = "php"
  dependency {
      source = "github.com/polidog/otto-mysql-5.6"
  }
}
$ otto compile
symfonyg側のparameters.ymlでdbの接続先とか変えておけば、使えます。
# This file is auto-generated during the composer install
parameters:
    database_host: dev
    database_port: null
    database_name: otto_symfony2
    database_user: root
    database_password: root
devのphp環境ってどうやって構築されているのだろうか?
ちょっと疑問に思ったので、調べてみました。
を見る感じだとubuntu-12.04みたいですね。
phpのパッケージは
- php5-mcrypt
 - php5-mysql
 - php5-fpm
 - php5-gd
 - php5-readline
 - php5-pgsql
 
みたいです。
ちなみにotto dev sshで接続するとどうやらphp-fpmが起動してみるみたいです。
$ otto dev ssh
vagrant@precise64:/vagrant$ ps aux | grep php
root      9563  0.0  4.4 334180 16816 ?        Ss   18:05   0:00 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)
こうなってくるとnginx欲しくなる。
ビルトインサーバあまり使いたくないし・・・。
ちなみにビルドするとapacheはいるのかな?
https://github.com/hashicorp/otto/blob/master/builtin/app/php/data/aws-simple/build/build-php.sh.tpl
とりあえず、devまわりはもう少し自由が欲しいところです・・・
現状はchefとかpuppetとかansibleとかプロビジョニングツール使ったほうがいいかも。
デプロイ
めんどいからまた今度・・・laravelの記事読めば大体わかるかと・・・w
気が向いたら追記します。
最後に
確かに簡単に実行環境を用意できるし便利なツールです。
しかし、細かい設定ができないのがちょっと辛いけど・・・
今後のottoに期待しています!
