前回までで、C++アプリケーションではOttoで自動的にプロジェクトを認識するのは難しいということが分かった。
では、Appfileを記述して、C++の環境を構築してみよう!
1. Appfileの文法を学ぶ
Appfileについては、Hashicorp社のサイトに説明が載っている。
記述できるブロックとしては、
- application: 開発しているアプリケーションについての情報を記述する。「名前」と「言語」だ。僕の場合は、ビルドするバイナリの名前と、C++を指定してみた。
- project: アプリケーションに結びついているプロジェクト、つまりどのインフラストラクチャに対してデプロイをするかという情報を記述している。 ここについては、AWSが例として上がっているが、僕はデプロイするつもりは無いので、まあ、いっか。
- infrastructure: インフラストラクチャはその名のとおりインフラの情報を記述する。これも、とりあえず無視。
- import: githubなどからの依存関係を記載できる。あれ、じゃあ、わざわざ最初に自分のプロジェクトをクローンしておかなくても、自動的にやってくれるのか?
2. Appfileを記述する
さっそく作ってみよう。僕のプロジェクト名と、言語の情報をまずは載せてみよう。
$ cat Appfile application { name = "swimmer_riscv" type = "c++" } $ otto compile ==> Loading Appfile... ==> Fetching all Appfile dependencies... ==> Compiling... Application: swimmer_riscv (c++) Project: otto-swimmer Infrastructure: aws (simple) Compiling infra... Compiling foundation: consul Error compiling: 1 error(s) occurred: * Error loading App implementation for 'swimmer_riscv': app implementation for tuple not found: ("c++", "aws", "simple")
え?C++で、この組み合わせの環境は無いだって?
C++では、AWSにデプロイするための環境は作れないということか?
いろいろ試して分かったことだが、Ottoは、どうやらデプロイの環境を重視して作られているようだ。そして現在はデプロイ先はAWSしかない。 したがって、AWSのアカウントを持っていることが推奨だし、それ以外では環境の構築もできない。
ちなみに、c++ではなく、rubyやgoを設定するとコンパイルに成功する。うーん、やっぱり、C++でデプロイする環境は作れないということね。 デプロイしなくていいから、プロジェクトにくっついた開発環境を自動的に構築できる、とかできないかなあ。
$ cat Appfile application { name = "swimmer_riscv" type = "ruby" } $ otto compile ==> Loading Appfile... ==> Fetching all Appfile dependencies... ==> Compiling... Application: swimmer_riscv (ruby) Project: otto-swimmer 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.
結論 : Ottoは、デプロイと非常に密接したツール。「開発」→「デプロイ(AWSに限定)」が密着したサービスの開発には使えるが、それ以外は柔軟性に難あり。Appfileの拡張に期待。
3. Import構文を使用して、自動的にプロジェクトをgithubから引っ張ってくることはできるのか?
さて、上記までは、プロジェクトをクローンしてからのAppfile記述だったが、import文を利用すると、そこも自動でやってくれるのだろうか? 例として、以下のようなAppfileを記述してみた。コンパイルを通すために、言語はRubyを指定してある。使うのはC++だけど。
$ cat Appfile import "github.com/msyksphinz/swimmer_riscv.git" {} application { name = "swimmer_riscv" type = "ruby" }
コンパイルはできるみたいだな。
$ otto compile ==> Loading Appfile... ==> Fetching all Appfile dependencies... ==> Compiling... Application: swimmer_riscv (ruby) Project: otto-swimmer2 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.
次は開発環境の構築だ。
$ otto dev [13/1998] ==> 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: Importing base box 'hashicorp/precise64'... ==> default: Matching MAC address for NAT networking... ==> default: Checking if box 'hashicorp/precise64' is up to date... ==> default: Setting the name of the VM: dev_default_1443543886497_56219 ==> default: Fixed port collision for 22 => 2222. Now on port 2200. ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat default: Adapter 2: hostonly ==> default: Forwarding ports... default: 22 => 2200 (adapter 1) ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2200 default: SSH username: vagrant default: SSH auth method: private key default: Warning: Connection timeout. Retrying... default: default: Vagrant insecure key detected. Vagrant will automatically replace default: this with a newly generated keypair for better security. default: default: Inserting generated public key within guest... default: Removing insecure key from the guest if it's present... default: Key inserted! Disconnecting and reconnecting using new SSH key... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... default: The guest additions on this VM do not match the installed version of default: VirtualBox! In most cases this is fine, but in rare cases it can default: prevent things such as shared folders from working properly. If you see default: shared folder errors, please make sure the guest additions within the default: virtual machine match the version of VirtualBox you have installed on default: your host and reload your VM. default: default: Guest Additions Version: 4.2.0 default: VirtualBox Version: 4.3 ==> default: Configuring and enabling network interfaces... ==> default: Mounting shared folders... default: /vagrant => C:/usr/work/otto_test/otto-swimmer2 default: /otto/foundation-1 => C:/usr/work/otto_test/otto-swimmer2/.otto/compiled/app/foundation-consul/app-dev ==> default: Running provisioner: shell... default: Running: inline script ==> default: stdin: is not a tty ==> default: [otto] Installing Consul... ==> default: [otto] Installing dnsmasq for Consul... ==> default: [otto] Configuring consul service: swimmer_riscv ==> default: Running provisioner: shell... default: Running: inline script ==> default: stdin: is not a tty ==> default: [otto] Adding apt repositories and updating... ==> default: [otto] Installing Ruby 2.2 and supporting packages... ==> default: [otto] Installing Bundler... ==> default: [otto] Configuring Git to use SSH instead of HTTP so we can agent-forward private repo auth... ==> Caching SSH credentials from Vagrant... ==> Development environment successfully created! IP address: 172.16.1.114 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: Fri Sep 14 06:23:18 2012 from 10.0.2.2 vagrant@precise64:/vagrant$ ls -lt total 1 -rwxrwxrwx 1 vagrant vagrant 114 Sep 29 16:14 Appfile vagrant@precise64:/vagrant$ cat Appfile import "github.com/msyksphinz/swimmer_riscv.git" {} application { name = "swimmer_riscv" type = "ruby" } vagrant@precise64:/vagrant ```` 何故か、Appfileはロードされていた。うーん、もうちょっと勉強してみる必要がありそうだな。