Skip to content

Commit

Permalink
test: add busybox image, use it to replace centos image.
Browse files Browse the repository at this point in the history
This is basically the add of BUSYBOX image and then using
that instead of centos image.

Signed-off-by: Scott Moser <[email protected]>
  • Loading branch information
smoser committed Nov 13, 2023
1 parent c75830e commit fa5aa70
Show file tree
Hide file tree
Showing 37 changed files with 221 additions and 211 deletions.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 \
Expand Down
4 changes: 2 additions & 2 deletions test/annotations-namespace.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,7 +28,7 @@ EOF
thing:
from:
type: oci
url: $CENTOS_OCI
url: $BUSYBOX_OCI
run: ls
EOF
stacker build
Expand Down
2 changes: 1 addition & 1 deletion test/annotations.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function teardown() {
thing:
from:
type: oci
url: $CENTOS_OCI
url: $BUSYBOX_OCI
run: ls
annotations:
a.b.c.key: val
Expand Down
2 changes: 1 addition & 1 deletion test/args.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function teardown() {
parent:
from:
type: oci
url: $CENTOS_OCI
url: $BUSYBOX_OCI
child:
from:
type: built
Expand Down
2 changes: 1 addition & 1 deletion test/asterisk.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function teardown() {
a:
from:
type: oci
url: $CENTOS_OCI
url: $BUSYBOX_OCI
run: |
mkdir /mybin
cp /bin/* /mybin
Expand Down
6 changes: 3 additions & 3 deletions test/atomfs.bats
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function basic_test() {
test:
from:
type: oci
url: $CENTOS_OCI
url: $BUSYBOX_OCI
run: |
touch /hello
EOF
Expand Down Expand Up @@ -48,7 +48,7 @@ EOF
base:
from:
type: oci
url: $CENTOS_OCI
url: $BUSYBOX_OCI
run: touch /base
a:
from:
Expand Down Expand Up @@ -121,7 +121,7 @@ EOF
test:
from:
type: oci
url: $CENTOS_OCI
url: $BUSYBOX_OCI
run: |
touch /hello
EOF
Expand Down
64 changes: 32 additions & 32 deletions test/basic.bats
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ function teardown() {

@test "multiple stacker builds in a row" {
cat > stacker.yaml <<EOF
centos:
busybox:
from:
type: oci
url: $CENTOS_OCI
url: $BUSYBOX_OCI
import: import
EOF
echo 1 > import
Expand All @@ -28,10 +28,10 @@ EOF

@test "basic workings" {
cat > stacker.yaml <<EOF
centos:
busybox:
from:
type: tar
url: .stacker/layer-bases/centos.tar
url: .stacker/layer-bases/busybox.tar
import:
- ./stacker.yaml
- https://www.cisco.com/favicon.ico
Expand All @@ -53,7 +53,7 @@ centos:
layer1:
from:
type: built
tag: centos
tag: busybox
run:
- rm /favicon.ico
EOF
Expand All @@ -62,29 +62,29 @@ EOF
chmod +x executable
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

stacker build --substitute "FAVICON=favicon.ico"
[ "$status" -eq 0 ]

# did we really download the image to the right place?
[ -f .stacker/layer-bases/centos.tar ]
[ -f .stacker/layer-bases/busybox.tar ]

# did run actually copy the favicon to the right place?
stacker grab centos:/favicon.ico
[ "$(sha .stacker/imports/centos/favicon.ico)" == "$(sha favicon.ico)" ]
stacker grab busybox:/favicon.ico
[ "$(sha .stacker/imports/busybox/favicon.ico)" == "$(sha favicon.ico)" ]

[ ! -f roots/layer1/rootfs/favicon.ico ] || [ ! -f roots/layer1/overlay/favicon.ico ]

rm executable
stacker grab centos:/usr/bin/executable
stacker grab busybox:/usr/bin/executable
[ "$(stat --format="%a" executable)" = "755" ]

# did we do a copy correctly?
[ "$(sha .stacker/imports/centos/stacker.yaml)" == "$(sha ./stacker.yaml)" ]
[ "$(sha .stacker/imports/busybox/stacker.yaml)" == "$(sha ./stacker.yaml)" ]

# check OCI image generation
manifest=$(cat oci/index.json | jq -r .manifests[0].digest | cut -f2 -d:)
Expand Down Expand Up @@ -140,15 +140,15 @@ EOF

@test "stacker.yaml without imports can run" {
cat > stacker.yaml <<EOF
centos:
busybox:
from:
type: oci
url: $CENTOS_OCI
url: $BUSYBOX_OCI
run: |
touch /foo
EOF
stacker build
umoci unpack --image oci:centos dest
umoci unpack --image oci:busybox dest
[ -f dest/rootfs/foo ]
}

Expand All @@ -162,25 +162,25 @@ EOF
@test "use colons in roots-dir path name should fail" {
local tmpd=$(pwd)
cat > stacker.yaml <<EOF
centos:
busybox:
from:
type: oci
url: $CENTOS_OCI
url: $BUSYBOX_OCI
run: |
touch /foo
EOF
bad_stacker --roots-dir $tmpd/with:colon build
[ "$status" -eq 1 ]
echo $output | grep "forbidden"
}
}

@test "use colons in layer name should fail" {
local tmpd=$(pwd)
cat > stacker.yaml <<EOF
centos:with:colon:
busybox:with:colon:
from:
type: oci
url: $CENTOS_OCI
url: $BUSYBOX_OCI
run: |
touch /foo
EOF
Expand All @@ -194,10 +194,10 @@ EOF
FAVICON: favicon.ico
EOF
cat > stacker.yaml <<EOF
centos:
busybox:
from:
type: tar
url: .stacker/layer-bases/centos.tar
url: .stacker/layer-bases/busybox.tar
import:
- ./stacker.yaml
- https://www.cisco.com/favicon.ico
Expand All @@ -219,7 +219,7 @@ centos:
layer1:
from:
type: built
tag: centos
tag: busybox
run:
- rm /favicon.ico
EOF
Expand All @@ -228,29 +228,29 @@ EOF
chmod +x executable
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

stacker build --substitute-file subs.yaml
[ "$status" -eq 0 ]

# did we really download the image to the right place?
[ -f .stacker/layer-bases/centos.tar ]
[ -f .stacker/layer-bases/busybox.tar ]

# did run actually copy the favicon to the right place?
stacker grab centos:/favicon.ico
[ "$(sha .stacker/imports/centos/favicon.ico)" == "$(sha favicon.ico)" ]
stacker grab busybox:/favicon.ico
[ "$(sha .stacker/imports/busybox/favicon.ico)" == "$(sha favicon.ico)" ]

[ ! -f roots/layer1/rootfs/favicon.ico ] || [ ! -f roots/layer1/overlay/favicon.ico ]

rm executable
stacker grab centos:/usr/bin/executable
stacker grab busybox:/usr/bin/executable
[ "$(stat --format="%a" executable)" = "755" ]

# did we do a copy correctly?
[ "$(sha .stacker/imports/centos/stacker.yaml)" == "$(sha ./stacker.yaml)" ]
[ "$(sha .stacker/imports/busybox/stacker.yaml)" == "$(sha ./stacker.yaml)" ]

# check OCI image generation
manifest=$(cat oci/index.json | jq -r .manifests[0].digest | cut -f2 -d:)
Expand Down
8 changes: 4 additions & 4 deletions test/binds.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function teardown() {
bind-test:
from:
type: oci
url: ${{CENTOS_OCI}}
url: ${{BUSYBOX_OCI}}
binds:
- ${{bind_path}} -> /root/tree1/foo
run: |
Expand All @@ -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)$ ]]

Expand All @@ -41,7 +41,7 @@ EOF
bind-test:
from:
type: oci
url: ${{CENTOS_OCI}}
url: ${{BUSYBOX_OCI}}
binds:
- source: ${{bind_path1}}
dest: /root/tree1/foo
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions test/bom.bats
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function teardown() {
bom-parent:
from:
type: oci
url: $CENTOS_OCI
url: $BUSYBOX_OCI
bom:
generate: true
packages:
Expand Down Expand Up @@ -72,7 +72,7 @@ EOF
bom-parent:
from:
type: oci
url: $CENTOS_OCI
url: $BUSYBOX_OCI
bom:
generate: true
packages:
Expand Down
2 changes: 1 addition & 1 deletion test/broken-link.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit fa5aa70

Please sign in to comment.