LoginSignup
8
9

More than 5 years have passed since last update.

otto での Ruby & mysql 環境の構築について

Posted at

otto ではotto compile時に自動でアプリケーションのタイプ(言語等)を判別する機能がある。
Ruby 環境の判別基準は以下。

  • *.rb のファイルがある
  • Gemfile がある
  • config.ru がある

自動判別ではなく、明示的にRubyであることを伝える方法もある。
以下のようにAppfileを作成する。

application {
    name = "test-app"
    type = "ruby"
}

これで、otto compile時にRubyと判別されるようになる、

ottoでRubyアプリだと判断した場合に、
自動でRubyアプリに必要なミドルウェア、ライブラリ等を含めた上でVMを立ち上げてくれるわけだが、
Rubyに必要なモノはなんなのか?
デフォルトで入るモノは以下。

  • Ruby(現在は 2.2.3 の最新) and RubyGems
  • bundler
  • node.js
  • git,mercurial
  • postgreSQL dev headers

また、Rubyのgem installに必要なライブラリ等も入っている。(libxmlとか)
以下のように記述することで特定のversionを指定することもできます。

customization "ruby" {
    ruby_version = "2.1"
}

mysql を含めたtype ruby のvm作成

otto では dependency として別でcompileしたAppfileを含める事ができる。
以下は、type docker で、mysqlを起動するAppfileを依存として記載している。
(このやり方が正しいのかはわかりませんが、好きではない・・・。)

application {
    name = "test-app"
    type = "ruby"

    dependency {
        source = "github.com/tamai/otto-mysql"
    }
}

以下のコマンドでvmを作成

otto compile
otto dev

作成されたvmに入ります。
残念ながら、mysqlクライアントは入らない為、手動で入れます。

otto dev ssh
sudo apt-get install mysql-client-core-5.5

以下のコマンドでdb接続可能

mysql -h 172.16.1.92 -u root -p

IPアドレスは以下のコマンドで確認可能。

otto dev address

8
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
9