From 8d233edcf27a7f5081d7cc54151b63237ff2af5f Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Tue, 14 Nov 2023 19:09:47 -0500 Subject: [PATCH] test: add busybox image, use it to mostly replace centos image (#545) This is basically the add of BUSYBOX image and then using that instead of centos image. Moving to busybox from centos required a few changed assumptions: * drop -P from grep - busybox's grep did not support -P. instead use posix groups ([:space:]) * don't use long --format for 'stat' - busybox stat didn't like this, so just use '-c'. * mount - /usr/bin/mount -> /bin/mount - busybox image only has /bin, not /usr/bin/mount * /bin/bash - busybox image does not have bin/bash The tests "squashfs empty change no layer" and "tar empty change no layer" do not work with the busybox image. There are layers created, and they have this content: $ tar tvf oci/blobs/sha256/acff571f8cf*b03f45 tar: Removing leading `/' from member names drwxr-xr-x 0/0 0 2023-11-13 14:06 / drwxr-xr-x 0/0 0 2023-11-13 14:06 etc/ ---------- 0/0 0 2023-11-13 14:06 etc/resolv.conf drwxr-xr-x 0/0 0 2023-11-13 14:06 proc/ drwxr-xr-x 0/0 0 2023-11-13 14:06 sys/ The content there are results of stacker. I don't have a good way to avoid them at the moment. I've also left the bom tests in place with the centos image. Those would have had to have been adjusted and probably would not work with busybox at the moment. Signed-off-by: Scott Moser --- Makefile | 9 ++++- test/annotations-namespace.bats | 4 +-- test/annotations.bats | 2 +- test/args.bats | 2 +- test/asterisk.bats | 2 +- test/atomfs.bats | 8 ++--- test/basic.bats | 64 ++++++++++++++++----------------- test/binds.bats | 8 ++--- test/broken-link.bats | 2 +- test/build-only.bats | 40 ++++++++++----------- test/built-type.bats | 2 +- test/caching.bats | 24 ++++++------- test/chroot.bats | 2 +- test/clean.bats | 2 +- test/config.bats | 8 ++--- test/dependency-order.bats | 2 +- test/dirlinks.bats | 2 +- test/docker-base.bats | 10 +++--- test/entrypoint.bats | 2 +- test/env.bats | 6 ++-- test/helpers.bash | 3 ++ test/import-http.bats | 10 +++--- test/import.bats | 50 +++++++++++++------------- test/invalid.bats | 6 ++-- test/labels.bats | 2 +- test/log.bats | 4 +-- test/multi-arch.bats | 8 ++--- test/multiple-output-types.bats | 12 +++---- test/oci-import.bats | 26 +++++++------- test/overlay-dirs.bats | 17 ++++----- test/prerequisites.bats | 16 ++++----- test/publish.bats | 6 ++-- test/squashfs.bats | 48 ++++++++++++------------- test/tmpfs.bats | 2 +- test/unprivileged.bats | 28 +++++++-------- 35 files changed, 225 insertions(+), 214 deletions(-) diff --git a/Makefile b/Makefile index bdebeb69..5dd54a16 100644 --- a/Makefile +++ b/Makefile @@ -20,9 +20,15 @@ build_stacker = go build -tags "$(BUILD_TAGS) $1" -ldflags "-X main.version=$(VE STACKER_DOCKER_BASE?=docker://ghcr.io/project-stacker/ # They default to their image name in STACKER_DOCKER_BASE STACKER_BUILD_BASE_IMAGE?=$(STACKER_DOCKER_BASE)alpine:edge +STACKER_BUILD_BUSYBOX_IMAGE?=$(STACKER_DOCKER_BASE)busybox:latest STACKER_BUILD_CENTOS_IMAGE?=$(STACKER_DOCKER_BASE)centos:latest STACKER_BUILD_UBUNTU_IMAGE?=$(STACKER_DOCKER_BASE)ubuntu:latest -STACKER_BUILD_IMAGES = $(STACKER_BUILD_BASE_IMAGE) $(STACKER_BUILD_CENTOS_IMAGE) $(STACKER_BUILD_UBUNTU_IMAGE) +STACKER_BUILD_IMAGES = \ + $(STACKER_BUILD_BASE_IMAGE) \ + $(STACKER_BUILD_BUSYBOX_IMAGE) \ + $(STACKER_BUILD_CENTOS_IMAGE) \ + $(STACKER_BUILD_UBUNTU_IMAGE) + LXC_CLONE_URL?=https://github.com/lxc/lxc LXC_BRANCH?=stable-5.0 @@ -128,6 +134,7 @@ test: stacker $(REGCLIENT) $(SKOPEO) $(ZOT) LXC_BRANCH=$(LXC_BRANCH) \ LXC_CLONE_URL=$(LXC_CLONE_URL) \ STACKER_BUILD_BASE_IMAGE=$(STACKER_BUILD_BASE_IMAGE) \ + STACKER_BUILD_BUSYBOX_IMAGE=$(STACKER_BUILD_BUSYBOX_IMAGE) \ STACKER_BUILD_CENTOS_IMAGE=$(STACKER_BUILD_CENTOS_IMAGE) \ STACKER_BUILD_UBUNTU_IMAGE=$(STACKER_BUILD_UBUNTU_IMAGE) \ ./test/main.py \ diff --git a/test/annotations-namespace.bats b/test/annotations-namespace.bats index d8210279..e9f2ae00 100644 --- a/test/annotations-namespace.bats +++ b/test/annotations-namespace.bats @@ -13,7 +13,7 @@ function teardown() { thing: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI run: ls EOF stacker build --annotations-namespace=namespace.example @@ -28,7 +28,7 @@ EOF thing: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI run: ls EOF stacker build diff --git a/test/annotations.bats b/test/annotations.bats index 82feba6a..81025017 100644 --- a/test/annotations.bats +++ b/test/annotations.bats @@ -13,7 +13,7 @@ function teardown() { thing: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI run: ls annotations: a.b.c.key: val diff --git a/test/args.bats b/test/args.bats index f987491d..004a814f 100644 --- a/test/args.bats +++ b/test/args.bats @@ -13,7 +13,7 @@ function teardown() { parent: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI child: from: type: built diff --git a/test/asterisk.bats b/test/asterisk.bats index 39abb122..39e42409 100644 --- a/test/asterisk.bats +++ b/test/asterisk.bats @@ -13,7 +13,7 @@ function teardown() { a: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI run: | mkdir /mybin cp /bin/* /mybin diff --git a/test/atomfs.bats b/test/atomfs.bats index 2c05a502..8215af97 100644 --- a/test/atomfs.bats +++ b/test/atomfs.bats @@ -16,7 +16,7 @@ function basic_test() { test: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI run: | touch /hello EOF @@ -48,7 +48,7 @@ EOF base: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI run: touch /base a: from: @@ -105,7 +105,7 @@ EOF # c should still be ok [ -f c/c ] - [ -f c/sbin/init ] + [ -f c/bin/sh ] stacker internal-go atomfs umount c # c's last layer shouldn't exist any more, since it is unique @@ -121,7 +121,7 @@ EOF test: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI run: | touch /hello EOF diff --git a/test/basic.bats b/test/basic.bats index dbf496e7..70414df9 100644 --- a/test/basic.bats +++ b/test/basic.bats @@ -10,10 +10,10 @@ function teardown() { @test "multiple stacker builds in a row" { cat > stacker.yaml < import @@ -28,10 +28,10 @@ EOF @test "basic workings" { cat > stacker.yaml < stacker.yaml < stacker.yaml < stacker.yaml < stacker.yaml < /root/tree1/foo run: | @@ -29,7 +29,7 @@ EOF bind_path=$(realpath tree1/foo) - out=$(stacker build --substitute bind_path=${bind_path} --substitute CENTOS_OCI=$CENTOS_OCI) + out=$(stacker build --substitute bind_path=${bind_path} --substitute BUSYBOX_OCI=$BUSYBOX_OCI) [[ "${out}" =~ ^(.*filesystem bind-test built successfully)$ ]] @@ -41,7 +41,7 @@ EOF bind-test: from: type: oci - url: ${{CENTOS_OCI}} + url: ${{BUSYBOX_OCI}} binds: - source: ${{bind_path1}} dest: /root/tree1/foo @@ -65,7 +65,7 @@ EOF out=$(stacker build \ "--substitute=bind_path1=${bind_path1}" \ "--substitute=bind_path2=${bind_path2}" \ - "--substitute=CENTOS_OCI=$CENTOS_OCI" ) || { + "--substitute=BUSYBOX_OCI=$BUSYBOX_OCI" ) || { printf "%s\n" "$out" 1>&2 exit 1 } diff --git a/test/broken-link.bats b/test/broken-link.bats index ce776e9f..a43391b7 100644 --- a/test/broken-link.bats +++ b/test/broken-link.bats @@ -14,7 +14,7 @@ function teardown() { broken_link: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI import: - dir run: cp -a /stacker/imports/dir/testln /testln diff --git a/test/build-only.bats b/test/build-only.bats index b3d0f1c7..3d251d04 100644 --- a/test/build-only.bats +++ b/test/build-only.bats @@ -14,7 +14,7 @@ function teardown() { parent: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI EOF cat > stacker.yaml < stacker.yaml < stacker.yaml < stacker.yaml <> tree2/foo/zomg # The layer should be rebuilt since the there is a bind configuration in stacker.yaml - stacker build --substitute bind_path=${bind_path} --substitute CENTOS_OCI=$CENTOS_OCI + stacker build --substitute bind_path=${bind_path} --substitute BUSYBOX_OCI=$BUSYBOX_OCI [[ "${output}" =~ ^(.*filesystem bind-test built successfully)$ ]] [[ ! "${output}" =~ ^(.*found cached layer bind-test)$ ]] } @@ -168,7 +168,7 @@ EOF mode-test: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI import: - executable run: cp /stacker/imports/executable /executable @@ -203,7 +203,7 @@ EOF test: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI import: - foo run: cp /stacker/imports/foo /foo @@ -218,7 +218,7 @@ EOF test: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI EOF stacker build echo '{"version": 1, "cache": "lolnope"}' > .stacker/build.cache diff --git a/test/chroot.bats b/test/chroot.bats index 831fd539..c7d19921 100644 --- a/test/chroot.bats +++ b/test/chroot.bats @@ -14,7 +14,7 @@ function teardown() { thing: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI run: touch /test EOF stacker build diff --git a/test/clean.bats b/test/clean.bats index f0102df4..0eea2b29 100644 --- a/test/clean.bats +++ b/test/clean.bats @@ -13,7 +13,7 @@ function teardown() { test: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI EOF stacker build stacker clean diff --git a/test/config.bats b/test/config.bats index 60790868..5c4fd9c3 100644 --- a/test/config.bats +++ b/test/config.bats @@ -18,7 +18,7 @@ function teardown() { test: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI EOF stacker "--oci-dir=$tmpd/args-oci" "--stacker-dir=$tmpd/args-stacker" \ @@ -37,7 +37,7 @@ EOF test: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI EOF cat > "$tmpd/config.yaml" < stacker.yaml < img/stacker1.yaml < img/stacker1.yaml < stacker.yaml < stacker.yaml < stacker.yaml < stacker.yaml < stacker.yaml < stacker2.yaml < /stacker/oci-labels/meshuggah EOF diff --git a/test/log.bats b/test/log.bats index 4a38cccc..853bef62 100644 --- a/test/log.bats +++ b/test/log.bats @@ -34,7 +34,7 @@ function teardown() { test: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI EOF stacker --progress build @@ -46,7 +46,7 @@ EOF test: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI EOF stacker build diff --git a/test/multi-arch.bats b/test/multi-arch.bats index 3755b0d5..2360f3dc 100644 --- a/test/multi-arch.bats +++ b/test/multi-arch.bats @@ -10,12 +10,12 @@ function teardown() { @test "multi-arch/os support" { cat > stacker.yaml < stacker.yaml < /rocks EOF @@ -36,7 +36,7 @@ EOF parent: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI run: | echo meshuggah > /rocks child: @@ -72,7 +72,7 @@ EOF parent: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI run: | echo meshuggah > /rocks build_only: true @@ -109,7 +109,7 @@ EOF parent: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI run: | echo meshuggah > /rocks EOF @@ -124,7 +124,7 @@ EOF one: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI two: build_only: true from: @@ -176,7 +176,7 @@ EOF one: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI two: build_only: true from: diff --git a/test/oci-import.bats b/test/oci-import.bats index f7b8ef75..d54d0393 100644 --- a/test/oci-import.bats +++ b/test/oci-import.bats @@ -13,18 +13,18 @@ function teardown() { output1: from: type: oci - url: oci:centos + url: oci:busybox output2: from: type: oci - url: oci:centos + url: oci:busybox EOF - image_copy oci:$CENTOS_OCI oci:oci:centos + image_copy oci:$BUSYBOX_OCI oci:oci:busybox stacker build name0=$(cat oci/index.json | jq -r .manifests[0].annotations.'"org.opencontainers.image.ref.name"') - [ "$name0" == "centos" ] + [ "$name0" == "busybox" ] name1=$(cat oci/index.json | jq -r .manifests[1].annotations.'"org.opencontainers.image.ref.name"') [ "$name1" == "output1" ] name2=$(cat oci/index.json | jq -r .manifests[2].annotations.'"org.opencontainers.image.ref.name"') @@ -33,28 +33,28 @@ EOF @test "oci imports" { cat > stacker.yaml < stacker.yaml < /dir_to_overlay run: | @@ -98,7 +98,7 @@ EOF first: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI overlay_dirs: - source: dir_to_overlay dest: /usr/local @@ -122,7 +122,7 @@ EOF first: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI overlay_dirs: - source: dir_to_overlay1 dest: /usr/local1 @@ -178,14 +178,15 @@ EOF first: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI overlay_dirs: - source: dir_to_overlay dest: /usr/local run: | [ -f /usr/local/file ] - [ "\$(stat --format=%G /usr/local/file )" == "root" ] - [ "\$(stat --format=%U /usr/local/file )" == "root" ] + # -c == --format, but busybox does not support --format + [ "\$(stat -c%G /usr/local/file )" == "root" ] + [ "\$(stat -c%U /usr/local/file )" == "root" ] EOF stacker build diff --git a/test/prerequisites.bats b/test/prerequisites.bats index 44a91f56..04052788 100644 --- a/test/prerequisites.bats +++ b/test/prerequisites.bats @@ -8,7 +8,7 @@ function setup() { layer1_1: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI import: - import1 run: | @@ -16,7 +16,7 @@ layer1_1: layer1_2: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI run: touch /root/import0 EOF @@ -161,7 +161,7 @@ EOF one: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI run: | touch /one EOF @@ -212,7 +212,7 @@ EOF one: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI run: | touch /one EOF @@ -246,7 +246,7 @@ EOF one: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI EOF stacker recursive-build @@ -260,11 +260,11 @@ EOF same: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI same: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI EOF bad_stacker build | grep "duplicate layer name" } @@ -274,7 +274,7 @@ EOF same: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI EOF cat > b.yaml < /root/ls_out EOF diff --git a/test/squashfs.bats b/test/squashfs.bats index 7da20da5..feed5da9 100644 --- a/test/squashfs.bats +++ b/test/squashfs.bats @@ -18,7 +18,7 @@ function teardown() { build: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI build_only: true importer: from: @@ -32,20 +32,20 @@ EOF @test "squashfs mutate /usr/bin" { cat > stacker.yaml < stacker.yaml < stacker.yaml < stacker.yaml < stacker.yaml < stacker.yaml < stacker.yaml < /message @@ -191,16 +191,16 @@ EOF @test "built type with squashfs build-only base works (overlay)" { mkdir -p .stacker/layer-bases chmod 777 .stacker/layer-bases - image_copy oci:$CENTOS_OCI oci:.stacker/layer-bases/oci:centos - umoci unpack --image .stacker/layer-bases/oci:centos dest - tar caf .stacker/layer-bases/centos.tar -C dest/rootfs . + image_copy oci:$BUSYBOX_OCI oci:.stacker/layer-bases/oci:busybox + umoci unpack --image .stacker/layer-bases/oci:busybox dest + tar caf .stacker/layer-bases/busybox.tar -C dest/rootfs . rm -rf dest cat > stacker.yaml < /message build_only: true diff --git a/test/tmpfs.bats b/test/tmpfs.bats index 4bca7059..2eb46d78 100644 --- a/test/tmpfs.bats +++ b/test/tmpfs.bats @@ -13,7 +13,7 @@ function teardown() { test: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI run: | echo hello world EOF diff --git a/test/unprivileged.bats b/test/unprivileged.bats index 40c71592..1db0a475 100644 --- a/test/unprivileged.bats +++ b/test/unprivileged.bats @@ -13,14 +13,14 @@ function teardown() { parent: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI run: | touch /etc/000 chmod 000 /etc/000 child: from: type: oci - url: $CENTOS_OCI + url: $BUSYBOX_OCI run: | echo "zomg" > /etc/000 chmod 000 /etc/000 @@ -38,10 +38,10 @@ EOF @test "unprivileged stacker" { cat > stacker.yaml < stacker.yaml <