From 46700ab794ce7ea6cfa8824e8f7815ee8a8a1033 Mon Sep 17 00:00:00 2001 From: Gerald Pinder Date: Fri, 9 Feb 2024 11:47:59 -0500 Subject: [PATCH] chore: Create base integration test setup (#55) This will allow us to create a suite of tests for our new features rather than using my personal image repo --- .github/workflows/build-pr.yml | 8 +-- .github/workflows/build.yml | 5 ++ Earthfile | 69 +------------------ integration-tests/Earthfile | 57 +++++++++++++++ integration-tests/mock-scripts/buildah | 3 + integration-tests/mock-scripts/podman | 3 + integration-tests/mock-scripts/rpm-ostree | 3 + .../test-repo/config/files/usr/.gitkeep | 0 .../test-repo/config/files/usr/test-file | 1 + integration-tests/test-repo/config/recipe.yml | 52 ++++++++++++++ .../test-repo/config/scripts/example.sh | 10 +++ integration-tests/test-repo/modules/.gitkeep | 0 .../modules/test-module/test-module.sh | 5 ++ 13 files changed, 143 insertions(+), 73 deletions(-) create mode 100644 integration-tests/Earthfile create mode 100755 integration-tests/mock-scripts/buildah create mode 100755 integration-tests/mock-scripts/podman create mode 100755 integration-tests/mock-scripts/rpm-ostree create mode 100644 integration-tests/test-repo/config/files/usr/.gitkeep create mode 100644 integration-tests/test-repo/config/files/usr/test-file create mode 100644 integration-tests/test-repo/config/recipe.yml create mode 100644 integration-tests/test-repo/config/scripts/example.sh create mode 100644 integration-tests/test-repo/modules/.gitkeep create mode 100644 integration-tests/test-repo/modules/test-module/test-module.sh diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index 6841f63..28fab9c 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -17,18 +17,16 @@ jobs: version: v0.8.3 - name: Earthly login - env: - EARTHLY_SAT_TOKEN: ${{ secrets.EARTHLY_SAT_TOKEN }} - if: env.EARTHLY_SAT_TOKEN != null + if: github.repository == 'blue-build/cli' run: | earthly account login --token ${{ secrets.EARTHLY_SAT_TOKEN }} >> /dev/null earthly org s blue-build - earthly sat s blue-build-pr + earthly sat s blue-build - uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.ref }} - name: Run build - run: earthly --ci -P +build + run: earthly --ci -P +all diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 38d4020..21c55c1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,6 +22,7 @@ jobs: version: v0.8.3 - name: Earthly login + if: github.repository == 'blue-build/cli' run: | earthly account login --token ${{ secrets.EARTHLY_SAT_TOKEN }} >> /dev/null earthly org s blue-build @@ -40,4 +41,8 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Run build + if: github.repository == 'blue-build/cli' run: earthly --push --ci -P +all + - name: Run build + if: github.repository != 'blue-build/cli' + run: earthly --ci -P +all diff --git a/Earthfile b/Earthfile index 0ae1ec1..6fe19d1 100644 --- a/Earthfile +++ b/Earthfile @@ -7,7 +7,7 @@ ARG --global IMAGE=ghcr.io/blue-build/cli all: BUILD +build - BUILD +integration-tests --NIGHTLY=true --NIGHTLY=false + BUILD ./integration-tests+all --NIGHTLY=true --NIGHTLY=false build: BUILD +default @@ -26,13 +26,6 @@ default: nightly: BUILD +default --NIGHTLY=true -integration-tests: - ARG NIGHTLY=false - BUILD +integration-test-template --NIGHTLY=$NIGHTLY - BUILD +integration-test-build --NIGHTLY=$NIGHTLY - BUILD +integration-test-rebase --NIGHTLY=$NIGHTLY - BUILD +integration-test-upgrade --NIGHTLY=$NIGHTLY - lint: FROM +common @@ -115,66 +108,6 @@ installer: ARG INSTALLER=true DO cargo+SAVE_IMAGE --IMAGE=$IMAGE --TAG=$TAG --LATEST=$LATEST --NIGHTLY=$NIGHTLY --INSTALLER=$INSTALLER -integration-test-template: - ARG NIGHTLY=false - FROM DOCKERFILE -f +integration-test-template-containerfile/test/Containerfile +integration-test-template-containerfile/test/* --NIGHTLY=$NIGHTLY - -integration-test-template-containerfile: - ARG NIGHTLY=false - FROM +integration-test-base --NIGHTLY=$NIGHTLY - RUN bluebuild -vv template config/recipe-jp-desktop.yml | tee Containerfile - - SAVE ARTIFACT /test - -integration-test-build: - ARG NIGHTLY=false - FROM +integration-test-base --NIGHTLY=$NIGHTLY - - RUN --privileged bluebuild -vv build config/recipe-jp-desktop.yml - -integration-test-rebase: - ARG NIGHTLY=false - FROM +integration-test-base --NIGHTLY=$NIGHTLY - - RUN --privileged bluebuild -vv rebase config/recipe-jp-desktop.yml - -integration-test-upgrade: - ARG NIGHTLY=false - FROM +integration-test-base --NIGHTLY=$NIGHTLY - RUN mkdir -p /etc/bluebuild && touch /etc/bluebuild/jp-desktop.tar.gz - - RUN --privileged bluebuild -vv upgrade config/recipe-jp-desktop.yml - -integration-test-base: - ARG NIGHTLY=false - - FROM +blue-build-cli-alpine --NIGHTLY=$NIGHTLY - - RUN echo "#!/bin/sh - echo 'Running podman'" > /usr/bin/podman \ - && chmod +x /usr/bin/podman - - RUN echo "#!/bin/sh - echo 'Running buildah'" > /usr/bin/buildah \ - && chmod +x /usr/bin/buildah - - RUN echo "#!/bin/sh - echo 'Running rpm-ostree'" > /usr/bin/rpm-ostree \ - && chmod +x /usr/bin/rpm-ostree - - GIT CLONE https://gitlab.com/wunker-bunker/wunker-os.git /test - WORKDIR /test - -iso-generator: - FROM registry.fedoraproject.org/fedora-toolbox - - GIT CLONE https://github.com/ublue-os/isogenerator.git /isogenerator - WORKDIR /isogenerator - ARG PACKAGES=$(cat deps.txt) - RUN dnf install --disablerepo="*" --enablerepo="fedora,updates" --setopt install_weak_deps=0 --assumeyes $PACKAGES - - SAVE IMAGE --push $IMAGE/iso-generator - cosign: FROM gcr.io/projectsigstore/cosign SAVE ARTIFACT /ko-app/cosign diff --git a/integration-tests/Earthfile b/integration-tests/Earthfile new file mode 100644 index 0000000..344ac5c --- /dev/null +++ b/integration-tests/Earthfile @@ -0,0 +1,57 @@ +VERSION 0.8 +PROJECT blue-build/cli + +all: + ARG NIGHTLY=false + BUILD +build-template --NIGHTLY=$NIGHTLY + BUILD +build --NIGHTLY=$NIGHTLY + BUILD +rebase --NIGHTLY=$NIGHTLY + BUILD +upgrade --NIGHTLY=$NIGHTLY + +build-template: + ARG NIGHTLY=false + FROM DOCKERFILE \ + -f +template-containerfile/test/Containerfile \ + +template-containerfile/test/* --NIGHTLY=$NIGHTLY + RUN [ -f /usr/test-file ] + +template-containerfile: + ARG NIGHTLY=false + FROM +test-base --NIGHTLY=$NIGHTLY + RUN bluebuild -vv template config/recipe.yml | tee Containerfile + + SAVE ARTIFACT /test + +build: + ARG NIGHTLY=false + FROM +test-base --NIGHTLY=$NIGHTLY + + RUN --privileged bluebuild -vv build config/recipe.yml + +rebase: + ARG NIGHTLY=false + FROM +test-base --NIGHTLY=$NIGHTLY + + RUN --privileged bluebuild -vv rebase config/recipe.yml + +upgrade: + ARG NIGHTLY=false + FROM +test-base --NIGHTLY=$NIGHTLY + RUN mkdir -p /etc/bluebuild && touch /etc/bluebuild/template.tar.gz + + RUN --privileged bluebuild -vv upgrade config/recipe.yml + +test-base: + ARG NIGHTLY=false + + FROM ../+blue-build-cli-alpine --NIGHTLY=$NIGHTLY + + COPY ./mock-scripts/ /usr/bin/ + + WORKDIR /test + COPY ./test-repo /test + + # Setup a cosign key pair + RUN echo -n "\n\n" | cosign generate-key-pair + ENV COSIGN_PRIVATE_KEY=$(cat cosign.key) + RUN rm cosign.key diff --git a/integration-tests/mock-scripts/buildah b/integration-tests/mock-scripts/buildah new file mode 100755 index 0000000..fc8d2ee --- /dev/null +++ b/integration-tests/mock-scripts/buildah @@ -0,0 +1,3 @@ +#!/bin/sh + +echo 'Running buildah' diff --git a/integration-tests/mock-scripts/podman b/integration-tests/mock-scripts/podman new file mode 100755 index 0000000..92ef8f3 --- /dev/null +++ b/integration-tests/mock-scripts/podman @@ -0,0 +1,3 @@ +#!/bin/sh + +echo 'Running podman' diff --git a/integration-tests/mock-scripts/rpm-ostree b/integration-tests/mock-scripts/rpm-ostree new file mode 100755 index 0000000..f0ec128 --- /dev/null +++ b/integration-tests/mock-scripts/rpm-ostree @@ -0,0 +1,3 @@ +#!/bin/sh + +echo 'Running rpm-ostree' diff --git a/integration-tests/test-repo/config/files/usr/.gitkeep b/integration-tests/test-repo/config/files/usr/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/integration-tests/test-repo/config/files/usr/test-file b/integration-tests/test-repo/config/files/usr/test-file new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/integration-tests/test-repo/config/files/usr/test-file @@ -0,0 +1 @@ + diff --git a/integration-tests/test-repo/config/recipe.yml b/integration-tests/test-repo/config/recipe.yml new file mode 100644 index 0000000..43de3a4 --- /dev/null +++ b/integration-tests/test-repo/config/recipe.yml @@ -0,0 +1,52 @@ +# image will be published to ghcr.io// +name: template +# description will be included in the image's metadata +description: This is my personal OS image. + +# the base image to build on top of (FROM) and the version tag to use +base-image: ghcr.io/ublue-os/silverblue-main +image-version: 39 # latest is also supported if you want new updates ASAP + +# module configuration, executed in order +# you can include multiple instances of the same module +modules: + - type: files + files: + - usr: /usr # copies config/files/usr into your image's /usr. + # put configuration files you want in /etc/ on a booted system + # in /usr/etc/ in the image. read more in files module reference. + + - type: script + scripts: + - example.sh + + - type: rpm-ostree + repos: + - https://copr.fedorainfracloud.org/coprs/atim/starship/repo/fedora-%OS_VERSION%/atim-starship-fedora-%OS_VERSION%.repo + install: + - micro + - starship + remove: + - firefox # default firefox removed in favor of flatpak + - firefox-langpacks # langpacks needs to also be removed to prevent dependency problems + + - type: default-flatpaks + notify: true # Send notification after install/uninstall is finished (true/false) + system: + # If no repo information is specified, Flathub will be used by default + # repo-url: https://dl.flathub.org/repo/flathub.flatpakrepo + # repo-name: flathub + # repo-title: "Flathub (system-wide)" # Optional; this sets the remote's user-facing name in graphical frontends like GNOME Software + install: + - org.mozilla.firefox + - org.gnome.Loupe + - one.ablaze.floorp//lightning # This is an example of flatpak which has multiple branches in selection (flatpak//branch). + # Flatpak runtimes are not supported (like org.winehq.Wine//stable-23.08), + # only normal flatpak applications are (like Floorp Lightning web browser in this example). + # Installing different branches of the same Flatpak is not supported. + remove: + - org.gnome.eog + + - type: signing # this sets up the proper policy & signing files for signed images to work fully + - type: test-module + diff --git a/integration-tests/test-repo/config/scripts/example.sh b/integration-tests/test-repo/config/scripts/example.sh new file mode 100644 index 0000000..fdb2e04 --- /dev/null +++ b/integration-tests/test-repo/config/scripts/example.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +# Tell this script to exit if there are any errors. +# You should have this in every custom script, to ensure that your completed +# builds actually ran successfully without any errors! +set -oue pipefail + +# Your code goes here. +echo 'This is an example shell script' +echo 'Scripts here will run during build if specified in recipe.yml' diff --git a/integration-tests/test-repo/modules/.gitkeep b/integration-tests/test-repo/modules/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/integration-tests/test-repo/modules/test-module/test-module.sh b/integration-tests/test-repo/modules/test-module/test-module.sh new file mode 100644 index 0000000..ab26db5 --- /dev/null +++ b/integration-tests/test-repo/modules/test-module/test-module.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -euo pipefail + +echo "This is a test module"