Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Example Packer pipeline with Berkshelf cookbook vendoring
#!/bin/bash -x
#DEBUG="-debug"
VM=`echo ${1} | sed 's/.json//g'`
PACKER=`which packer`
rm -rf output-${VM}
${PACKER} build ${DEBUG} ${VM}.json
if [ $? -ne 0 ] ; then
echo "ERROR: Unable to build ${VM}."
exit 1
fi
{
"builders": [{
"type": "virtualbox",
"name": "example-dev",
"vm_name": "example-dev",
"guest_os_type": "RedHat_64",
"hard_drive_interface": "sata",
"headless": true,
"vboxmanage": [
["modifyvm", "{{.Name}}", "--memory", "2048"],
["modifyvm", "{{.Name}}", "--rtcuseutc", "on"],
],
"iso_url": "http://mirrors.mit.edu/centos/6/isos/x86_64/CentOS-6.6-x86_64-bin-DVD1.iso",
"iso_checksum": "7b1fb1a11499b31271ded79da6af8584",
"iso_checksum_type": "md5",
"boot_command": ["<tab><wait> vmlinuz initrd=initrd.img ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/centos64-vm.ks <return>"],
"http_directory": "srv",
"ssh_username": "root",
"ssh_password": "admin",
"ssh_wait_timeout": "20m",
"shutdown_command": "shutdown -P now"
}],
"provisioners": [
{
"type":"shell",
"script":"provisioning/virtualbox.sh"
},
{
"type": "chef-solo",
"cookbook_paths": ["cookbooks"],
"run_list": [
"example",
],
"json": {
}
},{
"type":"shell",
"inline": ["mv -f /tmp/packer-chef-solo /home/admin/", "echo 'cookbook_path [\"/home/admin/packer-chef-solo/cookbooks-0\"]' > /home/admin/packer-chef-solo/solo.rb"]
},{
"type": "file",
"source": "provisioning/update.sh",
"destination": "/home/admin/update.sh"
},{
"type": "file",
"source": "Berksfile.lock",
"destination": "/home/admin/Berksfile.lock"
},{
},{
"type":"shell",
"inline": ["rm -rf /usr/local/tomcat/default/webapps/example"]
},
{
"type":"shell",
"script":"provisioning/cleanup.sh"
}
],
"post-processors": [{
"type": "vagrant",
"output": "packer_{{.BuildName}}_{{.Provider}}_{{timestamp}}.box"
}]
}
#! /bin/bash -xe
export VM=$1
bash update.sh
bash build.sh $VM
bash deploy.sh $VM
#!/bin/bash -x
# When on Windows or exported, use $BERKSHELF_PATH; default to the normal Linux location
BERK_PATH=${BERKSHELF_PATH:-$HOME/.berkshelf}
BERK_PATH=$(echo "${BERK_PATH}" | sed 's#\\#/#g')
# Remove cookbook caches
rm -rf ${BERK_PATH}/tmp
rm -rf ${BERK_PATH}/vagrant/*/multisite*
rm -rf ${BERK_PATH}/cookbooks/multisite-*
rm -rf ${BERK_PATH}/*/cookbooks/multisite*
rm -rf ${BERK_PATH}/*/vagrant/berkshelf-*/multisite*
rm -rf ./cookbooks
bundle exec berks install --path cookbooks
if [ $? -ne 0 ] ; then
echo "ERROR : Unable to update cookbooks."
exit 1
else
echo "SUCCESS: Updated and vendored cookbooks"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment