Skip to content

Instantly share code, notes, and snippets.

@jjs105
Created October 28, 2021 07:32
Show Gist options
  • Save jjs105/751935fe509c2026ac943d4420e39e62 to your computer and use it in GitHub Desktop.
Save jjs105/751935fe509c2026ac943d4420e39e62 to your computer and use it in GitHub Desktop.
Packer Sample Build Template
packer {
required_plugins {
docker = {
version = ">= 0.0.7"
source = "github.com/hashicorp/docker"
}
}
}
variable "docker_image" {
type = string
default = "ubuntu:xenial"
}
source "docker" "ubuntu" {
image = var.docker_image
commit = true
}
source "docker" "ubuntu-bionic" {
image = "ubuntu:bionic"
commit = true
}
build {
name = "learn-packer"
sources = [
"source.docker.ubuntu",
"source.docker.ubuntu-bionic",
]
provisioner "shell" {
environment_vars = [
"FOO=hello world",
]
inline = [
"echo Adding file to Docker Container",
"echo \"FOO is $FOO\" > example.txt",
]
}
provisioner "shell" {
inline = ["echo Running ${var.docker_image} Docker image."]
}
post-processor "docker-tag" {
repository = "learn-packer"
tags = ["ubuntu-xenial", "packer-rocks"]
only = ["docker.ubuntu"]
}
post-processor "docker-tag" {
repository = "learn-packer"
tags = ["ubuntu-bionic", "packer-rocks"]
only = ["docker.ubuntu-bionic"]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment