docs: update for OEM images

This commit is contained in:
Julian Tölle 2024-05-30 16:48:08 +02:00
parent 13579664cf
commit cd2b5e70ff

View file

@ -1,46 +1,43 @@
# 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)
- [Hetzner Cloud CLI](https://github.com/hetznercloud/cli) (`hcloud`) - [Hetzner Cloud CLI](https://github.com/hetznercloud/cli) (`hcloud`)
## Building Snapshots This requires Flatcar version `3941.1.0+`.
In Hetzner Cloud, you can create a "Snapshot" of your server's disk. You can then use these snapshots to create new servers. ## 1. Building Snapshots
We will use Packer and the `flatcar-install` script to write the pre-built images from Flatcar CI to the disk and then create a snapshot. In Hetzner Cloud, you can create a "Snapshot" of your server's disk. You can then use these snapshots to create new
servers.
We will use Packer and the `flatcar-install` script to write the pre-built images from Flatcar CI to the disk and then
create a snapshot.
```shell ```shell
$ git clone --branch oem-image-prebuilt https://github.com/apricote/flatcar-packer-hcloud.git $ git clone https://github.com/apricote/flatcar-packer-hcloud.git
$ cd flatcar-packer-hcloud $ cd flatcar-packer-hcloud
$ export HCLOUD_TOKEN=<Your Hetzner Cloud API Token> $ export HCLOUD_TOKEN=<Your Hetzner Cloud API Token>
$ packer init . $ packer init .
# This will build the Snapshot for x86. You need to specify the path to your local image file. # This will build the snapshot for x86 and Arm.
$ packer build . $ packer build .
# ... Takes a few minutes # ... Takes a few minutes
# It sometimes hangs on "==> hcloud.x86: + trap - EXIT", running with `PACKER_LOG=1` fixes it for me.
==> Builds finished. The artifacts of successful builds are: ==> Builds finished. The artifacts of successful builds are:
--> hcloud.x86: A snapshot was created: 'flatcar-x86' (ID: 157132241) --> hcloud.x86: A snapshot was created: 'flatcar-beta-3941.1.0-x86' (ID: 157132241)
--> hcloud.arm: A snapshot was created: 'flatcar-arm' (ID: 157132242) --> hcloud.arm: A snapshot was created: 'flatcar-beta-3941.1.0-arm' (ID: 157132242)
$ 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
157132241 snapshot - flatcar-x86 x86 0.47 GB 20 GB Sat Mar 30 16:48:22 CET 2024 - 167650172 snapshot - flatcar-beta-3941.1.0-arm arm 0.41 GB
157132242 snapshot - flatcar-arm arm 0.44 GB 20 GB Sat Mar 30 16:48:22 CET 2024 - 167650577 snapshot - flatcar-beta-3941.1.0-x86 x86 0.47 GB
``` ```
## Create a Server ## 2. Create a Server
You can now create a new server from the snapshot. Not every feature might automatically work, as the snapshot is You can now create a new server from the snapshot. Configuring SSH Keys and User Data (Ignition) will work as expected.
missing the functionality from [`hc-utils`](https://github.com/hetznercloud/hc-utils). Configuring SSH Keys and User
Data (Ignition) will work as expected.
```shell ```shell
# Get ID of the most recent flatcar snapshot for x86 # Get ID of the most recent flatcar snapshot for x86
@ -54,3 +51,40 @@ $ hcloud server create --name flatcar-test --image $SNAPSHOT_ID --type cx11 --ss
# 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 -u core flatcar-test $ hcloud server ssh -u core flatcar-test
``` ```
## Options
If you need to configure the Flatcar installation or the resulting image, there are a few packer variables that you can
set.
- `channel`: To choose a different Flatcar channel, defaults to `beta` (as `stable` does not have Hetzner images yet)
- `version`: If you want to install a specific version, defaults to `current`
- `labels`: See [section below](#labels)
### Labels
The `labels` variable controls the labels that are added to the resulting image. This can be helpful if you use a tool
that requires specific image labels, like `caph-image-name`
for [`cluster-api-provider-hetzner`](https://github.com/syself/cluster-api-provider-hetzner/blob/v1.0.0-beta.35/docs/topics/node-image.md#creating-a-node-image).
The following variables are supported:
- `$architecture`: The Hetzner Cloud API architecture (`x86` or `arm`).
- `$board`: The Flatcar Board identifier for the architecture (`amd64-usr` or `arm64-usr`).
- `$version`: The Flatcar version, if you are using `current`, this is resolved to the actual version in the snapshot.
- `$channel`: The Flatcar release channel.
The default labels are:
- `os=flatcar`
- `flatcar-channel=$channel`
- `flatcar-board=$board`
- `version=$version`
- `architecture=$architecture`
## Known Issues
These features do not work with Flatcar as of version 3941.1.0:
- **Volume Automount**: You need to mount volumes manually.
- **Setting & Resetting Root Passwords**: You need to configure an SSH Key through the API or Ignition User Data.