Skip to content

Commit 3ec22df

Browse files
Allow building HookOS from existing kernel image: (#233)
## Description <!--- Please describe what this PR is going to change --> When the `kernel-releases.json` is updated, which is pretty frequent, a new point release will be available and require Users to build the kernel. With this commit, `USE_LATEST_BUILT_KERNEL` allows a User to build HookOS without having to build the kernel. This is done by getting the latest point release from `quay.io/tinkerbell/hook-kernel` image tags. ## Why is this needed <!--- Link to issue you have raised --> Fixes: # ## How Has This Been Tested? <!--- Please describe in detail how you tested your changes. --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> ## How are existing users impacted? What migration steps/scripts do we need? <!--- Fixes a bug, unblocks installation, removes a component of the stack etc --> <!--- Requires a DB migration script, etc. --> ## Checklist: I have: - [ ] updated the documentation and/or roadmap (if required) - [ ] added unit or e2e tests - [ ] provided instructions on how to upgrade
2 parents 30bbf4a + baa93a2 commit 3ec22df

File tree

3 files changed

+45
-38
lines changed

3 files changed

+45
-38
lines changed

README.md

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ We started this project for the following reasons:
1818
- The [OSIE] build process was not standardised, which is critical for an open-source project because it causes friction for contributors.
1919
This project, as highlighted later in this page, uses [LinuxKit].
2020
It gives us:
21-
- Documentation about how the building phase works
22-
- A clear and defined CLI and [specification] (YAML)
23-
- A shared community that is supportive
24-
- LinuxKit cross-compiles in many architectures
25-
- Different output formats: ISO, init ramdisk, aws, docker, rpi3... see [formats].
21+
- Documentation about how the building phase works
22+
- A clear and defined CLI and [specification] (YAML)
23+
- A shared community that is supportive
24+
- LinuxKit cross-compiles in many architectures
25+
- Different output formats: ISO, init ramdisk, aws, docker, rpi3... see [formats].
2626
- It was not easy to explain to the Tinkerbell community how [OSIE] works and the components it is made for.
2727
A lot of the components were Equinix Metal specific and are not strictly needed in Tinkerbell.
2828

@@ -67,14 +67,14 @@ It will then speak with the `hook-docker` engine API through the shared `/var/ru
6767
> This refers to the 0.9.0-alpha version, compared to 0.8.1.
6868
6969
- Replaces the emulated Alpine kernel build with a Debian based cross-compiling build
70-
- Much faster building. Emulating x86_64 on arm64 is very slow and vice-versa.
70+
- Much faster building. Emulating x86_64 on arm64 is very slow and vice-versa.
7171
- Replaces kernel .config's with the `defconfig` versions, via Kbuild's `make savedefconfig`
7272
- Replaces Git-SHA1-based image versioning ("current revision") with content-based hashing.
73-
- This way, there's much higher cache reuse, and new versions are pushed only when components actually changed (caveat emptor)
73+
- This way, there's much higher cache reuse, and new versions are pushed only when components actually changed (caveat emptor)
7474
- Should allow people to develop Hook without having to build a kernel, depending on CI frequency and luck.
7575
- Introduces multiple "flavors" of hook. Instead of restricted to 2 hardcoded flavors (x86_64 and aarch64, built from source), we can now define multiple flavors, each with an ID and version/configure/build methods.
76-
- the `hook-default-amd64` and `hook-default-arm64` kernels are equivalent to the two original.
77-
- the `armbian-` prefixed kernels are actually Armbian kernels for more exotic arm64 SBCs, or Armbian's generic UEFI kernels for both arches. Those are very fast to "build" since Armbian publishes their .deb packages in OCI images, and here we
76+
- the `hook-default-amd64` and `hook-default-arm64` kernels are equivalent to the two original.
77+
- the `armbian-` prefixed kernels are actually Armbian kernels for more exotic arm64 SBCs, or Armbian's generic UEFI kernels for both arches. Those are very fast to "build" since Armbian publishes their .deb packages in OCI images, and here we
7878
just download and massage them into the format required by Linuxkit.
7979
- `hook.yaml` is replaced with `hook.template.yaml` which is templated via a limited-var invocation of `envsubst`; only the kernel image and the arch is actually different per-flavor.
8080
- Auto-updating of the kernel via kernel.org's JSON endpoint (ofc only works for LTS or recent-enough stable kernels). Could opt-out/use a fixed version.
@@ -108,14 +108,14 @@ So, just running `./build.sh` will build the default flavor for the host archite
108108
Other commands are:
109109

110110
- `kernel <id>`: builds the kernel for the specified flavor
111-
- for `default` ids, this will build the kernel from source
112-
- for other methods, usually this will download & massage the kernels from a distro's packages
111+
- for `default` ids, this will build the kernel from source
112+
- for other methods, usually this will download & massage the kernels from a distro's packages
113113
- `config <id>`: runs kernel configuration for the specified flavor.
114-
- this only works for the default flavors; Foreign kernels are configured elsewhere;
115-
- it will open an interactive menuconfig session where you can change kernel config options; after exiting, `savedefconfig` will be run and the resulting file copied back to the host, ready for commit.
114+
- this only works for the default flavors; Foreign kernels are configured elsewhere;
115+
- it will open an interactive menuconfig session where you can change kernel config options; after exiting, `savedefconfig` will be run and the resulting file copied back to the host, ready for commit.
116116
- `build <id>`: builds the Hook flavor. The kernel must be either available for pulling, or have been built locally beforehand.
117117
- `qemu <id>`: builds the Hook flavor and runs it in QEMU.
118-
- this accepts `MAC=<mac>` and `TINK_SERVER=<ip>` env vars, see below
118+
- this accepts `MAC=<mac>` and `TINK_SERVER=<ip>` env vars, see below
119119

120120
Other, less common commands are:
121121

@@ -131,26 +131,27 @@ Of course, you may also set them in the environment before running the script (t
131131
The most important environment variables are:
132132

133133
- general, applies to most commands:
134-
- `DEBUG=yes`: set this to get lots of debugging messages which can make understanding the build and finding problems easier.
135-
- `HOOK_VERSION`: The Hook version, ends up in `/etc/os-release` and on the screen at boot.
136-
- `HOOK_KERNEL_OCI_BASE`: OCI base coordinates for the kernel images.
137-
- `HOOK_LK_CONTAINERS_OCI_BASE`: OCI base coordinates for the LinuxKit containers.
138-
- `CACHE_DIR`: directory where the build system will cache downloaded files. Relative to the project root.
134+
- `DEBUG=yes`: set this to get lots of debugging messages which can make understanding the build and finding problems easier.
135+
- `HOOK_VERSION`: The Hook version, ends up in `/etc/os-release` and on the screen at boot.
136+
- `HOOK_KERNEL_OCI_BASE`: OCI base coordinates for the kernel images.
137+
- `HOOK_LK_CONTAINERS_OCI_BASE`: OCI base coordinates for the LinuxKit containers.
138+
- `CACHE_DIR`: directory where the build system will cache downloaded files. Relative to the project root.
139+
- `USE_LATEST_BUILT_KERNEL`: set this to `yes` to use the latest built kernel from `quay.io/tinkerbell/hook-kernel`.
139140
- exclusively for the `qemu` command:
140-
- `TINK_SERVER=<ip>`: the IP address of the Tinkerbell GRPC server. No default.
141-
- `MAC=<mac>`: the MAC address of the machine that will be provisioned. No default.
142-
- and also
143-
- `TINK_WORKER_IMAGE`, defaults to `"quay.io/tinkerbell/tink-worker:latest"`
144-
- `TINK_TLS` defaults to `false`
145-
- `TINK_GRPC_PORT` defaults to `42113`
141+
- `TINK_SERVER=<ip>`: the IP address of the Tinkerbell GRPC server. No default.
142+
- `MAC=<mac>`: the MAC address of the machine that will be provisioned. No default.
143+
- and also
144+
- `TINK_WORKER_IMAGE`, defaults to `"quay.io/tinkerbell/tink-worker:latest"`
145+
- `TINK_TLS` defaults to `false`
146+
- `TINK_GRPC_PORT` defaults to `42113`
146147

147148
### CI (GitHub Actions)
148149

149150
- There's a distributed GitHub Actions build workflow `"matrix"`.
150-
- The bash build system produces JSON objects that drive the matrix stages:
151-
- One matrix is per-arch, and builds all the containers whose source is hosted in this repo (bootkit, docker, mdev)
152-
- Second matrix is per-flavor(/kernel), and builds the kernel
153-
- Third matrix, depending on the other two, is per-flavor(/kernel), and builds Hook itself (via LinuxKit) and prepares a .tar.gz into GH artifacts
151+
- The bash build system produces JSON objects that drive the matrix stages:
152+
- One matrix is per-arch, and builds all the containers whose source is hosted in this repo (bootkit, docker, mdev)
153+
- Second matrix is per-flavor(/kernel), and builds the kernel
154+
- Third matrix, depending on the other two, is per-flavor(/kernel), and builds Hook itself (via LinuxKit) and prepares a .tar.gz into GH artifacts
154155

155156
The `gha-matrix` CLI command prepares a set of JSON outputs for GitHub Actions matrix workflow, based on the inventory and certain environment variables:
156157

@@ -164,16 +165,8 @@ The `gha-matrix` CLI command prepares a set of JSON outputs for GitHub Actions m
164165
- [ ] Update to Linuxkit 1.2.0 and new linuxkit pkgs; this might lead into the containerd vs dind;
165166
- [ ] `make debug` functionality (sshd enabled) was lost in the Makefile -> bash transition;
166167

167-
[current_versions.sh]: https://github.com/tinkerbell/sandbox/blob/main/current_versions.sh
168-
169168
[formats]: https://github.com/linuxkit/linuxkit/blob/master/README.md#booting-and-testing
170-
171169
[linuxkit]: https://github.com/linuxkit/linuxkit
172-
173170
[osie]: https://github.com/tinkerbell/osie
174-
175-
[sandbox]: https://github.com/tinkerbell/sandbox
176-
177171
[specification]: https://github.com/linuxkit/linuxkit/blob/master/docs/yaml.md
178-
179172
[tinkerbell]: https://tinkerbell.org

bash/kernel.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ function kernel_configure_interactive() {
5555
function resolve_latest_kernel_version_lts() { # Produces KERNEL_POINT_RELEASE
5656
declare -i cache_valid=0
5757

58+
# As the point release can and does change frequently, Users can specify if they
59+
# want to use the latest known point release version. This allows users to build
60+
# HookOS using an existing kernel container image from the registry. This only works with
61+
# unauthenticated registries.
62+
if [[ -n "${USE_LATEST_BUILT_KERNEL}" ]]; then
63+
reg="$(echo ${HOOK_KERNEL_OCI_BASE} | cut -d'/' -f1)"
64+
repo="$(echo ${HOOK_KERNEL_OCI_BASE} | cut -d'/' -f2-)"
65+
# expected format is: 6.6.32-14b8be17 (major.minor.point-hash)
66+
latest_point_release="$(curl -sL "https://${reg}/v2/${repo}/tags/list" | jq -r ".tags[]" | grep -e "^${KERNEL_MAJOR}.${KERNEL_MINOR}" | sort -V | tail -n1 | cut -d"-" -f1 | cut -d"." -f3)"
67+
log info "Using latest point release from registry ${HOOK_KERNEL_OCI_BASE} for kernel ${KERNEL_MAJOR}.${KERNEL_MINOR}: ${latest_point_release}"
68+
KERNEL_POINT_RELEASE="${latest_point_release}"
69+
return 0
70+
fi
71+
5872
if [[ -f "${CACHE_DIR}/kernel-releases.json" ]]; then
5973
log debug "Found disk cached kernel-releases.json"
6074
# if the cache is older than 2 hours, refresh it

bash/kernel/kernel_default.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function calculate_kernel_version_default() {
4646
esac
4747

4848
# Grab the latest version from kernel.org
49-
declare -g KERNEL_POINT_RELEASE=""
49+
declare -g KERNEL_POINT_RELEASE="${KERNEL_POINT_RELEASE:-""}"
5050
resolve_latest_kernel_version_lts
5151

5252
# Calculate a version and hash for the OCI image

0 commit comments

Comments
 (0)