Skip to content

Commit

Permalink
Refactor Docker build process
Browse files Browse the repository at this point in the history
  • Loading branch information
korewaChino committed Nov 7, 2023
1 parent 8aa9533 commit 5399663
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 113 deletions.
158 changes: 158 additions & 0 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
name: Build Docker images
env:
KATSU_BUILD_TASK_NAME: "Build image"
DNF_PKGS: |
git
xorriso
rpm
limine
systemd
btrfs-progs
e2fsprogs
xfsprogs
dosfstools
grub2
parted
util-linux-core
systemd-container
grub2-efi
uboot-images-armv8
uboot-tools
rustc
qemu-user-static-aarch64
qemu-user-binfmt
qemu-kvm
qemu-img
cargo
systemd-devel
mkpasswd
clang-devel
moby-engine
squashfs-tools
erofs-utils
grub2-tools
grub2-tools-extra
isomd5sum
moby-engine
podman
buildah
on:
push:
workflow_dispatch:

jobs:
#### DOCKER ######

docker:
strategy:
fail-fast: false
matrix:
variant:
- base/base-docker-x86_64
- base/base-docker-aarch64

outputs:
artifact: ${{ matrix.variant }}
# ubuntu-latest unless we're building aarch64
runs-on: ${{ matrix.variant == 'base/base-docker-aarch64' && 'arm64' || 'ubuntu-latest' }}
container:
image: ghcr.io/terrapkg/builder:f38
# Pass /dev from host to container
# Very hacky, but it works
# Microsoft/Github, if you're reading this,
# I'm sorry.
options: --privileged -v /dev:/dev

steps:
- name: Install dependencies
run: |
dnf install -y $DNF_PKGS
dnf clean all
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Clone Katsu
uses: actions/checkout@v3
with:
repository: FyraLabs/katsu
ref: main
path: katsu
- name: Build Katsu
run: |
pushd katsu
cargo build --release
cp target/release/katsu /usr/bin/katsu
popd
- name: Checkout
uses: actions/checkout@v2

- name: sanitize artifact name
run: |
name=$(echo ${{ matrix.variant }} | sed 's/\//-/g')
# set github variable
echo artifact=$name >> $GITHUB_ENV
# get architecture
# e.g. base/base-docker-x86_64 -> x86_64
echo arch=$(echo ${{ matrix.variant }} | cut -d'-' -f3) >> $GITHUB_ENV
- name: ${{ env.KATSU_BUILD_TASK_NAME }}
run: |
pushd katsu
katsu --output=fs modules/${{ matrix.variant }}.yaml
if [ ${{ env.arch }} == "x86_64" ]; then
host_arch="amd64"
elif [ ${{ env.arch }} == "aarch64" ]; then
host_arch="arm64"
fi
# tarball katsu-work/chroot then import using podman with tag ghcr.io/ultramarine-linux/ultramarine:39
tar -C katsu-work/chroot -c . | podman import --change='CMD ["/usr/bin/bash"]' - ghcr.io/ultramarine-linux/ultramarine:39 --arch $host_arch
podman save --format oci-archive ghcr.io/ultramarine-linux/ultramarine:39 --output katsu-work/image/katsu.tar.xz
popd
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.artifact }}-docker
path: katsu/katsu-work/image/*.tar.xz

#### DOCKER PUSH ######

docker-push:
strategy:
fail-fast: false
runs-on: ubuntu-latest
needs: docker

steps:
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y buildah
- name: Log in to ghcr.io
uses: redhat-actions/podman-login@v1
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io

# how do i combine those two images into one multiarch tag

- name: Download artifacts
uses: actions/download-artifact@v3

- name: Publish to registry
run: |
set -x
MANIFEST="ghcr.io/ultramarine-linux/ultramarine:39"
ls -lR
buildah manifest create $MANIFEST
buildah manifest add $MANIFEST oci-archive:base-base-docker-x86_64-docker/katsu.tar.xz --arch amd64
buildah manifest add $MANIFEST oci-archive:base-base-docker-aarch64-docker/katsu.tar.xz --arch arm64
# also tag as latest
buildah tag $MANIFEST $MANIFEST:latest || :
buildah manifest push --all --format v2s2 $MANIFEST docker://$MANIFEST || :
#### LIVE ISO ####
114 changes: 1 addition & 113 deletions .github/workflows/build-katsu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,120 +104,8 @@ jobs:
name: ${{ env.artifact }}-image
path: katsu/katsu-work/image/*.img.xz

#### DOCKER ######

docker:
strategy:
fail-fast: false
matrix:
variant:
- base/base-docker-x86_64
- base/base-docker-aarch64

outputs:
artifact: ${{ matrix.variant }}
runs-on: ubuntu-latest
container:
image: ghcr.io/terrapkg/builder:f38
# Pass /dev from host to container
# Very hacky, but it works
# Microsoft/Github, if you're reading this,
# I'm sorry.
options: --privileged -v /dev:/dev

steps:
- name: Install dependencies
run: |
dnf install -y $DNF_PKGS
dnf clean all
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Clone Katsu
uses: actions/checkout@v3
with:
repository: FyraLabs/katsu
ref: main
path: katsu
- name: Build Katsu
run: |
pushd katsu
cargo build --release
cp target/release/katsu /usr/bin/katsu
popd
- name: Checkout
uses: actions/checkout@v2

- name: sanitize artifact name
run: |
name=$(echo ${{ matrix.variant }} | sed 's/\//-/g')
# set github variable
echo artifact=$name >> $GITHUB_ENV
# get architecture
# e.g. base/base-docker-x86_64 -> x86_64
echo arch=$(echo ${{ matrix.variant }} | cut -d'-' -f3) >> $GITHUB_ENV
- name: ${{ env.KATSU_BUILD_TASK_NAME }}
run: |
pushd katsu
katsu --output=fs modules/${{ matrix.variant }}.yaml
if [ ${{ env.arch }} == "x86_64" ]; then
host_arch="amd64"
elif [ ${{ env.arch }} == "aarch64" ]; then
host_arch="arm64"
fi
# tarball katsu-work/chroot then import using podman with tag ghcr.io/ultramarine-linux/ultramarine:39
tar -C katsu-work/chroot -c . | podman import --change='CMD ["/usr/bin/bash"]' - ghcr.io/ultramarine-linux/ultramarine:39 --arch $host_arch
podman save --format oci-archive ghcr.io/ultramarine-linux/ultramarine:39 --output katsu-work/image/katsu.tar.xz
popd
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.artifact }}-docker
path: katsu/katsu-work/image/*.tar.xz

#### DOCKER PUSH ######

docker-push:
strategy:
fail-fast: false
runs-on: ubuntu-latest
needs: docker

steps:
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y buildah
- name: Log in to ghcr.io
uses: redhat-actions/podman-login@v1
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io

# how do i combine those two images into one multiarch tag

- name: Download artifacts
uses: actions/download-artifact@v3

- name: Publish to registry
run: |
set -x
MANIFEST="ghcr.io/ultramarine-linux/ultramarine:39"
ls -lR
buildah manifest create $MANIFEST
buildah manifest add $MANIFEST oci-archive:base-base-docker-x86_64-docker/katsu.tar.xz --arch amd64
buildah manifest add $MANIFEST oci-archive:base-base-docker-aarch64-docker/katsu.tar.xz --arch arm64
# also tag as latest
buildah tag $MANIFEST $MANIFEST:latest || :
buildah manifest push --all --format v2s2 $MANIFEST docker://$MANIFEST || :
buildah manifest push --all --format v2s2 $MANIFEST docker://ghcr.io/ultramarine-linux/ultramarine:latest || :

#### LIVE ISO ####

live-iso:
strategy:
Expand Down Expand Up @@ -280,7 +168,7 @@ jobs:

#### LIVE ISO PUSH ####

push-live-iso:
push-image:
runs-on: ubuntu-latest
environment: production
needs:
Expand Down

0 comments on commit 5399663

Please sign in to comment.