Skip to content

Commit

Permalink
feat: Add packer files to create the images
Browse files Browse the repository at this point in the history
  • Loading branch information
mrclrchtr committed Mar 16, 2024
1 parent 60f5501 commit 73d7d31
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packer/create.sh
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
116 changes: 116 additions & 0 deletions packer/talos-hcloud.pkr.hcl
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]
}
}

0 comments on commit 73d7d31

Please sign in to comment.