From d6c80f6d2c8f8ebc07b1ba2c18a5dfbbf5e4e0a5 Mon Sep 17 00:00:00 2001 From: Christian Kreibich Date: Wed, 22 Sep 2021 16:37:52 -0700 Subject: [PATCH] Test container with BTest instead of container-structure-tests This patch replaces the container-strucuture-tests for the Zeek container with a BTest-driven approach to provide a more familiar experience. In addtion to `python3` for `btest` we also rely on `make` being available in Github-hosted runners which at least currently seems to be hold (probably pulled in as a dependency of CMake which is officially included, see https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md). --- .github/workflows/docker.yml | 16 +++++--- docker/Makefile | 4 ++ docker/btest/.gitignore | 3 ++ .../Baseline/docker.structure_tests/output | 20 ++++++++++ docker/btest/Makefile | 11 ++++++ docker/btest/btest.cfg | 13 +++++++ docker/btest/docker/structure_tests.sh | 20 ++++++++++ docker/container-structure-test.yaml | 37 ------------------- 8 files changed, 81 insertions(+), 43 deletions(-) create mode 100644 docker/btest/.gitignore create mode 100644 docker/btest/Baseline/docker.structure_tests/output create mode 100644 docker/btest/Makefile create mode 100644 docker/btest/btest.cfg create mode 100644 docker/btest/docker/structure_tests.sh delete mode 100644 docker/container-structure-test.yaml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 79afc88acd..161e92cec2 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -36,12 +36,8 @@ jobs: load: true tags: ${{ env.TEST_TAG }} - # Run tests on the just created image. - - name: Run tests - uses: plexsystems/container-structure-test-action@v0.2.0 - with: - image: ${{ env.TEST_TAG }} - config: docker/container-structure-test.yaml + - name: Run btests + run: make -C docker/btest - name: Get Version id: version @@ -84,3 +80,11 @@ jobs: push: true tags: | zeekurity/${{ steps.target.outputs.tag}} + + - name: Preserve artifacts + uses: actions/upload-artifact@v2 + if: failure() + with: + name: docker-btest + path: docker/btest/.tmp + if-no-files-found: ignore diff --git a/docker/Makefile b/docker/Makefile index 0a242c04bd..696afc690d 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -6,3 +6,7 @@ VERSION := $$(cat ../VERSION) all: @docker build -t zeek:$(VERSION) -f Dockerfile .. + @docker tag zeek:$(VERSION) zeek:latest + +test: + @TEST_TAG=zeek:$(VERSION) $(MAKE) -C btest diff --git a/docker/btest/.gitignore b/docker/btest/.gitignore new file mode 100644 index 0000000000..5b0019848f --- /dev/null +++ b/docker/btest/.gitignore @@ -0,0 +1,3 @@ +.tmp +.btest.failed.dat +diag.log diff --git a/docker/btest/Baseline/docker.structure_tests/output b/docker/btest/Baseline/docker.structure_tests/output new file mode 100644 index 0000000000..0c8a07377a --- /dev/null +++ b/docker/btest/Baseline/docker.structure_tests/output @@ -0,0 +1,20 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +zeek version xxx +XXX +[sources] +zeek = https://github.com/zeek/packages + +[paths] +state_dir = /usr/local/zeek/var/lib/zkg +script_dir = /usr/local/zeek/share/zeek/site +plugin_dir = /usr/local/zeek/lib/zeek/plugins +bin_dir = /usr/local/zeek/bin +zeek_dist = + +[templates] +default = https://github.com/zeek/package-template + + +Installing "zeek/sethhall/domain-tld" +Installed "zeek/sethhall/domain-tld" (XXX) +Loaded "zeek/sethhall/domain-tld" diff --git a/docker/btest/Makefile b/docker/btest/Makefile new file mode 100644 index 0000000000..65d4d65c98 --- /dev/null +++ b/docker/btest/Makefile @@ -0,0 +1,11 @@ +DIAG=diag.log +BTEST=../../auxil/btest/btest + +all: cleanup btest-verbose + +# Showing all tests. +btest-verbose: + @$(BTEST) -d -j -f $(DIAG) + +cleanup: + @rm -f $(DIAG) diff --git a/docker/btest/btest.cfg b/docker/btest/btest.cfg new file mode 100644 index 0000000000..69b30b9184 --- /dev/null +++ b/docker/btest/btest.cfg @@ -0,0 +1,13 @@ +[btest] +TestDirs = docker +TmpDir = %(testbase)s/.tmp +BaselineDir = %(testbase)s/Baseline +IgnoreDirs = .tmp +IgnoreFiles = *.tmp *.swp #* *.trace .DS_Store +MinVersion = 0.63 + +[environment] +LC_ALL=C +PATH=%(testbase)s/../../auxil/btest:%(default_path)s +TEST_IMAGE=${TEST_TAG:-zeek:latest} +TZ=UTC diff --git a/docker/btest/docker/structure_tests.sh b/docker/btest/docker/structure_tests.sh new file mode 100644 index 0000000000..cb6cd2e6f0 --- /dev/null +++ b/docker/btest/docker/structure_tests.sh @@ -0,0 +1,20 @@ +# @TEST-REQUIRES: docker inspect ${TEST_TAG:-zeek:latest} +# @TEST-EXEC: bash -euxo pipefail %INPUT >output +# @TEST-EXEC: btest-diff output + +TEST_TAG=${TEST_TAG:-zeek:latest} + +# Check that `zeek` can be run. +docker run --rm "${TEST_TAG}" zeek -v | sed 's/\(zeek version\) .*/\1 xxx/' + +# Check that this is a release build. +docker run --rm "${TEST_TAG}" zeek-config --build_type | grep -q 'release' + +# Check that `btest` can be run. +docker run --rm "${TEST_TAG}" btest --version | sed 's/^[0-9].*/XXX/g' + +# Check that the zkg config looks valid. +docker run --rm "${TEST_TAG}" zkg config + +# Check that a plugin can be installed. We pick any plugin with minimal deps here. +docker run --rm "${TEST_TAG}" zkg install --force sethhall/domain-tld | sed 's/(.*)/(XXX)/' diff --git a/docker/container-structure-test.yaml b/docker/container-structure-test.yaml deleted file mode 100644 index 455f52358b..0000000000 --- a/docker/container-structure-test.yaml +++ /dev/null @@ -1,37 +0,0 @@ -# See the file "COPYING" in the main distribution directory for copyright. - -# This file contains a test configuration for -# https://github.com/GoogleContainerTools/container-structure-test. - -schemaVersion: 2.0.0 - -commandTests: - - name: zeek can be run - command: zeek - args: ["-v"] - expectedOutput: ["^zeek version .*"] - - - name: is release build - command: zeek-config - args: ["--build_type"] - expectedOutput: ["release"] - - - name: btest can be run - command: btest - args: ["--version"] - expectedOutput: ["\\d\\.\\d"] - - - name: valid zkg config - command: zkg - args: ["config"] - # Just validate that we some some valid entry here. - expectedOutput: ["state_dir = /usr/local/zeek/var/lib/zkg"] - - - name: plugin can be installed - command: zkg - # We pick any plugin with minimal deps here. - args: ["install", "--force", "sethhall/domain-tld"] - expectedOutput: - - "Installing \"zeek/sethhall/domain-tld\"" - - "Installed \"zeek/sethhall/domain-tld\" (.*)" - - "Loaded \"zeek/sethhall/domain-tld\""