Created
October 28, 2021 07:32
-
-
Save jjs105/751935fe509c2026ac943d4420e39e62 to your computer and use it in GitHub Desktop.
Packer Sample Build Template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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