-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add packer files to create the images
- Loading branch information
Showing
2 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
set -e -u -o pipefail | ||
|
||
command -v packer >/dev/null 2>&1 || { | ||
echo "packer is not installed. Install it with 'brew install packer'." | ||
exit 1 | ||
} | ||
|
||
if [[ -z "${HCLOUD_TOKEN:-}" ]]; then | ||
read -r -p "Enter your HCLOUD_TOKEN: " hcloud_token | ||
export HCLOUD_TOKEN=$hcloud_token | ||
fi | ||
echo "Running packer build for talos-hcloud.pkr.hcl" | ||
packer init talos-hcloud.pkr.hcl && packer build talos-hcloud.pkr.hcl |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# hcloud.pkr.hcl | ||
packer { | ||
required_plugins { | ||
hcloud = { | ||
version = "1.3.0" | ||
source = "github.com/hetznercloud/hcloud" | ||
} | ||
} | ||
} | ||
|
||
variable "talos_version" { | ||
type = string | ||
default = "v1.6.6" | ||
} | ||
|
||
variable "server_location" { | ||
type = string | ||
default = "fsn1" | ||
} | ||
|
||
locals { | ||
image_arm = "https://github.com/siderolabs/talos/releases/download/${var.talos_version}/hcloud-arm64.raw.xz" | ||
image_x86 = "https://github.com/siderolabs/talos/releases/download/${var.talos_version}/hcloud-amd64.raw.xz" | ||
|
||
# Add local variables for inline shell commands | ||
download_image = "wget --timeout=5 --waitretry=5 --tries=5 --retry-connrefused --inet4-only -O /tmp/talos.raw.xz " | ||
|
||
write_image = <<-EOT | ||
set -ex | ||
echo 'Talos image loaded, writing to disk... ' | ||
xz -d -c /tmp/talos.raw.xz | dd of=/dev/sda && sync | ||
echo 'done.' | ||
EOT | ||
|
||
clean_up = <<-EOT | ||
set -ex | ||
echo "Cleaning-up..." | ||
rm -rf /etc/ssh/ssh_host_* | ||
EOT | ||
} | ||
|
||
# Source for the Talos ARM image | ||
source "hcloud" "talos-arm" { | ||
rescue = "linux64" | ||
image = "debian-11" | ||
location = "${var.server_location}" | ||
server_type = "cax11" | ||
ssh_username = "root" | ||
|
||
snapshot_name = "Talos Linux ${var.talos_version} ARM by hcloud-talos" | ||
snapshot_labels = { | ||
type = "infra", | ||
os = "talos", | ||
version = "${var.talos_version}", | ||
arch = "arm", | ||
creator = "hcloud-talos" | ||
} | ||
} | ||
|
||
# Source for the Talos x86 image | ||
source "hcloud" "talos-x86" { | ||
rescue = "linux64" | ||
image = "debian-11" | ||
location = "${var.server_location}" | ||
server_type = "cx11" | ||
ssh_username = "root" | ||
|
||
snapshot_name = "Talos Linux ${var.talos_version} x86 by hcloud-talos" | ||
snapshot_labels = { | ||
type = "infra", | ||
os = "talos", | ||
version = "${var.talos_version}", | ||
arch = "x86", | ||
creator = "hcloud-talos" | ||
} | ||
} | ||
|
||
# Build the Talos ARM snapshot | ||
build { | ||
sources = ["source.hcloud.talos-arm"] | ||
|
||
# Download the Talos ARM image | ||
provisioner "shell" { | ||
inline = ["${local.download_image}${local.image_arm}"] | ||
} | ||
|
||
# Write the Talos ARM image to the disk | ||
provisioner "shell" { | ||
inline = [local.write_image] | ||
} | ||
|
||
# Clean-up | ||
provisioner "shell" { | ||
inline = [local.clean_up] | ||
} | ||
} | ||
|
||
# Build the Talos x86 snapshot | ||
build { | ||
sources = ["source.hcloud.talos-x86"] | ||
|
||
# Download the Talos x86 image | ||
provisioner "shell" { | ||
inline = ["${local.download_image}${local.image_x86}"] | ||
} | ||
|
||
# Write the Talos x86 image to the disk | ||
provisioner "shell" { | ||
inline = [local.write_image] | ||
} | ||
|
||
# Clean-up | ||
provisioner "shell" { | ||
inline = [local.clean_up] | ||
} | ||
} |