mirror of
https://github.com/apricote/flatcar-packer-hcloud.git
synced 2026-01-13 21:31:02 +00:00
docs: use preview image from Flatcar CI
This commit is contained in:
parent
230f28a49a
commit
3089324472
2 changed files with 25 additions and 29 deletions
18
README.md
18
README.md
|
|
@ -10,38 +10,30 @@
|
||||||
- [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 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
|
## 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.
|
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
|
```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
|
$ 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. 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
|
# ... Takes a few minutes
|
||||||
# It sometimes hangs on "==> hcloud.x86: + trap - EXIT", running with `PACKER_LOG=1` fixes it for me.
|
# 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-x86' (ID: 157132241)
|
||||||
|
--> hcloud.arm: A snapshot was created: 'flatcar-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 DISK SIZE CREATED DEPRECATED
|
||||||
157132241 snapshot - flatcar-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 -
|
||||||
|
157132242 snapshot - flatcar-arm arm 0.44 GB 20 GB Sat Mar 30 16:48:22 CET 2024 -
|
||||||
```
|
```
|
||||||
|
|
||||||
## Create a Server
|
## Create a Server
|
||||||
|
|
|
||||||
|
|
@ -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" {
|
variable "flatcar_install_script" {
|
||||||
type = string
|
type = string
|
||||||
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 "image_path" {
|
|
||||||
type = string
|
|
||||||
description = "absolute local file path to the hetzner image (.bin.bz2)"
|
|
||||||
}
|
|
||||||
|
|
||||||
locals {
|
locals {
|
||||||
hcloud_location = "fsn1"
|
hcloud_location = "fsn1"
|
||||||
hcloud_rescue = "linux64"
|
hcloud_rescue = "linux64"
|
||||||
hcloud_initial_os = "ubuntu-22.04"
|
hcloud_initial_os = "ubuntu-22.04"
|
||||||
flatcar_oem_id = "hetzner"
|
flatcar_oem_id = "hetzner"
|
||||||
|
|
||||||
|
board = {
|
||||||
|
x86 = "amd64"
|
||||||
|
arm = "arm64"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
source "hcloud" "flatcar" {
|
source "hcloud" "flatcar" {
|
||||||
|
|
@ -60,16 +70,10 @@ build {
|
||||||
snapshot_name = "flatcar-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-arm"
|
snapshot_name = "flatcar-arm"
|
||||||
#}
|
|
||||||
|
|
||||||
|
|
||||||
provisioner "file" {
|
|
||||||
source = var.image_path
|
|
||||||
destination = "/flatcar_production_hetzner_image.bin.bz2"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
provisioner "shell" {
|
provisioner "shell" {
|
||||||
|
|
@ -80,7 +84,7 @@ build {
|
||||||
"chmod +x flatcar-install",
|
"chmod +x flatcar-install",
|
||||||
|
|
||||||
# Install flatcar
|
# 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}",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue