From 656ef9322d4f68f1889bc0b96a2bf09d52821dbf Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 2 Dec 2022 11:03:50 -0500 Subject: [PATCH] Add initial CI infrastructure designed for Prow This test will - build a container image derived from FCOS, injecting bootc-under-test into it - Schedule a separate container derived from coreos-assembler which has a reference to that container injected via https://docs.ci.openshift.org/docs/architecture/ci-operator/#referring-to-images-in-tests - Run the stable FCOS base image via kola (qemu), injecting the target oscontainer - Execute a basic test that just verifies `status --json` today However, in the future we can change the build system to generate multiple container images, and test upgrades, rollbacks, etc. Signed-off-by: Colin Walters --- .dockerignore | 2 ++ .gitignore | 1 + Makefile | 13 +++++++++++++ ci/Dockerfile.ci | 10 ++++++++++ ci/Dockerfile.fcos | 10 ++++++++++ ci/run-kola.sh | 20 ++++++++++++++++++++ tests/kolainst/basic | 24 ++++++++++++++++++++++++ 7 files changed, 80 insertions(+) create mode 100644 .dockerignore create mode 100644 Makefile create mode 100644 ci/Dockerfile.ci create mode 100644 ci/Dockerfile.fcos create mode 100755 ci/run-kola.sh create mode 100644 tests/kolainst/basic diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..eae2fec0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.cosa +target diff --git a/.gitignore b/.gitignore index b59902fd..72355c7c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ example /target Cargo.lock +bootc.tar.zst diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..84eff857 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +prefix ?= /usr + +all: + cargo build --release + +install: + install -D -t $(DESTDIR)$(prefix)/bin target/release/bootc + +bin-archive: all + $(MAKE) install DESTDIR=tmp-install && tar --zstd -C tmp-install -cf bootc.tar.zst . && rm tmp-install -rf + +install-kola-tests: + install -D -t $(DESTDIR)$(prefix)/lib/coreos-assembler/tests/kola/bootc tests/kolainst/basic diff --git a/ci/Dockerfile.ci b/ci/Dockerfile.ci new file mode 100644 index 00000000..fc9f2643 --- /dev/null +++ b/ci/Dockerfile.ci @@ -0,0 +1,10 @@ +# This really just depends on `cosa run`, which we could +# in theory split out separately at some point later. +FROM quay.io/coreos-assembler/coreos-assembler:latest +WORKDIR /srv +USER root +# Grab all of our ci scripts +COPY /src/ci/ /ci/ +RUN ln -sr /ci/run-kola.sh /usr/bin/bootc-run-kola +USER builder +CMD ["/usr/bin/bootc-run-kola"] diff --git a/ci/Dockerfile.fcos b/ci/Dockerfile.fcos new file mode 100644 index 00000000..2d79eb36 --- /dev/null +++ b/ci/Dockerfile.fcos @@ -0,0 +1,10 @@ +# This Dockerfile generates a container image that installs bootc into +# a Fedora CoreOS image. +FROM quay.io/coreos-assembler/fcos-buildroot:testing-devel as builder +WORKDIR /src +COPY . . +RUN make bin-archive + +FROM quay.io/fedora/fedora-coreos:testing-devel +COPY --from=builder /src/bootc.tar.zst /tmp +RUN tar -xvf /tmp/bootc.tar.zst && ostree container commit diff --git a/ci/run-kola.sh b/ci/run-kola.sh new file mode 100755 index 00000000..22a90f57 --- /dev/null +++ b/ci/run-kola.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -xeuo pipefail + +# We require the an image containing bootc-under-test to have been injected +# by an external system, e.g. Prow +# https://docs.ci.openshift.org/docs/architecture/ci-operator/#referring-to-images-in-tests +if test -z "${TARGET_IMAGE:-}"; then + echo "fatal: Must set TARGET_IMAGE" 1>&2; exit 1 +fi +echo "Test base image: ${TARGET_IMAGE}" + +tmpdir="$(mktemp -d -p /var/tmp)" +cd "${tmpdir}" +if test -z "${BASE_QEMU_IMAGE:-}"; then + coreos-installer download -p qemu -f qcow2.xz --decompress + BASE_QEMU_IMAGE="$(echo *.qcow2)" +fi +kola run --oscontainer ostree-unverified-registry:${TARGET_IMAGE} --qemu-image "./${BASE_QEMU_IMAGE}" ext.bootc.'*' + +echo "ok kola bootc" diff --git a/tests/kolainst/basic b/tests/kolainst/basic new file mode 100644 index 00000000..7f45519c --- /dev/null +++ b/tests/kolainst/basic @@ -0,0 +1,24 @@ +#!/bin/bash +# Verify basic bootc functionality. +## kola: +## timeoutMin: 30 +## tags: "needs-internet" +# +# Copyright (C) 2022 Red Hat, Inc. + +set -xeuo pipefail + +cd $(mktemp -d) + +case "${AUTOPKGTEST_REBOOT_MARK:-}" in + "") + bootc status --json > status.json + image=$(jq -r '.[0].image.image' < status.json) + echo "booted into $image" + + # TODO more tests here + + echo "ok status test" + ;; + *) echo "unexpected mark: ${AUTOPKGTEST_REBOOT_MARK}"; exit 1;; +esac