diff --git a/README.md b/README.md index 874dcb4..da6dbbb 100644 --- a/README.md +++ b/README.md @@ -10,38 +10,30 @@ - [Packer](https://developer.hashicorp.com/packer) - [Hetzner Cloud CLI](https://github.com/hetznercloud/cli) (`hcloud`) -## Building Image - -See https://www.flatcar.org/docs/latest/reference/developer-guides/sdk-modifying-flatcar/ - -``` -./build_packages -./build_image --replace -./image_to_vm.sh --format hetzner -``` - ## Building Snapshots 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 image we built in the previous step to the disk and then create a snapshot. +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 -$ git clone --branch oem-image https://github.com/apricote/flatcar-packer-hcloud.git +$ git clone --branch oem-image-prebuilt https://github.com/apricote/flatcar-packer-hcloud.git $ cd flatcar-packer-hcloud $ export HCLOUD_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 . +$ packer build . # ... 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: --> hcloud.x86: A snapshot was created: 'flatcar-x86' (ID: 157132241) +--> hcloud.arm: A snapshot was created: 'flatcar-arm' (ID: 157132242) $ hcloud image list --type=snapshot --selector=os=flatcar ID TYPE NAME DESCRIPTION ARCHITECTURE IMAGE SIZE DISK SIZE CREATED DEPRECATED 157132241 snapshot - flatcar-x86 x86 0.47 GB 20 GB Sat Mar 30 16:48:22 CET 2024 - +157132242 snapshot - flatcar-arm arm 0.44 GB 20 GB Sat Mar 30 16:48:22 CET 2024 - ``` ## Create a Server diff --git a/flatcar.pkr.hcl b/flatcar.pkr.hcl index f45ece7..62e4309 100644 --- a/flatcar.pkr.hcl +++ b/flatcar.pkr.hcl @@ -21,21 +21,31 @@ variable "hcloud_server_type" { } } +variable "image_base_url" { + type = string + default = "https://bincache.flatcar-linux.net/images" +} + +variable "image_version_id" { + type = string + default = "9999.0.0+hetzner" +} + variable "flatcar_install_script" { type = string default = "https://raw.githubusercontent.com/flatcar/init/flatcar-master/bin/flatcar-install" } -variable "image_path" { - type = string - description = "absolute local file path to the hetzner image (.bin.bz2)" -} - locals { hcloud_location = "fsn1" hcloud_rescue = "linux64" hcloud_initial_os = "ubuntu-22.04" flatcar_oem_id = "hetzner" + + board = { + x86 = "amd64" + arm = "arm64" + } } source "hcloud" "flatcar" { @@ -60,16 +70,10 @@ build { snapshot_name = "flatcar-x86" } - #source "hcloud.flatcar" { - # name = "arm" - # server_type = var.hcloud_server_type["arm"] - # snapshot_name = "flatcar-arm" - #} - - - provisioner "file" { - source = var.image_path - destination = "/flatcar_production_hetzner_image.bin.bz2" + source "hcloud.flatcar" { + name = "arm" + server_type = var.hcloud_server_type["arm"] + snapshot_name = "flatcar-arm" } provisioner "shell" { @@ -80,7 +84,7 @@ build { "chmod +x flatcar-install", # Install flatcar - "./flatcar-install -v -s -o hetzner -f /flatcar_production_hetzner_image.bin.bz2", + "./flatcar-install -v -s -o hetzner -b ${var.image_base_url}/${local.board[source.name]} -V ${var.image_version_id}", ] } }