FPGA開発日記

カテゴリ別記事インデックス https://msyksphinz.github.io/github_pages , English Version https://fpgadevdiary.hatenadiary.com/

Hashicorp社の新しい仮想開発環境"Otto"をさっそく触ってみた

タイムリーなので。

Otto - HashiCorp

突然ですが僕はかなりのヘビーなVagrantユーザーで、僕の全ての開発環境はVagrant上に構築され、Chefでクロスコンパイル環境も自動的に構築されるようにしている。 いくらWindowsを再インストールしても、githubから自分のVagrantの環境を落としてきてprovisionすれば、開発環境が構築される。すばらしい!

github.com

そんなVagrantヘビーユーザの僕が、「Successor of Vagrant」などと言わたもんだから、発表初日にOttoを使ってみるに決まっている!

Today we announce Otto — the successor to Vagrant. Otto is the single solution to develop and deploy any application, with first class support for microservices. It is the most powerful tool we've built yet.

Ottoの概要に触れる

いろんな記事を読む限り、開発環境からデプロイまで一気通貫するためのツールらしい。 Vagrantで開発環境は整えてはいるが、確かにデプロイまではきちんとやっていない。というか趣味のツールを作るために環境を構築しているので、デプロイすることは殆どない。

とは言え、何が出来るのか見てみよう。まずは日本語のページから。

dev.classmethod.jp

サンプルが用意されているらしい。サンプルの環境ではRubyをデプロイしたようだ。

Ottoのキモとされているのが、アプリケーションを自動的に認識し、自動的に開発環境を構築するところだ。確かにサンプルでは、Rubyの環境を構築している。 otto compileで自動的に環境を認識している。

$ 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...
==> 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.
    These files can be manually inspected to determine what Otto will do.

ちなみに最後に構築されている開発環境はUbuntu12.04LTS だ。ここらへんのチョイスは良く分からない。

...
==> Caching SSH credentials from Vagrant...
==> Development environment successfully created!
    IP address: 172.16.1.26

    A development environment has been created for writing a generic
    Ruby-based app.

    Ruby is pre-installed. To work on your project, edit files locally on your
    own machine. The file changes will be synced to the development environment.

    When you're ready to build your project, run 'otto dev ssh' to enter
    the development environment. You'll be placed directly into the working
    directory where you can run 'bundle' and 'ruby' as you normally would.

    You can access any running web application using the IP above.
$ otto dev ssh
==> Executing SSH. This may take a few seconds...
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64)

 * Documentation:  https://help.ubuntu.com/
New release '14.04.3 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Welcome to your Vagrant-built virtual machine.
Last login: Tue Sep 29 14:38:29 2015 from 10.0.2.2

これ、サンプルだと非常にシンプルな状態で、ディレクトリにもapp.rbとかしかない。 だけど現実ではそんなことなくて、例えば僕はC++でアプリケーションを開発しているのだけれども、それでもうまくいくんだろうか? Appfileの構文も眺めてみたが、あまりにもシンプルで不安になってきた。

ちょっと自分のプロジェクトを使って、開発環境の構築に挑戦してみよう。

Ottoを使って、C++アプリケーションの開発環境を自動的に構築することはできるのか?

僕はC++で、MIPSRISC-Vの命令セットシミュレータを開発している。これの開発環境もVagrantとChefで自動構築されるようになっている。 これをOttoで置き換えることはできるだろうか?

github.com

まずはAppfile無しで何が出来るか確かめる

最初に、僕のプロジェクトの階層は以下のようになっている。

$ tree . -L 2
.
└── swimmer_riscv
    ├── benchmarks
    ├── build_mips
    ├── build_riscv
    ├── README.md
    ├── src
    └── vendor

6 directories, 1 files

srcの所にC++ファイルが大量に入っており、build_mips, build_riscvの所にはCMakeLists.txt、つまりビルド専用のディレクトリを作っている。 これはgccなどをビルドするときに、buildするディレクトリと実際のソースのディレクトリを分けてconfigureするのをまねている。

じゃあ、まずはどこでotto compileすれば良い?

$ 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.
No Appfile is present and Otto couldn't detect the project type automatically.
Otto does its best without an Appfile to detect what kind of project this is
automatically, but sometimes this fails if the project is in a structure
Otto doesn't recognize or its a project type that Otto doesn't yet support.

Please create an Appfile and specify at a minimum the project type. Below
is an example minimal Appfile specifying the "go" project type:

    application {
        type = "go"
    }

If you believe Otto should've been able to automatically detect your
project type, then please open an issue with the Otto project.

プロジェクトのトップ階層でやっても、もちろんOttoは自分でアプリケーションのタイプを認識することはできない。そりゃそーだ。 じゃあ、srcディレクトリに移って、compileしてみよう。

cd src
$ 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:    src (ruby)
    Project:        src
    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.
    These files can be manually inspected to determine what Otto will do.

あ、、、れ、、、Rubyとして認識された。 よく考えれば、そりゃそうだ。いくつかC++ソースを自動生成するために、Rubyスクリプトが入っている、Ottoはそれを検出して、Rubyのプロジェクトと勘違いしたという訳か。

ちなみに、build_mips, build_riscv など、Makefileが存在している場所でotto compileをしても同様にうまく認識されない。

cd ../build_mips
$ 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.
No Appfile is present and Otto couldn't detect the project type automatically.
Otto does its best without an Appfile to detect what kind of project this is
automatically, but sometimes this fails if the project is in a structure
Otto doesn't recognize or its a project type that Otto doesn't yet support.

Please create an Appfile and specify at a minimum the project type. Below
is an example minimal Appfile specifying the "go" project type:

    application {
        type = "go"
    }

If you believe Otto should've been able to automatically detect your
project type, then please open an issue with the Otto project.

やはり、Appfileを記述しないとダメか、、、ということで、次回はAppfileでプロジェクトのビルドに挑戦してみよう。