Skip to content
This repository has been archived by the owner. It is now read-only.
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.

Packer Common

When using Packer extensively, templates can be difficult to maintain; Packer common aims to fix it, by allowing to define separate Packer templates for builders, provisioners and project-specific items, merging them at execution time.

How to Run

Invoking Packer Common is simple:

curl -L https://raw.githubusercontent.com/Alfresco/packer-common/master/run-packer.sh --no-sessionid | bash -s -- ./ami.env

To run Packer Common you need:

  • A .env file (in this example ami.env) that defines all environment variables used by Packer logic; the .env file will include - amongst many other variables used by Packer Templates - a builder, a provisioner and a project-specific template "snippet":
export PACKER_BUILDER_TPL_NAME=amazon
export PACKER_PROVISIONER_TPL_NAME=chef-zero
export PACKER_INSTANCE_TPL=$ROOT_FOLDER/packer-ami.rb
  • The project-specific Packer logic, in this example packer-ami.rb

Template Composition

Based on the variables, the following "snippets" are fetched and merged:

  • The common builder
  • The common provisioner
  • The project-specific template "snippet", which can patch bits and pieces of builders and provisioners; an example is reported below

A project-specific Packer Common snippet

Racker::Processor.register_template do |t|
  t.provisioners = {
    10 => {
      "chef" => {
        "json"=> {
          "name"=> "img-basic"
        },
        "run_list" => [ "img-basic::default" ]
      }
    },
    20 => {
      "yum-clean-all" => {
        "type"=> "shell",
        "inline" => [
          "sudo yum -y clean all",
          "sudo rm -f /var/log/*",
          "sudo rm -rf /tmp/*"
        ]
      }
    }
  }
  t.builders['amazon'] = {
    "ami_block_device_mappings" => [
      {
        "device_name" => "/dev/sda1",
        "volume_size" => 12,
        "delete_on_termination" => true
      },
      {
        "device_name" => "/dev/sdb",
        "virtual_name" => "ephemeral0"
      },
      {
        "device_name" => "/dev/sdc",
        "virtual_name" => "ephemeral1"
      }
    ]
  }
end

Racker allows to generate Packer templates from a list of template "fragments" (or Racker templates).

Reusable Packer Template "snippets"

This is the list of currently available Packer Template "snippets" that can be reused with Packer Common:

Using Chef/Berkshelf

When Chef is involved, Packer Common will run some tasks before invoking racker and packer:

  1. Run Berkshelf to resolve all cookbooks needed
  2. Download and unpack databags
  3. Resolve Racker templates (from a Github repo)

run-packer.sh delivers these features, reading configurations from environment variables; check packer.env.sample for more info

About

Delivers image composition and building using Packer, Racker, Chef and Berkshelf

Resources

Packages

No packages published