LoginSignup
20
20

More than 5 years have passed since last update.

CoreOSにzsh、ansibleを入れてみた

Posted at

================================

CoreOSにはパッケージマネージャ(yum, aptなど)がないので、

$ yum install zsh

のようなノリでパッケージをインストール出来ない。
任意のパッケージをインストールする方法として、
SDKを使用してパッケージをインストール済みのイメージを作成するという方法があるので
今回はこれを試してみました。

ちなみにCoreOSはChomeOS派生のディストリビューション。(ChomeOSはGentoo派生)

参考にさせていただいたサイト
* http://tdoc.info/blog/2014/04/02/coreos_sdk_image.html
* CoreOS公式サイト

coreos-logo.png

目的

zsh、ansibleをインストールしてあるvagrant用CoreOSイメージを作成する。

作業環境

  • MBP cpu:i5 2.6GHz mem:8GB
  • OS X Yosemite 10.10
  • Vagrant 1.6.5
  • VirtualBox 4.3.18
  • Vagrant + VirtualBox + Ubuntu-Trusty 14.04

depot_toolsのインストール

まずは、CoreOSのソースを取得してビルドするためのツールをインストール。
SDK は x86-64 Linux で実行する必要があるので、Vagrant + VirtualBox + Ubuntu-Trusty 14.04環境にて作業。
自分は~/binにインストールしました。

$ mkdir ~/bin; cd ~/bin
$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
$ export PATH=~/bin/depot_tools:$PATH

SDK chrootの作成

プロジェクトディレクトリを掘って、ソースやSDKを取得します。
repo syncにかなり時間がかかります。散歩しましょう。
(repoはandroid本体の開発にも使っているGitのラッパーツールですね。)

$ mkdir ~/coreos; cd ~/coreos
$ repo init -u https://github.com/coreos/manifest.git -g minilayout --repo-url https://chromium.googlesource.com/external/repo.git
$ repo sync

SDK chrootに入る

SDKをダウンロードしてSDK chrootに入る。
これもそれなりに時間かかります。コーヒー飲んで待ちましょう。

$ ./chromite/bin/cros_sdk

実は、OS X Yosemite 10.10 でチャレンジしてたんですが、
ココらへんからpython2のパスがLinuxと違くて動かなかったり、unshareがないってエラーになったので、
素直にUbuntuでやり直しました。。

以下のように表示されて完了。

cros_sdk:make_chroot: All set up.  To enter the chroot, run:
$ cros_sdk --enter

CAUTION: Do *NOT* rm -rf the chroot directory; if there are stale bind
mounts you may end up deleting your source tree too.  To unmount and
delete the chroot cleanly, use:
$ cros_sdk --delete

vagrant@ubuntu ~/trunk/src/scripts $

SDK chrootに入っている(cros_sdk --enterした)状態になります。
emergeなんかが動作します。
ちなみに、自分はGentooシロウトです。

$ emerge --help

zsh、ansibleどちらも見つかりません。

$ emerge -s ansible
$ emerge -s zsh

試しにemacs入れてみようとしましたが、途中でエラー発生。
なんだかよくわかりません。

$ sudo emerge emacs

install: invalid group ‘mail’
make: *** [install_common] Error 1
emake failed
 * ERROR: net-libs/liblockfile-1.08::portage-stable failed (install phase):
 *   (no error message)
 *
 * Call stack:
 *     ebuild.sh, line  93:  Called src_install
 *   environment, line 2882:  Called die
 * The specific snippet of code:
 *       emake ROOT="${D}" install || die;
 *
 * If you need support, post the output of `emerge --info '=net-libs/liblockfile-1.08::portage-stable'`,
 * the complete build log and the output of `emerge -pqv '=net-libs/liblockfile-1.08::portage-stable'`.
 * The complete build log is located at '/var/log/portage/net-libs:liblockfile-1.08:20141111-015752.log'.
 * For convenience, a symlink to the build log is located at '/var/tmp/portage/net-libs/liblockfile-1.08/temp/build.log'.
 * The ebuild environment file is located at '/var/tmp/portage/net-libs/liblockfile-1.08/temp/environment'.
 * Working directory: '/var/tmp/portage/net-libs/liblockfile-1.08/work/liblockfile-1.08'
 * S: '/var/tmp/portage/net-libs/liblockfile-1.08/work/liblockfile-1.08'
 * QA Notice: command not found:
 *
 *      /mnt/host/source/src/third_party/portage-stable/net-libs/liblockfile/liblockfile-1.08.ebuild: line 19: enewgroup: command not found

zsh、ansibleを入れてイメージ作成

Add new upstream packageを確認したら、
emerge packageでパッケージを入れるわけではなく、scripts/update_ebuildsを使うっぽい。

zsh・ansibleをフェッチ。
ちなみにここでパッケージを探せる。

$ ./update_ebuilds app-shells/zsh
$ ./update_ebuilds app-admin/ansible

scripts/update_ebuildsでパッケージをフェッチすると'src/third_party/portage-stable'に入る。
編集する必要がある場合は'src/third_party/coreos-overlay'に入れる。
ちなみに、ここで言う編集が何を意味するのかはわかっていません。

~/trunk/src/third_party/coreos-overlay/coreos-base/coreos/coreos-0.0.1.ebuildの環境変数RDEPENDの最後に
パッケージ追記する。

coreos-0.0.1.ebuild

RDEPEND=
    ・
    ・
    ・
    dev-vcs/git
    app-shells/zsh
    app-admin/ansible
"

シンボリックリンクcoreos-0.0.1-r241.ebuildのリビジョンを上げる。
Add new upstream packageにはgit mvと書いてあるが、今回はコミットしないので普通にリネーム。
※はじめ、これをやらずにイメージ作って、zsh、ansibleが入らなくてめちゃくちゃハマりました。。

$ mv ~/trunk/src/third_party/coreos-overlay/coreos-base/coreos/coreos-0.0.1-r241.ebuild ~/trunk/src/third_party/coreos-overlay/coreos-base/coreos/coreos-0.0.1-r242.ebuild

"core"ユーザーのパスワードを設定

$ ./set_shared_user_password.sh

ターゲットをamd64にする。x86とかもできるみたい。
CoreOS 公式 box のデフォルトは amd64。
setup_board は10分位かかった。

$ echo amd64-usr > .default_board
$ ./setup_board

ビルド。

$ ./build_packages

エラー発生。

emerge: there are no ebuilds built with USE flags to satisfy "dev-python/pyyaml[python_targets_python2_7(-)?,-python_single_target_python2_7(-)]" for /build/amd64-usr/.
!!! One of the following packages is required to complete your request:
- app-admin/ansible-1.6.8::portage-stable (Change USE: -python_targets_python2_7, this change violates use flag constraints defined by app-admin/ansible-1.6.8: 'any-of ( python_targets_python2_7 )')
(dependency required by "app-admin/ansible-1.6.8" [ebuild])
(dependency required by "coreos-base/coreos-0.0.1-r242::coreos" [ebuild])
(dependency required by "coreos-devel/board-packages-0.0.1-r2::coreos" [binary])
(dependency required by "coreos-devel/board-packages" [argument])
ERROR   build_packages: script called: build_packages (args unknown, no debug available)
ERROR   build_packages: Backtrace:  (most recent call is last)
ERROR   build_packages:   file build_packages, line 223, called: die_err_trap 'sudo -E "${EMERGE_CMD[@]}" "${EMERGE_FLAGS[@]}" @system coreos-devel/board-packages' '1'
ERROR   build_packages:
ERROR   build_packages: Command failed:
ERROR   build_packages:   Command 'sudo -E "${EMERGE_CMD[@]}" "${EMERGE_FLAGS[@]}" @system coreos-devel/board-packages' exited with nonzero code: 1
vagrant@ubuntu ~/trunk/src/scripts $

ansibleに必要なパッケージがないっぽいので、依存しているパッケージを確認して入れる。
dev-python、net-misc/sshpassを入れた。

$ emerge -tp ansible

These are the packages that would be merged, in reverse order:

Calculating dependencies... done!

emerge: there are no ebuilds built with USE flags to satisfy "dev-python/pyyaml[python_targets_python2_7(-)?,-python_single_target_python2_7(-)]".
!!! One of the following packages is required to complete your request:
- app-admin/ansible-1.6.8::portage-stable (Change USE: -python_targets_python2_7, this change violates use flag constraints defined by app-admin/ansib
le-1.6.8: 'any-of ( python_targets_python2_7 )')
(dependency required by "app-admin/ansible-1.6.8" [ebuild])
(dependency required by "ansible" [argument])


$ ./update_ebuilds dev-python/pyyaml
$ emerge -tp ansible

These are the packages that would be merged, in reverse order:

Calculating dependencies... done!

emerge: there are no ebuilds to satisfy "net-misc/sshpass".
(dependency required by "app-admin/ansible-1.6.8" [ebuild])
(dependency required by "ansible" [argument])

$ ./update_ebuilds net-misc/sshpass

再度ビルド。

$ ./build_packages

イメージを作成。
10分位。

developイメージ(developer overlayを含む)
$ ./build_image --noenable_rootfs_verification dev

productイメージ
$ ./build_image prod

raw なイメージができたので、vagrantのイメージにコンバートする。

developイメージの場合
$ ./image_to_vm.sh --format vagrant

productイメージの場合
$ ./image_to_vm.sh --format vagrant --prod_image

コンバート可能なフォーマットは以下のとおり。(default: 'qemu')

ami
pxe
iso
openstack
qemu
qemu_no_kexec
qemu_uefi
rackspace
rackspace_onmetal
rackspace_vhd
vagrant
vagrant_vmware_fusion
virtualbox
vmware
vmware_insecure
xen
gce
brightbox
cloudstack
cloudstack_vhd
digitalocean
exoscale
azure
hyperv
seaure_demo

以下にboxができる。

$ ls -l ~/trunk/src/build/images/amd64-usr/developer-494.0.0+2014-11-12-1906-a1/
total 1330052
-rw-r--r-- 1 vagrant vagrant 4756340736 11月 12 19:12 coreos_production_image.bin
-rw-r--r-- 1 vagrant vagrant    1468783 11月 12 19:12 coreos_production_image_contents.txt
-rw-r--r-- 1 vagrant vagrant       5885 11月 12 19:12 coreos_production_image_packages.txt
-rw-r--r-- 1 vagrant vagrant 1073741824 11月 12 19:12 coreos_production_update.bin
-rw-r--r-- 1 vagrant vagrant    6072177 11月 12 19:12 coreos_production_update.zip
-rw-r--r-- 1 vagrant vagrant  225675625 11月 12 19:18 coreos_production_vagrant.box
-rw-r--r-- 1 vagrant vagrant        338 11月 12 19:18 coreos_production_vagrant.json
-rw-r--r-- 1 vagrant vagrant         84 11月 12 19:07 developer_data
drwxr-xr-x 2 root    root          4096 11月 12 19:07 rootfs
-rw-r--r-- 1 vagrant vagrant        174 11月 12 19:12 version.txt

Ubuntuからだと以下の場所。

$ ls -l ~/coreos/src/build/images/amd64-usr/developer-494.0.0+2014-11-12-1906-a1/

作成したイメージで動作確認する

作成したイメージを Vagrant + VirtualBox + Ubuntu 環境とホスト(Mac)の共有ディレクトリへコピーする。

$ cp ~/coreos/src/build/images/amd64-usr/developer-494.0.0+2014-11-12-1906-a1/coreos_production_vagrant.* /vagrant/.

ホストで、作成したイメージで Vagrant + カスタムCoreOS を起動。

$ mkdir coreos-custom; cd coreos-custom
$ mv ../ubuntu-trusty/coreos_production_vagrant.* .
$ vagrant init coreos-custom coreos_production_vagrant.box
$ vagrant up

CoreOSにログインして動作確認してみる。

$ vagrant ssh
CoreOS (developer)
core@localhost ~ $ zsh
zsh        zsh-5.0.5
core@localhost ~ $ zsh
localhost%
core@localhost ~ $ ansible
ansible           ansible-doc       ansible-galaxy    ansible-playbook  ansible-pull      ansible-vault
core@localhost ~ $ ansible --version
ansible 1.6.8

$ vagrant box listでCoreOSのバージョンが'0'なのはあとで調べます。

$ vagrant box list
coreos-custom        (virtualbox, 0)
20
20
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
20
20