generated from accelerator-blueprints/base-blueprint
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker.pkr.hcl
95 lines (84 loc) · 2.28 KB
/
docker.pkr.hcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
variable "version" {
type = string
default = ""
}
packer {
required_plugins {
ansible = {
source = "github.com/hashicorp/ansible"
version = "~> 1"
}
docker = {
version = "~> 1"
source = "github.com/hashicorp/docker"
}
}
}
locals {
os_username = "ubuntu"
os = "ubuntu"
os_freindly_name = "jammy-22.04"
os_virtualization_type = "hvm"
os_arch = "amd64"
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
}
# https://github.com/hashicorp/packer-plugin-docker/blob/main/docs/builders/docker.mdx
source "docker" "this" {
image = "ubuntu:jammy" # https://hub.docker.com/_/ubuntu/tags?page=1&name=jammy
# discard = true
pull = true
commit = true
run_command = [ "-d", "-i", "-t", "--name", "default", "{{.Image}}", "/bin/bash" ]
# changes = [
# "EXPOSE 56793",
# "LABEL version=1.0",
# "ONBUILD RUN date",
# ]
}
build {
name = "docker-example"
sources = ["source.docker.this"]
provisioner "shell" {
inline= [
"echo 'Etc/UTC' > /etc/timezone",
"cat /etc/timezone",
"echo '-${build.ID}. uuid ${build.PackerRunUUID}-'"
]
}
provisioner "ansible" {
playbook_file = "${path.root}/ansible/playbook.yaml"
# inventory_file = "${path.root}/ansible/inventory.yml"
ansible_env_vars = ["ANSIBLE_HOST_KEY_CHECKING=False", "ANSIBLE_SSH_ARGS='-v -o ControlMaster=auto -o ControlPersist=15m"]
host_alias = "${build.ID}"
# sftp_command = "/usr/lib/sftp-server -e -l INFO"
extra_arguments = ["--scp-extra-args", "'-O'", "-vvv",
"-e", "ansible_connection=docker",
]
user = "root"
# sftp_command = "/usr/bin/false"
# use_sftp = false
# local_port = 2222
# extra_arguments = [
# "--connection", "docker",
# ]
}
provisioner "shell" {
inline= [
"cat /tmp/ansible-test",
"git --version",
"curl --version",
]
}
provisioner "shell" {
environment_vars = [
"FOO=hello world",
]
inline = [
"echo Adding file to Docker Container",
"echo \"FOO is $FOO\" > example.txt"
]
}
provisioner "shell" {
inline = ["echo 'Build docker image'"]
}
}