Compare commits

...

No commits in common. "main" and "lib/main" have entirely different histories.

5 changed files with 91 additions and 46 deletions

7
.editorconfig Normal file
View File

@ -0,0 +1,7 @@
root = true
[*.sh]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
stage3-*.tar.*
latest-*.txt

View File

@ -1,55 +1,62 @@
# Aimee OS Build Container Images
This repository contains the build scripts for the container images that
provide the build environment for Aimee OS projects. Most projects will use
the _build/build-{target}_ image, which contains a cross-compiler toolchain for
the _{target}_ system (e.g. _aarch64-unknown-linux-gnu_) with Rust support, as
well as several other tools for compiling software and creating bootable OS
images.
Prerequisites:
* `buildah`
## Container Images
## Gentoo Stage 3 Image
There are several images in the collection:
```
gentoo/stage3 †
build/base
└── build/cross-aarch64-unknown-linux-gnu
└── build/build-aarch64-unknown-linux-gnu ‡
```
† The _gentoo/stage3_ image contains an unmodified Gentoo stage3 system. It is
used to bootstrap the _build/base_ image.
‡ Although the _build/build-{target}_ image is initially populated from the
corresponding _build/cross-{target}_ image, the final image is "squashed" into
a single layer to minimize download size.
## Git Branches
To enable building images in Jenkins without building all of the preceding
images, each image has its own Jenkins job. Since Jenkins does not support
(auto discovering) multiple jobs in a single Git repository branch, the build
scripts for the images are tracked in separate branches. Each branch is named
like _{image}/{sub-branch}_, where _{image}_ is the short name of the image
(e.g. `base`, `cross`, etc) and _{sub-branch}_ is an arbitrary name (e.g.
_main_).
* _base/main_: This branch is responsible for building _gentoo/stage3_ and
_build/base_.
* _cross/main_: This branch contains the build script for
_build/cross-{target}_.
* _build/main_: This branch builds _build/build-{target}_.
In addition to the per-image branches, there is also _lib/{sub-branch}_.
Code shared by multiple image build scripts is tracked here. Build scripts
expect the shared code to be available in the `lib` directory, which is
generally populated using a Git worktree, e.g.:
This image is used to bootstrap the base layer for Aimee OS build images. To
build it, use the `gentoo-stage3.sh` build script. This script takes a single
(optional) positional argument: the name of a Gentoo stage 3 tarball to use to
produce the container image. If none is specified, the latest
`stage3-amd64-nomultilib-openrc` tarball is downloaded and used.
```sh
git worktree add lib lib/main
sh image-build/gentoo-stage3.sh
```
The _main_ branch itself is empty except for this README.
## Base Image
The Aimee OS base build image is a minimal environment based on Gentoo. It
includes Portage and a basic build toolchain. Building it requires a Stage 3
image to bootstrap the environment. By default,
_aimee-os.org/gentoo/stage3-amd64-nomultilib-openrc:latest_ is used, but an
alternative image can be specified using the `-b`/`--base` argument to the
`base.sh` script.
```sh
sh image-build/base.sh
```
## Crossdev Image
This image includes a cross-compilation toolchain, generated by _crossdev_. It
is built using the `cross.sh` script. This script takes a `-t`/`--target`
argument, which specifies the toolchain to generate. The default is
`aarch64-unknown-linux-gnu`. This image is layered on top of the base image,
which can be specified using the `-b`/`--base` argument. By default,
_aimee-os.org/build/base:latest_ is used.
```sh
sh image-build/cross.sh
```
## Build Image
The top-level image is based on the Crossdev image, and includes additional
tools for building an Aimee OS project. It is built using the `build.sh` script.
As with the Crossdev image build script, this script accepts `-t`/`--target`
and `-b`/`--build` arguments, which specify the cross-compilation toolchain and
base image later, respectively.
```sh
sh image-build/build.sh
```
This image is "squashed," meaning it consists of only a single layer. The Base
and Crossdev image layers are merged into the final layer when the image is
built. This reduces the final size of the image.

21
common.sh Normal file
View File

@ -0,0 +1,21 @@
#!/bin/sh
buildah_run_script() {
local cid script
cid=$1
shift
script=$(readlink -f "$1")
shift
mkdir -p binpkgs log tmp
buildah run \
--mount type=cache,target=/var/db/repos/gentoo \
--mount type=cache,target=/var/cache \
--mount type=bind,src="${PWD}"/log,target=/var/log,rw,z \
--mount type=bind,src="${PWD}"/tmp,target=/var/tmp,rw,z \
--mount type=bind,src="${PWD}"/binpkgs,target=/var/cache/binpkgs,rw,z \
--mount type=bind,src="${script}",target=/run/script,ro,z \
--tty=false \
-e FEATURES='-ipc-sandbox -network-sandbox -pid-sandbox' \
"${cid}" \
/run/script "$@"
}

8
sync.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
if [ ! -e /var/db/repos/gentoo/metadata ]; then
emerge-webrsync
fi
if [ "$(find /var/db/repos/gentoo/metadata -newermt '-24 hours' | wc -l)" -eq 0 ]; then
emaint sync
fi