You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/build-process.md
+18-22Lines changed: 18 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ The entire build is configured from a declarative file `apko.yaml`, which does n
5
5
commands. Instead, all content is generated from installing `apk` packages.
6
6
7
7
The build process is driven by the implementation of the `apko build` command, specifically
8
-
[`BuildCmd()`](../internal/cli/build.go#L104).
8
+
[`BuildCmd()`](../internal/cli/build.go#L142).
9
9
10
10
The entire build process involves laying out the desired files in a temporary working directory, and then
11
11
packaging that working directory as an OCI filesystem layer `.tar.gz`. With that layer file in hand,
@@ -14,44 +14,40 @@ it can be packaged into an OCI image, and an SBoM can be created.
14
14
The process is as follows:
15
15
16
16
1. Create a temporary working directory.
17
-
1. Create a [`build.Context`](../pkg/build/build.go#L37-45). This `Context` contains:
18
-
* The path to the config file, default to `apko.yaml`
19
-
* The parsed config file into an internal structure [`ImageConfiguration`](../pkg/build/types/types.go#L55-83)
20
-
* The [`buildImplementation`](../pkg/build/build_implementation.go#L43-59), which is the engine responsible for executing the actual build
21
-
* The [`Executor`](../pkg/exec/exec.go#L26-31), which handles external command execution by the `buildImplementation`
17
+
2. Create a [`build.Context`](../pkg/build/build.go#L52-61). This `Context` contains:
18
+
* The parsed config file into an internal structure [`ImageConfiguration`](../pkg/build/types/types.go#L150-199)
22
19
* The [`s6.Context`](../pkg/s6/s6.go#L23-26), which contains configuration for optionally installing the s6 supervisor to manage the process in the container
23
20
* Build-time options
24
-
1. Refresh the `build.Context`, which sets initialization and runtime parameters, such as isolation, working directory, the executor and the s6 context.
25
-
1. Build the layer in the working directory, the heart of the build, calling [`build.Context.BuildLayer()`](../pkg/build/build.go#L80-109). This results in the entire laid out filesystem packaged up into a `.tar.gz` file. More detail on this follows later in this document.
26
-
1. Generate an SBoM.
27
-
1. Generate an OCI image tar file from the single layer `.tar.gz` file in [`oci.BuildImageTarballFromLayer()`](../pkg/build/oci/oci.go#L285).
21
+
3. Refresh the `build.Context`, which sets initialization and runtime parameters, such as isolation, working directory, the executor and the s6 context.
22
+
4. Build the layer in the working directory, the heart of the build, calling [`build.Context.BuildLayer()`](../pkg/build/build.go#L117-135). This results in the entire laid out filesystem packaged up into a `.tar.gz` file. More detail on this follows later in this document.
23
+
5. Generate an SBoM.
24
+
6. Generate an OCI image tar file from the single layer `.tar.gz` file in [`oci.BuildImageTarballFromLayer()`](../pkg/build/oci/image.go#L190).
28
25
29
26
## Layer Build
30
27
31
28
As described above, after everything is setup, the actual build occurs inside the working directory.
32
-
The build is in [`build.Context.BuildLayer()`](../pkg/build/build.go#L80-109), which consists of:
29
+
The build is in [`build.Context.BuildLayer()`](../pkg/build/build.go#L117-135), which consists of:
33
30
34
31
1.`Context.BuildImage()`: building the image
35
-
1.`Context.GenerateSBOM()` optionally generate the SBoM
36
32
37
-
The actual building of the image via `BuildImage()` just wraps [`buildImage()`](../pkg/build/build_implementation.go#L195-247).
33
+
The actual building of the image via `BuildImage()` just wraps [`buildImage()`](../pkg/build/build_implementation.go#L154-246).
38
34
39
35
It involves several steps:
40
36
41
37
1. Validate the image configuration. This includes setting defaults.
42
-
1. Initialize the apk. This involves setting up the various apk directories inside the working directory.
43
-
1. Add additional tags for apk packages.
44
-
1.`MutateAccounts()`: Create users and groups.
45
-
1. Set file and directory permissions.
46
-
1. Set the symlinks for busybox, as busybox is a single binary which determines what action to take based on the invoked path.
47
-
1. Update ldconfig.
48
-
1. Create the `/etc/os-release` file.
49
-
1. If s6 is used for supervision, install it and create its configuration files.
38
+
2. Initialize the apk. This involves setting up the various apk directories inside the working directory.
39
+
3. Add additional tags for apk packages.
40
+
4.`MutateAccounts()`: Create users and groups.
41
+
5. Set file and directory permissions.
42
+
6. Set the symlinks for busybox, as busybox is a single binary which determines what action to take based on the invoked path.
43
+
7. Update ldconfig.
44
+
8. Create the `/etc/os-release` file.
45
+
9. If s6 is used for supervision, install it and create its configuration files.
50
46
51
47
Note that all of the steps involve some file manipulation.
52
48
53
49
* In the case of simply laying out files or changing permissions, this is straightforward and performed in the working directory.
54
-
* In the case of apk commands, it uses the [pkg/apk/impl](../pkg/apk/impl/) implementation to lay out files directly.
50
+
* In the case of apk commands, it uses the [pkg/apk/apk/implementation](../pkg/apk/apk/implementation.go) implementation to lay out files directly.
55
51
* In the case of `chown`/`chmod`, if it cannot do so directly - either because the underlying filesystem does not support it or because it is not running as root - it ignores the errors and keeps track of the intended ownership and permissions, adding them to the final layer tar stream.
56
52
* In the case of `ldconfig`, it replicates the equivalent functionality by parsing the library ELF headers and creating the symlinks.
57
53
* In the case of `busybox`, it creates symlinks to the busybox binary, based on a fixed list.
0 commit comments