LoginSignup
4
4

More than 5 years have passed since last update.

ottoで構築する環境のubuntuのバージョンを上げる

Last updated at Posted at 2016-04-27

背景

ottoが構築する環境のubuntuのバージョンは12.04です。

Vagrantのboxにhashicorp/precise64を使っています。
https://github.com/hashicorp/otto/blob/master/helper/compile/data/app/dev/Vagrantfile-layer.tpl#L12

ところがprecise64ではdockerコンテナが動きません。
Unable to provision docker container on precise64 · Issue #496 · hashicorp/otto

依存サービスをdockerで動かせません。
これでは、どこにottoを使う甲斐がありましょうや?

対策その1 boxをbento/ubuntu-14.04に変更

issue496のコメントにある
https://github.com/hashicorp/otto/issues/442#issuecomment-212756614
のようにboxをbento/ubuntu-14.04に変更します。

これにはottoのソースコードを修正してコンパイルしなおす必要があります。

ソースコードの修正

git clone git@github.com:hashicorp/otto.git
cd otto

ソースコードは
https://github.com/hashicorp/otto/blob/master/helper/compile/data/app/dev/Vagrantfile-layer.tpl#L12
hashicorp/precise64bento/ubuntu-14.04に変更します。

コンパイル

goの開発環境は$HOME/workに設定済みとして、以下のコマンドを実行すると

set --export GOPATH $HOME/work
make updatedeps
make dev

~/work/src/github.com/hashicorp/otto/bin/ottoにコマンドができます。

実行

otto compile
otto dev

過去に、otto 0.2で、PC上に別の環境を作っている場合は、これでは上手くいきません。

対策その2 PC上のotto環境をクリアする

原因

otto 0.2のLayered Development EnvironmentsはVagrantのLinked Cloneを使っています。
ottoは可能な限り、既存のイメージを流用します。

precise64 -> consul -> application のようにコピーして環境構築を行います。

precise64が存在していると対策1で作ったottoコマンドを実行しても、OSは更新されません。

既存の仮想環境を削除

vagrant global-status

を使い関連する仮想環境をvagrant destroyコマンドで消します。

Linked Cloneを削除

Linked CloneのClone元環境はVagrantからは消せないためVirtualboxの管理コンソールから消します。
またVagrantはClone元のidをキャッシュしているます。

rm ~/.vagrant.d/boxes/hashicorp-VAGRANTSLASH-precise64/1.1.0/virtualbox/master_id

参考: Vagrant 1.8の新機能 Linked CloneとSnapshotを試してみた | Developers.IO

クローンVMとマスターVMを全て削除するときは注意が必要です。ドキュメントの[Note]にあるようにクローンVMを全て削除してもマスターVMは自動では削除されないので、Virtualbox側で削除する必要があります。 ただ、VagrantはBoxと既存のマスターVMをUUIDで紐付けるメタデータを持っているため、マスターVMを削除するときに以下のメタデータファイルmaster_idも削除する必要があるようです。

.otto.dを削除

ottoは流用可能なレイヤーを探す際に~/.otto.d/global-data/vagrant-layered/vagrant-layered.dbの情報を見ています。
https://github.com/hashicorp/otto/blob/master/helper/vagrant/layered.go#L421

このファイルがあるとVgarantのイメージを消しても、消した環境のVagratfileを参照しにいきます。

ひと思いにディレクトリごと消します。
https://github.com/hashicorp/otto/issues/423#issuecomment-176198082

rm -rf ~/.otto.d

このあとで対策1で作ったottoコマンドを使えば、ubuntu-14.04の環境が作れます。
dockerを使いつづけることができます!

補足

rubyの環境を作る場合は、上記の問題とは別のエラーが出ます。
app/ruby: Error on rails preparing database · Issue #393 · hashicorp/otto

環境自体は構築できています。手動で

bundle exec rake db:setup || bundle exec rake db:migrate

を実行してください。

感想

ottoとは、ここまでして使うものか。ちょっと疑問に感じてきました。

4
4
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
4
4