Tech Trier Blog

エンジニアとして「好奇心」のおもくまま、いろいろやったり調べたりするブログです。

【otto compile】 Ottoを試して理解する(その1)

Ottoは、Vagrantを開発したHashi corpの次世代ツールです。

Otto by HashiCorp

主な特徴を調べて、トライしてみました。

Ottoとは

アプリケーションの開発環境を整え、開発し、セキュリティの設定を行い、アプリケーションをクラウドにデプロイするまでの一連の作業を、ベストプラクティスに基づいて自動化するツールです。現在、複数ツールを使って行われる作業を、Otto一つに集約することができます。 Vagrantと並行して開発を進めていくようです。

主な特徴

  • 開発環境の自動化:Ottoは開発中のアプリケーションのタイプを検出し、そのアプリケーションに最適化された開発環境を設定なし(または最小限の設定)で立ち上げます。

  • Micro servicesに最適:Ottoはソフトウェア間の依存関係やバージョンを自動的に理解して、その依存関係をどんな環境にもデプロイし、設定することができます。

Micro servicesとは、単一機能のサービスが連携してアプリケーションを構成する手法。Unixの理念に根付いています。

33rd Degree - Conference for Java Masters - Micro services - Java, the Unix Way

  • デプロイ:Ottoは開発中のアプリがmicroservicesでも、モノリシックなタイプでも、うまいことデプロイするやり方を知っています。

  • Docker:OttoはDockerを使ってアプリケーションを自動的にコンテナ化することができます。

  • ツール:開発環境構築にはVagrantを、サーバー起動にはTerraformを、サーバ設定にはConsulを使います。これらツールのインストールと管理はOttoが自動で行います。

Ottoを試してみる

試したOS: Windows 10 (64bit)

事前準備

トライアルにgitを使う必要があるので、git for windowsをインストールしておきます。

また、WindowsではVagrantの自動インストールに対応していないようです。 otto実行中にこのメッセージを見ることになります。 事前に、VagrantVirtualBoxをインストールしておくのが良いです。

Ottoのダウンロードとインストール

Download Otto - Otto by HashiCorp

2016/1/16現在のバージョンは0.2です。 ダウンロードしたバイナリを、パスの通った場所に置く必要があります。

Windows10での環境変数設定

ちなみに、環境変数の設定方法は、 windows + xを押した後に、

コントロールパネル - コントロールパネルの検索窓に環境変数と入力 - システム環境変数の編集を選択

PATHで設定されているパス一覧がとっても見やすいのは、Windows10の良いところです。

インストールの確認

コマンドプロンプトを開き、 ottoと入力してみましょう。

C:\Users\u1bell>otto
usage: otto [--version] [--help] <command> [<args>]

Available commands are:
    build      Build the deployable artifact for the app
    compile    Prepares your project for being run
    deploy     Deploy the application
    dev        Start and manage a development environment
    infra      Builds the infrastructure for the Appfile
    status     Status of the stages of this application
    version    Prints the Otto version

試してみる

https://www.ottoproject.io/intro/getting-started/dev.html の内容に沿って、試してみます。

$ git clone https://github.com/hashicorp/otto-getting-started.git
$ cd otto-getting-started
$ otto compile
$ otto dev

実際にやってみると、

otto-getting-started>otto compile
==> Loading Appfile...
==> No Appfile found! Detecting project information...
    No Appfile was found. If there is no Appfile, Otto will do its best
    to detect the type of application this is and set reasonable defaults.
    This is a good way to get started with Otto, but over time we recommend
    writing a real Appfile since this will allow more complex customizations,
    the ability to reference dependencies, versioning, and more.
==> Fetching all Appfile dependencies...
==> Compiling...
    Application:    otto-getting-started (ruby)
    Project:        otto-getting-started
    Infrastructure: aws (simple)

    Compiling infra...
    Compiling foundation: consul
==> Compiling main application...
==> Detecting Ruby version to use...
    No desired Ruby version found! Will use the default: 2.2
==> Compilation success!
    This means that Otto is now ready to start a development environment,
    deploy this application, build the supporting infrastructure, 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.
    These files can be manually inspected to determine what Otto will do.

Rubyを使ったプロジェクトであることを、自動検出したようです。 指定がないので、Ruby2.2を使うよ、と言っています。

なお、Vagrantが未インストールだと、Vagrantをインストールしますか?と聞いてきます。 yesと答えましたが、このOSではVagrantの自動インストールに対応していません、マニュアルでお願いします、とのことでした。 この辺は、windowsのつらいところですね。。

ともあれ、compileは無事成功しました。

otto devに失敗。。

Windowsでのotto devに失敗しました。

==> Creating layer: consul
Bringing machine 'default' up with 'virtualbox' provider...
There are errors in the configuration of this machine. Please fix
the following errors and try again:

File provisioner:
* File upload source file C:/Users/Suzuki/.otto.d/global-data/vagrant-layered/layers/consul/UsersSuzukiottoFistTryotto-getting-started.ottompiledpp criptpacksSTDLIB.tar.gz must exist
* File upload source file C:/Users/Suzuki/.otto.d/global-data/vagrant-layered/layers/consul/UsersSuzukiottoFistTryotto-getting-started.ottompiledpp criptpacksRUBY.tar.gz must exist


Error building dev environment: Error building dev environment layers: Error executing Vagrant: exit status 1

The error messages from Vagrant are usually very informative.
Please read it carefully and fix any issues it mentions. If
the message isn't clear, please report this to the Otto project.

なにやら、otto compileで生成したはずのファイルが見つけられないようです。 ここに書いてあるのと同じことが起きています。 github.com

どうやら、自動生成するvagrantファイルでWindowsのファイルパスに含まれるバックスラッシュがエスケープ文字と認識されちゃう、というありがちなミスのようで、GitHub上ではすでに修正されているようです。

fix hashicorp/otto#391 · castaneai/otto@a960d1f · GitHub

Rubyのダブルクォーテーション(エスケープ文字が有効)とシングルクォーテーション(エスケープ文字無効)の使いどころを間違えるという、私もよくやるミスですね。 なんだか親近感がわきます。またVersion 0.2ですし、こういうのを楽しめなくちゃ好きものとは言えません。

仕方ありません。Github上のottoをコンパイルしてみますか。。 修正は、まだfix-fails-provisioning-on-windowsというブランチにあるようです。

git clone -b fix-fails-provisioning-on-windows ht
tps://github.com/castaneai/otto.git

今日はここまで!