-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.pkr.hcl
170 lines (143 loc) · 4.52 KB
/
build.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
locals {
controller_image = "${var.controller_image}:${var.controller_version}"
controller_token = "ROOKOUT_TOKEN=$${ROOKOUT_TOKEN}"
controller_cert_mount = "$${ROOKOUT_CONTROLLER_CERT_PATH}:/var/controller-tls-secrets/"
controller_cert_path = "/etc/rookout/controller/certs"
dop_image = "${var.dop_image}:${var.dop_version}"
dop_token = "ROOKOUT_DOP_LOGGING_TOKEN=$${ROOKOUT_TOKEN}"
dop_cert_mount = "$${ROOKOUT_DOP_CERT_PATH}:/var/rookout/"
dop_cert_path = "/etc/rookout/data-onprem/certs"
uuid = substr(uuidv4(), 0, 8)
date = legacy_isotime("2006-01-02")
build_name = "${var.name}-${var.linux_distro}-${local.date}-${local.uuid}"
}
build {
name = var.name
sources = var.sources
provisioner "shell-local" {
inline = [
"echo =======================================================",
"echo Hello from ${source.type}.${source.name} ${var.name} ${build.Host}",
"echo =======================================================",
]
}
provisioner "shell" {
script = "scripts/install-docker-${var.linux_distro}.sh"
}
provisioner "file" {
content = templatefile(("templates/config.tpl"),
{
token = var.token
})
destination = "/tmp/config"
}
provisioner "file" {
content = templatefile(("templates/controller/env.tpl"),
{
server_mode = var.server_mode
port = var.controller_port
certs_path = local.controller_cert_path
})
destination = "/tmp/controller_env"
}
provisioner "file" {
content = templatefile(("templates/data-onprem/env.tpl"),
{
server_mode = var.server_mode
port = var.dop_port
certs_path = local.dop_cert_path
})
destination = "/tmp/dop_env"
}
provisioner "file" {
content = templatefile(("templates/systemd-unit.tpl"),
{
description = "Rookout Controller Service"
name = "controller"
image = local.controller_image
token = local.controller_token
certs_mount = local.controller_cert_mount
port = var.controller_port
})
destination = "/tmp/rookout-controller.service"
}
provisioner "file" {
content = templatefile(("templates/systemd-unit.tpl"),
{
description = "Rookout DOP Service"
name = "data-onprem"
image = local.dop_image
token = local.dop_token
certs_mount = local.dop_cert_mount
port = var.dop_port
})
destination = "/tmp/rookout-data-on-prem.service"
}
provisioner "shell" {
inline = [
"sudo mkdir -p ${local.controller_cert_path}",
"sudo mkdir -p ${local.dop_cert_path}",
]
}
provisioner "shell" {
inline = [
"sudo docker pull ${local.controller_image}",
"sudo docker pull ${local.dop_image}"
]
}
provisioner "shell" {
script = "scripts/rookout-startup.sh"
}
provisioner "shell" {
script = "scripts/secure_ami.sh"
}
provisioner "shell-local" {
environment_vars = [
"TARGET_USER=ubuntu",
"HOST_KEY=${build.SSHPrivateKey}",
"SPEC_NAME=${source.name}",
"HOST=${build.Host}"
]
inline = [
"if [[ ${var.tests} != \"true\" ]];then exit 0;fi",
"echo =======================================================",
"echo Running RSpec tests ${source.type}.${source.name} ${var.name}",
"echo =======================================================",
"cd tests/ && rake spec"
]
}
provisioner "shell" {
environment_vars = [
"ROOKOUT_TOKEN=${var.token}"
]
script = "scripts/cleanup.sh"
}
provisioner "shell-local" {
environment_vars = [
"TARGET_USER=ubuntu",
"HOST_KEY=${build.SSHPrivateKey}",
"SPEC_NAME=cleanup",
"HOST=${build.Host}"
]
inline = [
"if [[ ${var.tests} != \"true\" ]];then exit 0;fi",
"echo =======================================================",
"echo Running RSpec tests ${source.type}.${source.name} ${var.name}",
"echo =======================================================",
"cd tests/ && rake spec"
]
}
provisioner "shell" {
inline = [
"echo === Cleaning Up Public Keys ===",
"sudo shred -u /etc/ssh/*_key /etc/ssh/*_key.pub",
]
}
post-processor "shell-local" {
inline = [
"echo =======================================================",
"echo Good Buy from ${source.type}.${source.name} ${var.name}",
"echo ======================================================="
]
}
}