Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Atlas Tutorial | Packer pushでAtlas上でBOXをbuildし、完成したBOXを利用してVagrant upする

f:id:tbpg:20150819232628j:plain

Atlas TutorialでPackerを用いてAtlas上でBOXをbuildし、
Vagrant upまでを疎通確認します

手順

サインイン

Atlasにサインインします。

Tutorialのメニュー選択

Build Vagrant Boxes with Packer and Atlasを選択します

f:id:tbpg:20150825230632p:plain

Install Packer

Packerのバージョンを確認します。

$ packer version

Clone Packer Template

Packerのテンプレートをcloneします

$ git clone "https://github.com/hashicorp/atlas-packer-vagrant-tutorial.git"

Generate Token

APIトークンを生成します。

set environment

環境変数に取得したAPIトークンを設定します。

$ export ATLAS_TOKEN="your token"

Verify

$ curl "https://atlas.hashicorp.com/ui/tutorial/check?access_token=$ATLAS_TOKEN"

Configure build settings in Atlas

build名を指定します。今回は以下の名前にしました。

atlas_sample

Packer Push

だいたい30分かかります。 また、たまにbuildが失敗するので、その場合は再実行します。

$ packer push -name tbpgr/atlas_sample template.json

完成したBOXをVagrantから利用

Vagrantfileの生成

$ vagrant init tbpgr/atrals_sample -m

Vagrantfile

config.vm.providerの部分は手動で追加しました

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "tbpgr/atrals_sample"
  config.vm.network :private_network, ip: "172.16.33.109"

  config.vm.provider :virtualbox do |vb|
    vb.name = "atlas_sample"
  end
end

Vagrant 起動

$ vagrant login --check
You aren't logged in! Run `vagrant login` to log in
$ vagrant login --token $ATLAS_TOKEN
The token was successfully saved.
You are already logged in.
$ vagrant login --check
You are already logged in.
$ vagrant up --provider virtualbox
$ vagrant ssh
Welcome to Ubuntu 12.04.5 LTS (GNU/Linux 3.13.0-32-generic x86_64)

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

図でまとめ

f:id:tbpg:20150825230531p:plain

外部資料

AtlasでPackerが実行できるようになってて感動した