ページ

2015年5月10日日曜日

Jenkis用のVagrantをBox化

Jenkinsをインストールして初期設定したばかりのVagrant環境をBox化してみる

・vagrant package
$ vagrant package
==> default: Clearing any previously set forwarded ports...
==> default: Exporting VM...
==> default: Compressing package to: /Users/{ユーザ名}/Documents/develop/vagrant/boxes/centos6/package.box
$ ls
Vagrantfile package.box

Vagrant fileがあるディレクトリでvagrant packageコマンド実行する事でpackage化してくれる。package.boxができている事を確認。

・vagrantのboxとして登録
$ vagrant box add jenkins package.box
==> box: Adding box 'jenkins' (v0) for provider: 
    box: Downloading: file:///Users/{ユーザ名}/Documents/develop/vagrant/boxes/centos6/package.box
==> box: Successfully added box 'jenkins' (v0) for 'virtualbox'!
$ vagrant box list
centos6 (virtualbox, 0)
centos7 (virtualbox, 0)
jenkins (virtualbox, 0)

vagrant box add {名前} package.boxでpackage化したものをboxとして登録

・実際にboxを使ってみる
$ mkdir jenkins
$ ls
centos6 centos7 jenkins
$ cd jenkins/
$ ls
$ vagrant init jenkins
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
$ ls
Vagrantfile
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'jenkins'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: jenkins_default_1431183086594_26350
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => /Users/{ユーザ名}/Documents/develop/vagrant/boxes/jenkins

vagrant init で作成したjenkinsというboxを指定し初期化&立ち上げ
※この時NICのMACアドレスなんかもコピーしてしまう為以下サイトの設定が必要
http://www.absolute-keitarou.net/blog/?p=583
また当然VagrantのIP設定(192.168.33.10)も必要

macのブラウザからjenkinsへアクセスしてみる
無事アクセスできました^^



0 件のコメント:

コメントを投稿