mirror of
https://github.com/apricote/flatcar-packer-hcloud.git
synced 2026-01-13 13:21:01 +00:00
feat: document building the draft oem image pr
This commit is contained in:
parent
e5b84e72be
commit
0752579fe1
3 changed files with 42 additions and 44 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1 +1,2 @@
|
||||||
ignition-*.json
|
ignition-*.json
|
||||||
|
credentials.auto.pkrvars.hcl
|
||||||
|
|
|
||||||
45
README.md
45
README.md
|
|
@ -1,35 +1,46 @@
|
||||||
# Build Flatcar Snapshots on Hetzner Cloud with Packer
|
# Build Flatcar Snapshots on Hetzner Cloud with Packer
|
||||||
|
|
||||||
|
> [!IMPORTANT]
|
||||||
|
> This version of the README describes the process to build & test Hetzner OEM images using the Draft PR [flatcar/scripts#1880](https://github.com/flatcar/scripts/pull/1880).
|
||||||
|
> If you are a user looking to install Flatcar on Hetzner Cloud right now, you can check out the [`main` branch](https://github.com/apricote/flatcar-packer-hcloud/) of this repo.
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
- [Hetzner Cloud API Token](https://docs.hetzner.com/cloud/api/getting-started/generating-api-token/)
|
- [Hetzner Cloud API Token](https://docs.hetzner.com/cloud/api/getting-started/generating-api-token/)
|
||||||
- [Packer](https://developer.hashicorp.com/packer)
|
- [Packer](https://developer.hashicorp.com/packer)
|
||||||
- [Butane](https://coreos.github.io/butane/)
|
|
||||||
- [Hetzner Cloud CLI](https://github.com/hetznercloud/cli) (`hcloud`)
|
- [Hetzner Cloud CLI](https://github.com/hetznercloud/cli) (`hcloud`)
|
||||||
|
|
||||||
This only works on Flatcar version `3913.0.0` (or later), as this version has the appropriate versions of
|
## Building Image
|
||||||
`ignition` and `afterburn` that include support for the Hetzner Cloud metadata service.
|
|
||||||
|
See https://www.flatcar.org/docs/latest/reference/developer-guides/sdk-modifying-flatcar/
|
||||||
|
|
||||||
|
```
|
||||||
|
./build_packages
|
||||||
|
./build_image --replace
|
||||||
|
./image_to_vm --format hetzner
|
||||||
|
```
|
||||||
|
|
||||||
## Building Snapshots
|
## Building Snapshots
|
||||||
|
|
||||||
```shell
|
In Hetzner Cloud, you can create a "Snapshot" of your server's disk. You can then use these snapshots to create new servers.
|
||||||
$ git clone ... # TODO
|
|
||||||
$ export HCLOUD_TOKEN=<Your Hetzner Cloud API Token>
|
|
||||||
$ packer init flatcar.pkr.hcl
|
|
||||||
$ butane butane-oem.yaml --pretty --strict --output=ignition-oem.json
|
|
||||||
|
|
||||||
# This will build Snapshots for x86 and arm. If you only need one, you can add
|
We will use Packer and the flatcar-install script to write the image we built in the previous step to the disk and then create a snapshot.
|
||||||
# `--only=hcloud.x86` or `--only=hcloud.arm` to the `packer build` command.
|
|
||||||
$ packer build flatcar.pkr.hcl
|
```shell
|
||||||
|
$ git clone --branch oem-image https://github.com/apricote/flatcar-packer-hcloud.git
|
||||||
|
$ cd flatcar-packer-hcloud
|
||||||
|
$ export HCLOUD_TOKEN=<Your Hetzner Cloud API Token>
|
||||||
|
$ packer init .
|
||||||
|
|
||||||
|
# This will build the Snapshot for x86. You need to specify the path to your local image file.
|
||||||
|
$ packer build . -var image_path=/path/to/flatcar_production_hetzner_image.bin.bz2
|
||||||
# ... Takes a few minutes
|
# ... Takes a few minutes
|
||||||
==> Builds finished. The artifacts of successful builds are:
|
==> Builds finished. The artifacts of successful builds are:
|
||||||
--> hcloud.x86: A snapshot was created: 'flatcar-alpha-x86' (ID: 157132241)
|
--> hcloud.x86: A snapshot was created: 'flatcar-x86' (ID: 157132241)
|
||||||
--> hcloud.arm: A snapshot was created: 'flatcar-alpha-arm' (ID: 157132252)
|
|
||||||
|
|
||||||
$ hcloud image list --type=snapshot --selector=os=flatcar
|
$ hcloud image list --type=snapshot --selector=os=flatcar
|
||||||
ID TYPE NAME DESCRIPTION ARCHITECTURE IMAGE SIZE DISK SIZE CREATED DEPRECATED
|
ID TYPE NAME DESCRIPTION ARCHITECTURE IMAGE SIZE DISK SIZE CREATED DEPRECATED
|
||||||
157132241 snapshot - flatcar-alpha-x86 x86 0.47 GB 20 GB Sat Mar 30 16:48:22 CET 2024 -
|
157132241 snapshot - flatcar-x86 x86 0.47 GB 20 GB Sat Mar 30 16:48:22 CET 2024 -
|
||||||
157132252 snapshot - flatcar-alpha-arm arm 0.42 GB 40 GB Sat Mar 30 16:48:24 CET 2024 -
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Create a Server
|
## Create a Server
|
||||||
|
|
@ -48,5 +59,5 @@ $ hcloud server create --name flatcar-test --image $SNAPSHOT_ID --type cx11 --ss
|
||||||
# Wait about a minute or two for the server to be started
|
# Wait about a minute or two for the server to be started
|
||||||
|
|
||||||
# Now you can login, the following is a helper that calls `ssh` with the public ipv4 address of the server
|
# Now you can login, the following is a helper that calls `ssh` with the public ipv4 address of the server
|
||||||
$ hcloud server ssh flatcar-test
|
$ hcloud server ssh -u core flatcar-test
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,9 @@ variable "flatcar_install_script" {
|
||||||
default = "https://raw.githubusercontent.com/flatcar/init/flatcar-master/bin/flatcar-install"
|
default = "https://raw.githubusercontent.com/flatcar/init/flatcar-master/bin/flatcar-install"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "flatcar_channel" {
|
variable "image_path" {
|
||||||
type = string
|
type = string
|
||||||
default = "alpha"
|
description = "absolute local file path to the hetzner image (.bin.bz2)"
|
||||||
}
|
}
|
||||||
|
|
||||||
locals {
|
locals {
|
||||||
|
|
@ -47,7 +47,6 @@ source "hcloud" "flatcar" {
|
||||||
|
|
||||||
snapshot_labels = {
|
snapshot_labels = {
|
||||||
os = "flatcar"
|
os = "flatcar"
|
||||||
"flatcar.channel" = var.flatcar_channel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ssh_username = "root"
|
ssh_username = "root"
|
||||||
|
|
@ -58,43 +57,30 @@ build {
|
||||||
source "hcloud.flatcar" {
|
source "hcloud.flatcar" {
|
||||||
name = "x86"
|
name = "x86"
|
||||||
server_type = var.hcloud_server_type["x86"]
|
server_type = var.hcloud_server_type["x86"]
|
||||||
snapshot_name = "flatcar-${var.flatcar_channel}-x86"
|
snapshot_name = "flatcar-x86"
|
||||||
}
|
}
|
||||||
|
|
||||||
source "hcloud.flatcar" {
|
#source "hcloud.flatcar" {
|
||||||
name = "arm"
|
# name = "arm"
|
||||||
server_type = var.hcloud_server_type["arm"]
|
# server_type = var.hcloud_server_type["arm"]
|
||||||
snapshot_name = "flatcar-${var.flatcar_channel}-arm"
|
# snapshot_name = "flatcar-arm"
|
||||||
}
|
#}
|
||||||
|
|
||||||
|
|
||||||
provisioner "file" {
|
provisioner "file" {
|
||||||
source = "ignition-oem.json"
|
source = var.image_path
|
||||||
destination = "/ignition.json"
|
destination = "/flatcar_production_hetzner_image.bin.bz2"
|
||||||
}
|
}
|
||||||
|
|
||||||
provisioner "shell" {
|
provisioner "shell" {
|
||||||
inline = [
|
inline = [
|
||||||
# Download script and dependencies
|
# Download script and dependencies
|
||||||
"apt-get update",
|
|
||||||
"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 ${var.flatcar_install_script}",
|
||||||
"chmod +x flatcar-install",
|
"chmod +x flatcar-install",
|
||||||
|
|
||||||
# Install flatcar
|
# Install flatcar
|
||||||
"./flatcar-install -s -C ${var.flatcar_channel}",
|
"./flatcar-install -v -s -o hetzner -f /flatcar_production_hetzner_image.bin.bz2",
|
||||||
|
|
||||||
# Setup Ignition Config & Kernel Parameters for OEM Platform
|
|
||||||
"mkdir /root/OEM",
|
|
||||||
"mount /dev/disk/by-label/OEM /root/OEM",
|
|
||||||
|
|
||||||
## Kernel Parameter
|
|
||||||
"echo 'set oem_id=${local.flatcar_oem_id}' > /root/OEM/grub.cfg",
|
|
||||||
|
|
||||||
## Base Ignition Config (merged with user data)
|
|
||||||
"mkdir /root/OEM/base",
|
|
||||||
"cp /ignition.json /root/OEM/base/base.ign",
|
|
||||||
|
|
||||||
"umount /root/OEM",
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue