|
| 1 | +# Siderolabs self-hosted imagefactory example |
| 2 | + |
| 3 | +This code runs [sidero imagefactory](https://github.com/siderolabs/image-factory) in [docker compose](https://docs.docker.com/compose/). |
| 4 | + |
| 5 | +It also deploys a few companion components: |
| 6 | +* upstream `ghcr.io` [registry](https://distribution.github.io/distribution/) [mirror](https://distribution.github.io/distribution/recipes/mirror/) to avoid potential upstream rate limitings and speed up builds by caching previously pulled image layers |
| 7 | +* a script that applies prepared `talos` [image schematics](https://www.talos.dev/v1.8/learn-more/image-factory/#schematics) |
| 8 | +* a [registry](https://distribution.github.io/distribution/) used as storage and cache for the generated images |
| 9 | + |
| 10 | +# how to use |
| 11 | + |
| 12 | +tested with `talos` version `v1.8.1`, via [iPXE boot](https://www.talos.dev/v1.8/talos-guides/install/bare-metal-platforms/pxe/) and directly applying generated images to disk via `hcloud` (use it's [packer](https://developer.hashicorp.com/packer/integrations/hetznercloud/hcloud) integration and point [this](https://github.com/siderolabs/contrib/blob/9cd1e1c9d2469b77d2278eb07e7f61c09bb32d40/examples/terraform/hcloud/packer/hcloud_talosimage.pkr.hcl#L18) URL to your `imagefactory` instance). |
| 13 | + |
| 14 | +## preparation |
| 15 | + |
| 16 | +some preparation is required. |
| 17 | + |
| 18 | +### signing keys |
| 19 | +see [official docs](https://github.com/siderolabs/image-factory?tab=readme-ov-file#development). |
| 20 | + |
| 21 | +```shell |
| 22 | +mkdir -pv keys |
| 23 | +openssl ecparam -name prime256v1 -genkey -noout -out keys/cache-signing-key.key |
| 24 | +``` |
| 25 | + |
| 26 | +### schematics |
| 27 | + |
| 28 | +Refer to the [official docs](https://www.talos.dev/v1.8/learn-more/image-factory/#schematics) on how to create these. |
| 29 | +The [script](./scripts/sync-schematics.sh) will find and apply all files in `schematics/*.yaml`. |
| 30 | + |
| 31 | +Example: |
| 32 | +```yaml |
| 33 | +# schematics/example.yaml |
| 34 | +customization: |
| 35 | + extraKernelArgs: |
| 36 | + - gfxmode=1280x1024 |
| 37 | + - console=ttyS0,115200 |
| 38 | + - net.ifnames=0 |
| 39 | + - talos.platform=metal |
| 40 | + systemExtensions: |
| 41 | + officialExtensions: |
| 42 | + - siderolabs/amd-ucode |
| 43 | + - siderolabs/fuse3 |
| 44 | + - siderolabs/intel-ucode |
| 45 | + - siderolabs/iscsi-tools |
| 46 | + - siderolabs/qemu-guest-agent |
| 47 | + - siderolabs/tailscale |
| 48 | + - siderolabs/util-linux-tools |
| 49 | + meta: |
| 50 | + - key: 12 |
| 51 | + value: | |
| 52 | + machineLabels: |
| 53 | + env: prod |
| 54 | + type: controlplane |
| 55 | +``` |
| 56 | +
|
| 57 | +### environment variables |
| 58 | +
|
| 59 | +copy the [docker compose env file](https://docs.docker.com/compose/how-tos/environment-variables/variable-interpolation/#env-file) and adjust the example values. |
| 60 | +
|
| 61 | +```shell |
| 62 | +cp env.example .env |
| 63 | +vim .env |
| 64 | +``` |
| 65 | + |
| 66 | +Adjust all domains and `EXT_IP` to where you want to expose your `imagefactory` instance. |
| 67 | +This is relevant for payloads sent to `iPXE` clients and URLs generated in the UI. |
| 68 | + |
| 69 | +## run |
| 70 | + |
| 71 | +after preparation is done, run `docker compose up -d`. |
| 72 | + |
| 73 | +# miscellaneous & troubleshooting |
| 74 | + |
| 75 | +This is a community contribution so expect no official support. |
| 76 | +Some trouble I ran into: |
| 77 | + |
| 78 | +## TLS |
| 79 | + |
| 80 | +The configuration used does *not* deploy TLS, so you should put this behind something like a reverse proxy that does. |
| 81 | + |
| 82 | +## connection timeouts |
| 83 | + |
| 84 | +Image generation can take some time, so clients might have to increase their connection timeout limits. If images are cached, [TTFB](https://en.wikipedia.org/wiki/Time_to_first_byte) is very short, if not `TTFB` can take up to several minutes. |
| 85 | + |
| 86 | +## iPXE and https |
| 87 | + |
| 88 | +If you want to [iPXE](https://ipxe.org)-boot from this via `https`, keep in mind that by default `iPXE` does *not* support `https` and you need to compile your own, enabling [this](https://ipxe.org/buildcfg/download_proto_https) flag. This is a pitfall for reverse proxies that automatically redirect plaintext `http` requests to `https`. |
| 89 | + |
| 90 | +## URLs not working |
| 91 | + |
| 92 | +There is a tiny problem in the `imagefactory` frontend: The URLs generated contain the external domain used and it is duplicated for some reason. This is particularly mean because the URL _visible_ in the UI looks correct, but the `HTML` `href` is not. |
| 93 | +Make sure to sanitize the URL before use, the resulting URL works as expected. Not sure yet as to _why_ this happens (misconfiguration or might be a bug). |
| 94 | +Querying the `API` seems to return the correct URL. |
| 95 | + |
| 96 | +## registry resource consumption |
| 97 | + |
| 98 | +* When building a large number of images, make sure to provide sufficient storage to the `registry` container and monitor `docker volumes` as it grows in size quite rapidly. |
| 99 | +* the image generation process is compute heavy and can take some time, depending on the compute power available. |
0 commit comments