mirror of
https://github.com/apricote/flatcar-packer-hcloud.git
synced 2026-01-13 13:21:01 +00:00
feat: cleanup code and introduce custom labels
This commit is contained in:
parent
c7730392cc
commit
a5c8a49c6a
2 changed files with 51 additions and 70 deletions
|
|
@ -1,41 +0,0 @@
|
||||||
variant: flatcar
|
|
||||||
version: 1.1.0
|
|
||||||
|
|
||||||
systemd:
|
|
||||||
units:
|
|
||||||
- name: "coreos-metadata.service"
|
|
||||||
enabled: true
|
|
||||||
contents: |
|
|
||||||
[Unit]
|
|
||||||
Description=Flatcar Metadata Agent
|
|
||||||
After=nss-lookup.target
|
|
||||||
After=network-online.target
|
|
||||||
Wants=network-online.target
|
|
||||||
[Service]
|
|
||||||
Type=oneshot
|
|
||||||
Restart=on-failure
|
|
||||||
RemainAfterExit=yes
|
|
||||||
ExecStart=/usr/bin/coreos-metadata --cmdline --attributes=/run/metadata/flatcar
|
|
||||||
ExecStartPost=/usr/bin/sed --in-place "s/AFTERBURN/COREOS/g ; s/AWS/EC2/g ; s/GCP/GCE/g" /run/metadata/flatcar
|
|
||||||
ExecStartPost=/usr/bin/ln -fs /run/metadata/flatcar /run/metadata/coreos
|
|
||||||
[Install]
|
|
||||||
RequiredBy=system-config.target
|
|
||||||
Alias=afterburn.service
|
|
||||||
- name: "coreos-metadata-sshkeys@root.service"
|
|
||||||
enabled: true
|
|
||||||
- name: "coreos-metadata-hostname.service"
|
|
||||||
# The unit in initramfs has restrictive conditions on the OEM platform that do not include Hetzner
|
|
||||||
enabled: true
|
|
||||||
contents: |
|
|
||||||
[Unit]
|
|
||||||
Description=Flatcar Metadata Agent Hostname
|
|
||||||
After=coreos-metadata.service
|
|
||||||
Requires=coreos-metadata.service
|
|
||||||
[Service]
|
|
||||||
EnvironmentFile=/run/metadata/flatcar
|
|
||||||
Type=oneshot
|
|
||||||
Restart=on-failure
|
|
||||||
RemainAfterExit=yes
|
|
||||||
ExecStart=/usr/bin/hostnamectl hostname "${COREOS_COREOS_HETZNER_HOSTNAME}"
|
|
||||||
[Install]
|
|
||||||
RequiredBy=system-config.target
|
|
||||||
|
|
@ -2,7 +2,7 @@ packer {
|
||||||
required_plugins {
|
required_plugins {
|
||||||
hcloud = {
|
hcloud = {
|
||||||
source = "github.com/hetznercloud/hcloud"
|
source = "github.com/hetznercloud/hcloud"
|
||||||
version = "~> 1"
|
version = "~> 1.4.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -26,65 +26,87 @@ variable "channel" {
|
||||||
default = "beta"
|
default = "beta"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "image_version_id" {
|
variable "version" {
|
||||||
type = string
|
type = string
|
||||||
default = "current"
|
default = "current"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "flatcar_install_script" {
|
variable "labels" {
|
||||||
type = string
|
// Available replacements:
|
||||||
default = "https://raw.githubusercontent.com/flatcar/init/flatcar-master/bin/flatcar-install"
|
// $architecture
|
||||||
|
// $board
|
||||||
|
// $channel
|
||||||
|
// $version - if "current" was specified, this is resolved to the actual version
|
||||||
|
type = map(string)
|
||||||
|
default = {
|
||||||
|
os = "flatcar"
|
||||||
|
flatcar-channel = "$channel"
|
||||||
|
flatcar-board = "$board"
|
||||||
|
version = "$version"
|
||||||
|
architecture = "$architecture"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
locals {
|
locals {
|
||||||
hcloud_location = "fsn1"
|
boards = {
|
||||||
hcloud_rescue = "linux64"
|
|
||||||
hcloud_initial_os = "ubuntu-22.04"
|
|
||||||
flatcar_oem_id = "hetzner"
|
|
||||||
|
|
||||||
board = {
|
|
||||||
x86 = "amd64-usr"
|
x86 = "amd64-usr"
|
||||||
arm = "arm64-usr"
|
arm = "arm64-usr"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
architectures = ["x86", "arm"]
|
||||||
|
|
||||||
|
// If the user wants the "current" version, we still want to make the
|
||||||
|
// actual version id available through labels + snapshot description
|
||||||
|
//
|
||||||
|
// regex matches: FLATCAR_VERSION=1234.0.0
|
||||||
|
version = regex("FLATCAR_VERSION=(\\d+\\.\\d+\\.\\d+)", data.http.version_info.body)[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
data "http" "version_info" {
|
||||||
|
// We assume that both boards have the same version
|
||||||
|
url = "https://${var.channel}.release.flatcar-linux.net/amd64-usr/${var.version}/version.txt"
|
||||||
}
|
}
|
||||||
|
|
||||||
source "hcloud" "flatcar" {
|
source "hcloud" "flatcar" {
|
||||||
token = var.hcloud_token
|
token = var.hcloud_token
|
||||||
|
|
||||||
image = local.hcloud_initial_os
|
image = "ubuntu-22.04"
|
||||||
location = local.hcloud_location
|
location = "fsn1"
|
||||||
rescue = local.hcloud_rescue
|
rescue = "linux64"
|
||||||
|
|
||||||
snapshot_labels = {
|
|
||||||
os = "flatcar"
|
|
||||||
}
|
|
||||||
|
|
||||||
ssh_username = "root"
|
ssh_username = "root"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
build {
|
build {
|
||||||
source "hcloud.flatcar" {
|
dynamic "source" {
|
||||||
name = "x86"
|
for_each = local.architectures
|
||||||
server_type = var.hcloud_server_type["x86"]
|
labels = ["hcloud.flatcar"]
|
||||||
snapshot_name = "flatcar-x86"
|
|
||||||
}
|
|
||||||
|
|
||||||
source "hcloud.flatcar" {
|
content {
|
||||||
name = "arm"
|
name = source.value
|
||||||
server_type = var.hcloud_server_type["arm"]
|
server_type = var.hcloud_server_type[source.value]
|
||||||
snapshot_name = "flatcar-arm"
|
snapshot_name = "flatcar-${var.channel}-${local.version}-${source.value}"
|
||||||
|
|
||||||
|
snapshot_labels = {
|
||||||
|
for k, v in var.labels : k => replace(replace(replace(replace(v,
|
||||||
|
"$channel", var.channel),
|
||||||
|
"$version", local.version),
|
||||||
|
"$architecture", source.value),
|
||||||
|
"$board", local.boards[source.name])
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
provisioner "shell" {
|
provisioner "shell" {
|
||||||
inline = [
|
inline = [
|
||||||
# Download script and dependencies
|
# Download script and dependencies
|
||||||
"apt-get -y install gawk",
|
"apt-get -y install gawk",
|
||||||
"curl -fsSLO --retry-delay 1 --retry 60 --retry-connrefused --retry-max-time 60 --connect-timeout 20 ${var.flatcar_install_script}",
|
"curl -fsSLO --retry-delay 1 --retry 60 --retry-connrefused --retry-max-time 60 --connect-timeout 20 https://raw.githubusercontent.com/flatcar/init/flatcar-master/bin/flatcar-install",
|
||||||
"chmod +x flatcar-install",
|
"chmod +x flatcar-install",
|
||||||
|
|
||||||
# Install flatcar
|
# Install flatcar
|
||||||
"./flatcar-install -v -s -o hetzner -b https://${var.channel}.release.flatcar-linux.net/${local.board[source.name]} -V ${var.image_version_id}",
|
"./flatcar-install -s -o hetzner -C ${var.channel} -B ${local.boards[source.name]} -V ${var.version} ",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue