Skip to content

Instantly share code, notes, and snippets.

@mhubig
Last active December 27, 2015 11:39
Show Gist options
  • Save mhubig/7319549 to your computer and use it in GitHub Desktop.
Save mhubig/7319549 to your computer and use it in GitHub Desktop.
Testing a possible workflow with paker.io and vagrant.

The intended workflow should be:

  1. Build the images

    $ packer build template.json
    
  2. Import and start an image.

    $ vagrant up --provider=aws
    $ vagrant up --provider=virtualbox
    $ vagrant up --provider=vmware
    

You can set the default vagrant provider with export VAGRANT_DEFAULT_PROVIDER=vmware.

{
"variables": {
"aws_access_key": "",
"aws_secret_key": ""
},
"builders": [
{
"type": "amazon-ebs",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key` }}",
"region": "eu-west-1",
"source_ami": "ami-8e987ef9",
"instance_type": "t1.micro",
"ssh_username": "ubuntu",
"ami_name": "yocto-builder {{timestamp}}"
},
{
"type": "vmware",
"iso_url": "http://releases.ubuntu.com/12.04/ubuntu-12.04.3-server-amd64.iso",
"iso_checksum": "61d5e67c70d97b33c13537461a0b153b41304ef412bb0e9d813bb157068c3c65",
"iso_checksum_type": "sha256",
"boot_wait": "5s",
"boot_command": [
"<esc><esc><enter><wait>",
"/install/vmlinuz noapic preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ",
"debian-installer=en_US auto locale=en_US kbd-chooser/method=us ",
"hostname={{ .Name }} ",
"fb=false debconf/frontend=noninteractive ",
"keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false ",
"initrd=/install/initrd.gz -- <enter>"
],
"http_directory": "http",
"shutdown_command": "echo 'vagrant' | sudo -S shutdown -P now",
"ssh_wait_timeout": "20m",
"ssh_username": "vagrant",
"ssh_password": "vagrant"
},
{
"type": "virtualbox",
"iso_url": "http://releases.ubuntu.com/12.04/ubuntu-12.04.3-server-amd64.iso",
"iso_checksum": "61d5e67c70d97b33c13537461a0b153b41304ef412bb0e9d813bb157068c3c65",
"iso_checksum_type": "sha256",
"guest_os_type": "Ubuntu_64",
"boot_wait": "5s",
"boot_command": [
"<esc><esc><enter><wait>",
"/install/vmlinuz noapic preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ",
"debian-installer=en_US auto locale=en_US kbd-chooser/method=us ",
"hostname={{ .Name }} ",
"fb=false debconf/frontend=noninteractive ",
"keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false ",
"initrd=/install/initrd.gz -- <enter>"
],
"http_directory": "http",
"shutdown_command": "echo 'vagrant' | sudo -S shutdown -P now",
"ssh_wait_timeout": "20m",
"guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso",
"virtualbox_version_file": ".vbox_version",
"ssh_username": "vagrant",
"ssh_password": "vagrant"
}
],
"provisioners": [
{
"type": "shell",
"script": "scripts/vagrant.sh",
"only": ["virtualbox", "vmware"],
"execute_command": "echo 'vagrant' | {{.Vars}} sudo -E -S bash '{{.Path}}'"
},
{
"type": "shell",
"script": "scripts/virtualbox.sh",
"only": ["virtualbox"],
"execute_command": "echo 'vagrant' | {{.Vars}} sudo -E -S bash '{{.Path}}'"
},
{
"type": "shell",
"script": "scripts/kernel.sh",
"only": ["amazon-ebs"],
"execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E '{{ .Path }}'"
},
{
"type": "shell",
"script": "scripts/docker.sh",
"only": ["virtualbox", "vmware", "amazon-ebs"],
"override": {
"amazon-ebs": {
"execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E '{{ .Path }}'"
},
"virtualbox": {
"execute_command": "echo 'vagrant' | {{.Vars}} sudo -E -S bash '{{.Path}}'"
},
"vmware": {
"execute_command": "echo 'vagrant' | {{.Vars}} sudo -E -S bash '{{.Path}}'"
}
}
},
{
"type": "shell",
"script": "scripts/vm_cleanup.sh",
"only": ["virtualbox", "vmware"],
"execute_command": "echo 'vagrant' | {{.Vars}} sudo -E -S bash '{{.Path}}'"
}
],
"post-processors": [{
"type": "vagrant",
"output": "yocto-builder_{{.Provider}}.box"
}]
}
# -*- mode: ruby -*-
# vi: set ft=ruby :
BOX_NAME = "Yocto-Builder"
AWS_SSH_PRIVKEY = ENV['AWS_SSH_PRIVKEY'] || "~/.ssh/yocto-builder.pem"
AWS_KEYPAIR_NAME = ENV['AWS_KEYPAIR_NAME'] || "yocto-builder"
AWS_ACCESS_KEY = ENV['AWS_ACCESS_KEY_ID'] || "your aws access key"
AWS_SECRET_KEY = ENV['AWS_SECRET_ACCESS_KEY'] || "your aws secret key"
Vagrant.configure("2") do |config|
config.vm.box = "yocto-builder"
config.ssh.forward_agent = true
config.vm.provider :virtualbox do |vb|
config.vm.box_url = "yocto-builder_virtualbox.box"
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end
config.vm.provider :vmware_fusion do |f, override|
override.vm.box_url = "yocto-builder_vmware.box"
config.vm.synced_folder ".", "/vagrant", disabled: true
f.vmx["displayName"] = "yocto-builder"
end
config.vm.provider :aws do |aws, override|
override.vm.box_url = "yocto-builder_aws.box"
override.ssh.username = "ubuntu"
override.ssh.private_key_path = AWS_SSH_PRIVKEY
aws.keypair_name = AWS_KEYPAIR_NAME
aws.access_key_id = AWS_ACCESS_KEY
aws.secret_access_key = AWS_SECRET_KEY
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment