Skip to content

Commit a9846fc

Browse files
Merge pull request #23 from gardenlinux/doc
add docs
2 parents ca6b3f7 + 231e162 commit a9846fc

File tree

3 files changed

+166
-1
lines changed

3 files changed

+166
-1
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ By default, the Builder uses `podman` as the container engine. If you prefer usi
2626

2727
A config directory serves as the input for the Builder and is used to create a Linux system image. It consists of the following components:
2828

29-
- **`features` directory**: Contains sub-directories for each feature. You can create your own features by referring to the example in [gardenlinux/features/example](https://github.com/gardenlinux/gardenlinux/tree/main/features/example).
29+
- **`features` directory**: Contains sub-directories for each feature. You can create your own features by referring to [features.md](docs/features.md).
3030

3131
- **`cert` directory** (optional): If you plan to use secure boot, include a `cert` directory.
3232

@@ -38,6 +38,8 @@ In addition to the above components, your configuration directory must include t
3838
- `get_version`: This script should output the version of the package repository to use. For example, use `bookworm` for Debian or `today` for Garden Linux.
3939
- `keyring.gpg`: The PGP key used to validate the package repository. For Debian, you can obtain this key from the [debian-archive-keyring](https://packages.debian.org/bookworm/debian-archive-keyring) package.
4040

41+
For a quick start guide on setting up your own config directory with your own features checkout [getting_started.md](docs/getting_started.md).
42+
4143
### Example Config Directory
4244

4345
If you're new to configuring the Builder, you can find a minimal example config directory at [gardenlinux/builder_example](https://github.com/gardenlinux/builder_example). For a more comprehensive example, refer to the main [gardenlinux](https://github.com/gardenlinux/gardenlinux) repository.

docs/features.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Features
2+
3+
Each feature must at least contain an `info.yaml` file
4+
5+
The `info.yaml` file has the following structure fields:
6+
7+
- `description`: (*optional*) a string explaining what this feature does / what it is used for.
8+
- `type`: can be any of `platform`, `element`, or `flag`. The builder does not make any technical distinction between each type of feature, however it is strongly encouraged that each image uses exactly one platform and flags should only perform minor changes and not include any other features.
9+
- `features`: (*optional*) sub-structure containing related features
10+
- `include`: (*optional*) list of features that will automatically be included as well if this feature gets included
11+
- `exclude`: (*optional*) list of features that are incompatible with this feature. If any of these features were included implicitly from another they will be removed from the feature set. If they were explicitly provided as part of the target the build will fail.
12+
13+
An example `info.yaml` looks as follows:
14+
15+
```yaml
16+
description: example platform feature
17+
type: platform
18+
features:
19+
include:
20+
- A
21+
- B
22+
exclude:
23+
- C
24+
```
25+
26+
Additionally a feature may contain any of the following:
27+
28+
## `pkg.include`
29+
30+
A list of packages to be installed into the image.
31+
32+
## `pkg.exclude`
33+
34+
A list of packages to be ignored if provided by another features `pkg.include`
35+
36+
## `file.include`
37+
38+
A directory containing files to copy into the target rootfs.
39+
This directory is copied recursively into the root directory.
40+
By default only the executable bit of the files permission will be preserved when copying.
41+
The other permissions will be set to read write for owner and read for group and other.
42+
The owner of all copied files will be root by default.
43+
44+
To overwrite these defaults see `file.stat` below
45+
46+
## `file.stat`
47+
48+
A file to assign owner and permissions to files copied by `file.include`.
49+
Each line should contain an entry of the form:
50+
51+
```
52+
user group permissions file
53+
```
54+
55+
## `file.exclude`
56+
57+
A list of files / directories to remove from the rootfs at the end of the configure stage.
58+
Wildcard in file paths are allowed.
59+
60+
## `exec.config` `exec.early` `exec.late` `exec.post`
61+
62+
Scripts to be executed to configure the image.
63+
All scripts except `exec.post` are executed inside the rootfs of the system being build without any parameters.
64+
`exec.post` is executed inside the builder container with the path of the rootfs provided as `argv[1]`.
65+
66+
The order of exectution is as follows:
67+
68+
- bootstrap (outside chroot)
69+
- `exec.early`
70+
- package install (from `pkg.include`)
71+
- copy files from `file.include` and set permissions according to `file.stat`
72+
- `exec.config`
73+
- `exec.late`
74+
- remove files according to `file.exclude`
75+
- `exec.post` (outside chroot)
76+
77+
When building with multiple features the execution steps of each feature are interleaved; so for example the `exec.config` step will run for all features before any features `exec.late` runs.

docs/getting_started.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Getting started
2+
3+
These instructions will guide you through how to create a custom linux image using the builder.
4+
We will start from the builder example repo, and build our own feature on top to add an `nginx` http server.
5+
6+
First clone the builder example repo:
7+
8+
```shell
9+
git clone https://github.com/gardenlinux/builder_example
10+
cd builder_example
11+
```
12+
13+
At this point you can test, that your local podman install works by running `./build base`.
14+
This should create a bootable debian bookworm disk image at `.build/base-amd64-bookworm-6f72b564.raw` (the commit may have changed since the time of writing).
15+
You can test run the image with
16+
17+
```shell
18+
qemu-system-x86_64 -m 2048 -nodefaults -display none -serial mon:stdio -drive if=pflash,unit=0,readonly=on,format=raw,file=/usr/share/OVMF/OVMF_CODE.fd -drive if=virtio,format=raw,file=.build/base-amd64-bookworm-6f72b564.raw
19+
```
20+
21+
Now that we know all local tooling works, let's start building our own feature.
22+
23+
1. Create a feature directory called `nginx`.
24+
25+
```shell
26+
mkdir features/nginx
27+
```
28+
29+
2. create a file `features/nginx/info.yaml` and edit it using the editor of your choice to have the following content:
30+
31+
```yaml
32+
description: http server using nginx
33+
type: element
34+
```
35+
36+
3. create a file `features/nginx/pkg.include` with the following content:
37+
38+
```
39+
nginx
40+
```
41+
42+
4. create a file `features/nginx/exec.config` with the following content:
43+
44+
```shell
45+
#!/usr/bin/env bash
46+
47+
set -eufo pipefail
48+
49+
systemctl enable nginx
50+
```
51+
52+
5. make this executable `chmod +x features/nginx/exec.config`
53+
54+
6. create a `/var/www/html` directory inside the nginx `file.include` directory
55+
56+
```shell
57+
mkdir -p features/nginx/file.include/var/www/html
58+
```
59+
60+
7. create a dummy `index.html` file inside `features/nginx/file.include/var/www/html` with content like the following or whatever you like:
61+
62+
```html
63+
<!DOCTYPE html>
64+
<html>
65+
<body>
66+
<p>Hello World!</p>
67+
</body>
68+
</html>
69+
```
70+
71+
With this we have created our own first feature for the builder.
72+
Test it by building with
73+
74+
```shell
75+
./build base-nginx
76+
```
77+
78+
and running with
79+
80+
```shell
81+
qemu-system-x86_64 -m 2048 -nodefaults -display none -serial mon:stdio -drive if=pflash,unit=0,readonly=on,format=raw,file=/usr/share/OVMF/OVMF_CODE.fd -drive if=virtio,format=raw,file=.build/base-nginx-amd64-bookworm-local.raw -netdev user,id=net0,hostfwd=tcp::8080-:80 -device virtio-net-pci,netdev=net0
82+
```
83+
84+
if everything worked as intended you should see the system boot up and once booted opening http://localhost:8080 in a browser should display the hello world message.
85+
86+
Congrats, you have just successfully created a feature for the builder :tada:

0 commit comments

Comments
 (0)