-
Notifications
You must be signed in to change notification settings - Fork 12
/
packer.pkr.hcl
105 lines (86 loc) · 2.92 KB
/
packer.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
packer {
required_plugins {
googlecompute = {
version = ">= 1.1.6"
source = "github.com/hashicorp/googlecompute"
}
}
}
# Define required variables
variable "project_id" {
type = string
default = "hyperbeam-cd"
}
variable "region" {
type = string
default = "us-east1"
}
variable "zone" {
type = string
default = "us-east1-c"
}
variable "image_name" {
type = string
default = "hyperbeam-image"
}
# Source block to define GCP builder
source "googlecompute" "ubuntu" {
project_id = var.project_id
source_image_family = "ubuntu-2204-lts"
image_name = var.image_name
zone = var.zone
machine_type = "n1-standard-1"
ssh_username = "packer"
}
# Define the build stage
build {
sources = ["source.googlecompute.ubuntu"]
# Add a provisioner to download and install go-tpm-tools
provisioner "shell" {
inline = [
"sudo apt-get update -y",
"sudo apt-get install -y wget tar",
# Download the go-tpm-tools binary archive
"wget https://github.com/google/go-tpm-tools/releases/download/v0.4.4/go-tpm-tools_Linux_x86_64.tar.gz -O /tmp/go-tpm-tools.tar.gz",
# Extract the binary
"tar -xzf /tmp/go-tpm-tools.tar.gz -C /tmp",
# Move the gotpm binary to /usr/local/bin
"sudo mv /tmp/gotpm /usr/local/bin/",
# Clean up
"rm -f /tmp/go-tpm-tools.tar.gz /tmp/LICENSE /tmp/README.md"
]
}
# Upload the pre-built release (with ERTS included) to the instance
provisioner "file" {
source = "./_build/default/rel/ao"
destination = "/tmp/hyperbeam"
}
provisioner "shell" {
inline = [
# Move the release to /opt with sudo
"sudo mv /tmp/hyperbeam /opt/hyperbeam",
"sudo chmod -R 755 /opt/hyperbeam",
# Create a symlink to make it easier to run the app
"sudo ln -s /opt/hyperbeam/bin/hyperbeam /usr/local/bin/hyperbeam",
# (Optional) If you want to create a systemd service to manage the app
"echo '[Unit]' | sudo tee /etc/systemd/system/hyperbeam.service",
"echo 'Description=Permaweb Node' | sudo tee -a /etc/systemd/system/hyperbeam.service",
"echo '[Service]' | sudo tee -a /etc/systemd/system/hyperbeam.service",
"echo 'Type=simple' | sudo tee -a /etc/systemd/system/hyperbeam.service",
"echo 'ExecStart=/opt/hyperbeam/bin/hyperbeam foreground' | sudo tee -a /etc/systemd/system/hyperbeam.service",
"echo 'Restart=on-failure' | sudo tee -a /etc/systemd/system/hyperbeam.service",
"echo '[Install]' | sudo tee -a /etc/systemd/system/hyperbeam.service",
"echo 'WantedBy=multi-user.target' | sudo tee -a /etc/systemd/system/hyperbeam.service",
# Enable and start the service
"sudo systemctl enable hyperbeam",
"sudo systemctl start hyperbeam"
]
}
# Disable ssh
# provisioner "shell" {
# inline = [
# "sudo systemctl stop ssh",
# "sudo systemctl disable ssh"
# ]
# }
}