forked from getredash/setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.pkr.hcl
95 lines (79 loc) · 3.33 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
# This file was autogenerated by the 'packer hcl2_upgrade' command. We
# recommend double checking that everything is correct before going forward. We
# also recommend treating this file as disposable. The HCL2 blocks in this
# file can be moved to other files. For example, the variable blocks could be
# moved to their own 'variables.pkr.hcl' file, etc. Those files need to be
# suffixed with '.pkr.hcl' to be visible to Packer. To use multiple files at
# once they also need to be in the same folder. 'packer inspect folder/'
# will describe to you what is in that folder.
# Avoid mixing go templating calls ( for example ```{{ upper(`string`) }}``` )
# and HCL2 calls (for example '${ var.string_value_example }' ). They won't be
# executed together and the outcome will be unknown.
# See https://www.packer.io/docs/templates/hcl_templates/blocks/packer for more info
packer {
required_plugins {
amazon = {
source = "github.com/hashicorp/amazon"
version = "~> 1"
}
}
}
# All generated input variables will be of 'string' type as this is how Packer JSON
# views them; you can change their type later on. Read the variables type
# constraints documentation
# https://www.packer.io/docs/templates/hcl_templates/variables#type-constraints for more info.
variable "image_version" {
type = string
default = "10.0"
}
# "timestamp" template function replacement
locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") }
# source blocks are generated from your builders; a source can be referenced in
# build blocks. A build block runs provisioner and post-processors on a
# source. Read the documentation for source blocks here:
# https://www.packer.io/docs/templates/hcl_templates/blocks/source
source "amazon-ebs" "redash-us-east-1" {
ami_name = "redash-${var.image_version}-us-east-1"
instance_type = "t2.micro"
region = "us-east-1"
source_ami = "ami-0ea09f73e400d0c98"
ssh_username = "ubuntu"
}
# a build block invokes sources and runs provisioning steps on them. The
# documentation for build blocks can be found here:
# https://www.packer.io/docs/templates/hcl_templates/blocks/build
build {
sources = ["source.amazon-ebs.redash-us-east-1"]
provisioner "shell" {
inline = ["sleep 30"]
}
provisioner "file" {
destination = "/tmp/docker-compose.yml"
source = "data/docker-compose.yml"
}
provisioner "shell" {
execute_command = "{{ .Vars }} sudo -E -S bash '{{ .Path }}'"
script = "setup.sh"
}
provisioner "shell" {
inline = ["sudo rm /root/.ssh/authorized_keys || true"]
}
provisioner "shell" {
inline = ["sudo rm /home/ubuntu/.ssh/authorized_keys || true"]
}
provisioner "file" {
destination = "/tmp/rc.local"
source = "data/generate_key.sh"
}
provisioner "file" {
destination = "/tmp/docker-compose-up.service"
source = "data/docker-compose-up.service"
}
provisioner "shell" {
inline = ["sudo mv /tmp/rc.local /etc/rc.local", "sudo chown root /etc/rc.local", "sudo chmod 755 /etc/rc.local", "sudo mv /tmp/docker-compose-up.service /etc/systemd/system/docker-compose-up.service", "sudo chown root /etc/systemd/system/docker-compose-up.service", "sudo systemctl enable docker-compose-up"]
}
provisioner "shell" {
execute_command = "{{ .Vars }} sudo -E -S bash '{{ .Path }}'"
script = "data/cleanup.sh"
}
}