Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

Commit

Permalink
Make Builds configurable (#14)
Browse files Browse the repository at this point in the history
Allows to configure build variables via files

Fixes #12
  • Loading branch information
fwilhe authored Dec 4, 2023
1 parent 406482d commit 6d5b1c9
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 62 deletions.
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"cSpell.words": [
"bootable",
"gardenlinux",
"ostree",
"Stateroot",
"trixie"
]
}
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

> [!IMPORTANT]
> This repository is part of a proof of concept.
The Garden Linux team does not provide any support or gurantee for this repository.
The Garden Linux team does not provide any support or guarantee for this repository.
Feel free to open an issue if something does not work, but please be aware of the experimental status of this repository.

Builder for [OSTree](https://ostreedev.github.io/ostree/)-based operating system images using the [Garden Linux Builder](https://github.com/gardenlinux/builder).
Expand All @@ -27,6 +27,14 @@ This directory contains a lot of code taken from the [gardenlinux/gardenlinux](h

This repo contains two os builder definitions.

Builds can be parameterized to change certain default values.
To change any of the values, create a file using the parameter name inside the feature directory.
This might be needed in both the `ostreeRepo` and the `ostreeImage` feature.

- `REMOTE_URL`: Hostname to use as OSTree remote, default value is `http://ostree.gardenlinux.io`
- `OS_NAME`: OS Name (Stateroot) used for OSTree, default value is either `debian` or `gardenlinux`, change this if you want to build a custom OS
- `REMOTE_NAME`: Name for the OSTree remote (similar to remote 'origin' in git), default value is either `debian` or `gardenlinux`, change this if you want to build a custom OS

### Debian

To build the debian image yourself, run inside the `debian` directory:
Expand All @@ -46,11 +54,13 @@ This applies both to the Garden Linux and the Debian builder.

### Garden Linux

Additionally to the build parameters defined above, the Garden Linux build has another parameter called `BUILD_VARIANT`.

To build the Garden Linux yourself, run inside the `gardenlinux` directory:

```bash
# Required: Set the platform. Must match between what is set in the BUILD_VARIANT file and in the repo argument.
# Allowd values for PLATFORM: kvm, metal
# Allowed values for PLATFORM: kvm, metal
$ PLATFORM=kvm
$ echo $PLATFORM > features/ostreeRepo/BUILD_VARIANT
$ echo $PLATFORM > features/ostreeImage/BUILD_VARIANT
Expand All @@ -66,7 +76,7 @@ You don't need to run `ostreeRepo` locally.
To build an image based on your self-created repo, copy the output file from the `ostreeRepo` build to `gardenlinux/features/ostreeImage/ostree-gardenlinux-repo-$(PLATFORM)-(amd64/arm64).tar.gz`, depending on your local architecture and the selected platform.
This applies both to the Garden Linux and the Debian builder.

Alternativly, use the `./ostree-build.sh` script:
Alternatively, use the `./ostree-build.sh` script:

```bash
./ostree-build.sh kvm
Expand Down
3 changes: 3 additions & 0 deletions debian/features/ostreeImage/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
REMOTE_URL
OS_NAME
REMOTE_NAME
ostree-debian-repo*.tar.gz
38 changes: 22 additions & 16 deletions debian/features/ostreeImage/image.ostree.raw
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

set -euxo pipefail

REMOTE_URL=$([ -f /builder/features/ostreeImage/REMOTE_URL ] && cat /builder/features/ostreeImage/REMOTE_URL || echo http://ostree.gardenlinux.io)
OS_NAME=$([ -f /builder/features/ostreeImage/OS_NAME ] && cat /builder/features/ostreeImage/OS_NAME || echo debian)
REMOTE_NAME=$([ -f /builder/features/ostreeImage/REMOTE_NAME ] && cat /builder/features/ostreeImage/REMOTE_NAME || echo debian)
REMOTE_ARCHIVE_NAME=ostree-${OS_NAME}-repo-${BUILDER_ARCH}.tar.gz
LOCAL_ARCHIVE_PATH=/builder/features/ostreeImage/$REMOTE_ARCHIVE_NAME
REMOTE_REPO_PATH=${OS_NAME}-repo-${BUILDER_ARCH}
echo Build Configuration:
echo REMOTE_URL: $REMOTE_URL
echo REMOTE_REPO_PATH: $REMOTE_REPO_PATH
echo OS_NAME: $OS_NAME

export PATH="/builder/image.d:$PATH"

rootfs_work="$(mktemp -d)"
Expand All @@ -11,15 +22,10 @@ MYROOT="$(mktemp -d)"
mount -t tmpfs tmpfs "$MYROOT"
mkdir -p "$MYROOT"/sysroot
mkdir -p "$MYROOT"/sysroot/ostree/deploy
mkdir -p "$MYROOT"/sysroot/ostree/deploy/debian/var
mkdir -p "$MYROOT"/sysroot/ostree/deploy/${OS_NAME}/var
OSTREE_SYSROOT="$MYROOT/sysroot"
OSTREE_REPO=$OSTREE_SYSROOT/ostree/repo
OSTREE_REF="debian/testing/$BUILDER_ARCH"

REMOTE_URL="http://ostree.gardenlinux.io"
REMOTE_ARCHIVE_NAME=ostree-debian-repo-${BUILDER_ARCH}.tar.gz

LOCAL_ARCHIVE_PATH=/builder/features/ostreeImage/$REMOTE_ARCHIVE_NAME
OSTREE_REF="${OS_NAME}/testing/$BUILDER_ARCH"

rootfs="$1"
output="$2"
Expand All @@ -43,18 +49,18 @@ else
rm -rf $download
fi

ostree admin deploy --karg=root=LABEL=ROOT --karg-append=rw --karg-append=efi=runtime --sysroot=$OSTREE_SYSROOT --os=debian $OSTREE_REF
ostree admin deploy --karg=root=LABEL=ROOT --karg-append=rw --karg-append=efi=runtime --sysroot=$OSTREE_SYSROOT --os=${OS_NAME} $OSTREE_REF

boot_hash=`ls "$OSTREE_SYSROOT"/ostree/boot.1.1/debian/`
mkdir -p "$OSTREE_SYSROOT"/ostree/boot.1.1/debian/$boot_hash/0/sysroot
boot_hash=`ls "$OSTREE_SYSROOT"/ostree/boot.1.1/${OS_NAME}/`
mkdir -p "$OSTREE_SYSROOT"/ostree/boot.1.1/${OS_NAME}/$boot_hash/0/sysroot

mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/debian/var/home
mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/debian/var/home/user
mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/debian/var/roothome
mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/debian/var/opt
mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/debian/var/srv
mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/${OS_NAME}/var/home
mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/${OS_NAME}/var/home/user
mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/${OS_NAME}/var/roothome
mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/${OS_NAME}/var/opt
mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/${OS_NAME}/var/srv

chown 1000:1000 "$OSTREE_SYSROOT"/ostree/deploy/debian/var/home/user
chown 1000:1000 "$OSTREE_SYSROOT"/ostree/deploy/${OS_NAME}/var/home/user

# Build disk image, this is hacky as of now, needs rework
# Setup bootloader
Expand Down
3 changes: 3 additions & 0 deletions debian/features/ostreeRepo/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
REMOTE_URL
OS_NAME
REMOTE_NAME
ostree-debian-repo*.tar.gz
26 changes: 17 additions & 9 deletions debian/features/ostreeRepo/image.ostreeRepo.tar.gz
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

set -euxo pipefail

REMOTE_URL=$([ -f /builder/features/ostreeRepo/REMOTE_URL ] && cat /builder/features/ostreeRepo/REMOTE_URL || echo http://ostree.gardenlinux.io)
OS_NAME=$([ -f /builder/features/ostreeRepo/OS_NAME ] && cat /builder/features/ostreeRepo/OS_NAME || echo debian)
REMOTE_NAME=$([ -f /builder/features/ostreeRepo/REMOTE_NAME ] && cat /builder/features/ostreeRepo/REMOTE_NAME || echo debian)
REMOTE_ARCHIVE_NAME=ostree-${OS_NAME}-repo-${BUILDER_ARCH}.tar.gz
LOCAL_ARCHIVE_PATH=/builder/features/ostreeRepo/$REMOTE_ARCHIVE_NAME
REMOTE_REPO_PATH=${OS_NAME}-repo-${BUILDER_ARCH}
LOCAL_ARCHIVE_PATH=/builder/features/ostreeRepo/$REMOTE_ARCHIVE_NAME
echo Build Configuration:
echo REMOTE_URL: $REMOTE_URL
echo REMOTE_REPO_PATH: $REMOTE_REPO_PATH
echo OS_NAME: $OS_NAME

export PATH="/builder/image.d:$PATH"

rootfs_work="$(mktemp -d)"
Expand All @@ -12,11 +24,7 @@ mount -t tmpfs tmpfs "$MYROOT"
mkdir -p "$MYROOT"/sysroot
OSTREE_SYSROOT="$MYROOT/sysroot"
OSTREE_REPO=$OSTREE_SYSROOT/ostree/repo
OSTREE_REF="debian/testing/$BUILDER_ARCH"

REMOTE_URL="http://ostree.gardenlinux.io"
REMOTE_ARCHIVE_NAME=ostree-debian-repo-${BUILDER_ARCH}.tar.gz
REMOTE_NAME=debian-repo-${BUILDER_ARCH}
OSTREE_REF="${OS_NAME}/testing/$BUILDER_ARCH"

LOCAL_ARCHIVE_PATH=/builder/features/ostreeRepo/$REMOTE_ARCHIVE_NAME

Expand All @@ -42,17 +50,17 @@ else
echo "Coud use local file from $LOCAL_ARCHIVE_PATH or remote file from $REMOTE_URL/$REMOTE_ARCHIVE_NAME, building new repo"
ostree init --mode=archive --repo=$OSTREE_REPO
ostree admin init-fs --modern $OSTREE_SYSROOT
ostree admin os-init --sysroot=$OSTREE_SYSROOT debian
ostree admin os-init --sysroot=$OSTREE_SYSROOT ${OS_NAME}
ostree config --repo=$OSTREE_REPO set sysroot.bootloader none
fi

popd
rm -rf $download

ostree remote --repo=$OSTREE_REPO delete --if-exists origin
ostree remote --repo=$OSTREE_REPO add --no-gpg-verify --no-sign-verify origin $REMOTE_URL/$REMOTE_NAME $OSTREE_REF
ostree remote --repo=$OSTREE_REPO delete --if-exists ${REMOTE_NAME}
ostree remote --repo=$OSTREE_REPO add --no-gpg-verify --no-sign-verify ${REMOTE_NAME} $REMOTE_URL/$REMOTE_REPO_PATH $OSTREE_REF

ostree commit --repo=$OSTREE_REPO --branch $OSTREE_REF --skip-if-unchanged -s "Debian $REMOTE_NAME $(date --utc +%Y-%m-%dT%H:%M%Z)" "$rootfs_work"
ostree commit --repo=$OSTREE_REPO --branch $OSTREE_REF --skip-if-unchanged -s "Debian $REMOTE_REPO_PATH $(date --utc +%Y-%m-%dT%H:%M%Z)" "$rootfs_work"

ostree log --repo=$OSTREE_REPO $OSTREE_REF

Expand Down
3 changes: 3 additions & 0 deletions gardenlinux/features/ostreeImage/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
BUILD_VARIANT
REMOTE_URL
OS_NAME
REMOTE_NAME
ostree-gardenlinux-repo*.tar.gz
41 changes: 21 additions & 20 deletions gardenlinux/features/ostreeImage/image.ostree.raw
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

set -euxo pipefail

# BUILD_VARIANT determains which repo we need to download (like metal, kvm, gcp, aws, azure, ..)
# Use kvm as default variant when nothing is configured
BUILD_VARIANT=$([ -f /builder/features/ostreeImage/BUILD_VARIANT ] && cat /builder/features/ostreeImage/BUILD_VARIANT || echo kvm)
REMOTE_URL=$([ -f /builder/features/ostreeImage/REMOTE_URL ] && cat /builder/features/ostreeImage/REMOTE_URL || echo http://ostree.gardenlinux.io)
OS_NAME=$([ -f /builder/features/ostreeImage/OS_NAME ] && cat /builder/features/ostreeImage/OS_NAME || echo gardenlinux)
REMOTE_ARCHIVE_NAME=ostree-${OS_NAME}-repo-${BUILD_VARIANT}-${BUILDER_ARCH}.tar.gz
LOCAL_ARCHIVE_PATH=/builder/features/ostreeImage/$REMOTE_ARCHIVE_NAME
echo Build Configuration:
echo BUILD_VARIANT: $BUILD_VARIANT
echo REMOTE_URL: $REMOTE_URL
echo OS_NAME: $OS_NAME

export PATH="/builder/image.d:$PATH"

rootfs_work="$(mktemp -d)"
Expand All @@ -11,25 +23,14 @@ MYROOT="$(mktemp -d)"
mount -t tmpfs tmpfs "$MYROOT"
mkdir -p "$MYROOT"/sysroot
mkdir -p "$MYROOT"/sysroot/ostree/deploy
mkdir -p "$MYROOT"/sysroot/ostree/deploy/gardenlinux/var
mkdir -p "$MYROOT"/sysroot/ostree/deploy/${OS_NAME}/var
OSTREE_SYSROOT="$MYROOT/sysroot"
OSTREE_REPO=$OSTREE_SYSROOT/ostree/repo
OSTREE_REF="gardenlinux/today/$BUILDER_ARCH"

# BUILD_VARIANT determains which repo we need to download (like metal, kvm, gcp, aws, azure, ..)
BUILD_VARIANT=$([ -f /builder/features/ostreeImage/BUILD_VARIANT ] && cat /builder/features/ostreeImage/BUILD_VARIANT || echo '')
# Use kvm as default variant when nothing is configured
BUILD_VARIANT="${BUILD_VARIANT:-kvm}"
REMOTE_URL="http://ostree.gardenlinux.io"
REMOTE_ARCHIVE_NAME=ostree-gardenlinux-repo-${BUILD_VARIANT}-${BUILDER_ARCH}.tar.gz
REMOTE_NAME=gardenlinux-repo-${BUILD_VARIANT}-${BUILDER_ARCH}
LOCAL_ARCHIVE_PATH=/builder/features/ostreeImage/$REMOTE_ARCHIVE_NAME
OSTREE_REF="${OS_NAME}/today/$BUILDER_ARCH"

rootfs="$1"
output="$2"

echo Building variant $BUILD_VARIANT

tar xf "$rootfs" -C "$rootfs_work"

mkdir -p $OSTREE_REPO
Expand All @@ -49,15 +50,15 @@ else
rm -rf $download
fi

ostree admin deploy --karg=root=LABEL=ROOT --karg-append=rw --karg-append=efi=runtime --sysroot=$OSTREE_SYSROOT --os=gardenlinux $OSTREE_REF
ostree admin deploy --karg=root=LABEL=ROOT --karg-append=rw --karg-append=efi=runtime --sysroot=$OSTREE_SYSROOT --os=${OS_NAME} $OSTREE_REF

boot_hash=`ls "$OSTREE_SYSROOT"/ostree/boot.1.1/gardenlinux/`
mkdir -p "$OSTREE_SYSROOT"/ostree/boot.1.1/gardenlinux/$boot_hash/0/sysroot
boot_hash=`ls "$OSTREE_SYSROOT"/ostree/boot.1.1/${OS_NAME}/`
mkdir -p "$OSTREE_SYSROOT"/ostree/boot.1.1/${OS_NAME}/$boot_hash/0/sysroot

mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/gardenlinux/var/home
mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/gardenlinux/var/roothome
mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/gardenlinux/var/opt
mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/gardenlinux/var/srv
mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/${OS_NAME}/var/home
mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/${OS_NAME}/var/roothome
mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/${OS_NAME}/var/opt
mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/${OS_NAME}/var/srv

# Build disk image, this is hacky as of now, needs rework
# Setup bootloader
Expand Down
3 changes: 3 additions & 0 deletions gardenlinux/features/ostreeRepo/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
BUILD_VARIANT
REMOTE_URL
OS_NAME
REMOTE_NAME
ostree-gardenlinux-repo*.tar.gz
34 changes: 20 additions & 14 deletions gardenlinux/features/ostreeRepo/image.ostreeRepo.tar.gz
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

set -euxo pipefail

# BUILD_VARIANT determains which repo we need to download (like metal, kvm, gcp, aws, azure, ..)
# Use kvm as default variant when nothing is configured
BUILD_VARIANT=$([ -f /builder/features/ostreeRepo/BUILD_VARIANT ] && cat /builder/features/ostreeRepo/BUILD_VARIANT || echo kvm)
REMOTE_URL=$([ -f /builder/features/ostreeRepo/REMOTE_URL ] && cat /builder/features/ostreeRepo/REMOTE_URL || echo http://ostree.gardenlinux.io)
OS_NAME=$([ -f /builder/features/ostreeRepo/OS_NAME ] && cat /builder/features/ostreeRepo/OS_NAME || echo gardenlinux)
REMOTE_NAME=$([ -f /builder/features/ostreeRepo/REMOTE_NAME ] && cat /builder/features/ostreeRepo/REMOTE_NAME || echo gardenlinux)
REMOTE_ARCHIVE_NAME=ostree-${OS_NAME}-repo-${BUILD_VARIANT}-${BUILDER_ARCH}.tar.gz
LOCAL_ARCHIVE_PATH=/builder/features/ostreeRepo/$REMOTE_ARCHIVE_NAME
REMOTE_REPO_PATH=${OS_NAME}-repo-${BUILD_VARIANT}-${BUILDER_ARCH}
LOCAL_ARCHIVE_PATH=/builder/features/ostreeRepo/$REMOTE_ARCHIVE_NAME
echo Build Configuration:
echo BUILD_VARIANT: $BUILD_VARIANT
echo REMOTE_URL: $REMOTE_URL
echo REMOTE_REPO_PATH: $REMOTE_REPO_PATH
echo OS_NAME: $OS_NAME

export PATH="/builder/image.d:$PATH"

rootfs_work="$(mktemp -d)"
Expand All @@ -12,17 +28,7 @@ mount -t tmpfs tmpfs "$MYROOT"
mkdir -p "$MYROOT"/sysroot
OSTREE_SYSROOT="$MYROOT/sysroot"
OSTREE_REPO=$OSTREE_SYSROOT/ostree/repo
OSTREE_REF="gardenlinux/today/$BUILDER_ARCH"

# BUILD_VARIANT determains which repo we need to download (like metal, kvm, gcp, aws, azure, ..)
BUILD_VARIANT=$([ -f /builder/features/ostreeRepo/BUILD_VARIANT ] && cat /builder/features/ostreeRepo/BUILD_VARIANT || echo '')
# Use kvm as default variant when nothing is configured
BUILD_VARIANT="${BUILD_VARIANT:-kvm}"
REMOTE_URL="http://ostree.gardenlinux.io"
REMOTE_ARCHIVE_NAME=ostree-gardenlinux-repo-${BUILD_VARIANT}-${BUILDER_ARCH}.tar.gz
REMOTE_NAME=gardenlinux-repo-${BUILD_VARIANT}-${BUILDER_ARCH}

LOCAL_ARCHIVE_PATH=/builder/features/ostreeRepo/$REMOTE_ARCHIVE_NAME
OSTREE_REF="${OS_NAME}/today/$BUILDER_ARCH"

rootfs="$1"
output="$2"
Expand All @@ -48,15 +54,15 @@ else
echo "Coud use local file from $LOCAL_ARCHIVE_PATH or remote file from $REMOTE_URL/$REMOTE_ARCHIVE_NAME, building new repo"
ostree init --mode=archive --repo=$OSTREE_REPO
ostree admin init-fs --modern $OSTREE_SYSROOT
ostree admin os-init --sysroot=$OSTREE_SYSROOT gardenlinux
ostree admin os-init --sysroot=$OSTREE_SYSROOT ${OS_NAME}
ostree config --repo=$OSTREE_REPO set sysroot.bootloader none
fi

popd
rm -rf $download

ostree remote --repo=$OSTREE_REPO delete --if-exists origin
ostree remote --repo=$OSTREE_REPO add --no-gpg-verify --no-sign-verify origin $REMOTE_URL/$REMOTE_NAME $OSTREE_REF
ostree remote --repo=$OSTREE_REPO delete --if-exists ${REMOTE_NAME}
ostree remote --repo=$OSTREE_REPO add --no-gpg-verify --no-sign-verify ${REMOTE_NAME} $REMOTE_URL/$REMOTE_REPO_PATH $OSTREE_REF

ostree commit --repo=$OSTREE_REPO --branch $OSTREE_REF --skip-if-unchanged -s "Garden Linux $BUILD_VARIANT $(date --utc +%Y-%m-%dT%H:%M%Z)" "$rootfs_work"

Expand Down

0 comments on commit 6d5b1c9

Please sign in to comment.