diff --git a/docker/tester/root/usr/bin/entrypoint b/docker/tester/root/usr/bin/entrypoint index ad3cfb24..1e1bef6b 100755 --- a/docker/tester/root/usr/bin/entrypoint +++ b/docker/tester/root/usr/bin/entrypoint @@ -7,7 +7,7 @@ BUILD_DIR=/build CMD=${1:-test} shift -# Build type can be "debug" or "release", fallbacks to "release" by default +# build type can be "debug" or "release", fallbacks to "release" by default BUILD_TYPE=$(echo "$BUILD_TYPE" | tr "[:upper:]" "[:lower:]") case "$BUILD_TYPE" in "debug") @@ -31,26 +31,25 @@ case "$CMD" in echo "Falco version cannot be guessed, please provide it with the FALCO_VERSION environment variable." >&2 exit 1 fi - PACKAGE="$BUILD_DIR/$BUILD_TYPE/falco-$FALCO_VERSION-x86_64.deb" - if [ ! -f "$PACKAGE" ]; then - echo "Package(s) not found." >&2 - exit 1 - fi - DOCKER_IMAGE_NAME="falcosecurity/falco:test" - echo "Building local docker image $DOCKER_IMAGE_NAME from latest debian package..." - cp "$PACKAGE" $BUILD_DIR/$BUILD_TYPE/docker/local - cd $BUILD_DIR/$BUILD_TYPE/docker/local - docker build --build-arg FALCO_VERSION="$FALCO_VERSION" -t "$DOCKER_IMAGE_NAME" . + + # build docker images + build_image "$BUILD_DIR" "$BUILD_TYPE" "$FALCO_VERSION" "deb" + build_image "$BUILD_DIR" "$BUILD_TYPE" "$FALCO_VERSION" "rpm" - # Check that source directory contains Falco and sysdig + # check that source directory contains Falco and sysdig if [ ! -d "$SOURCE_DIR/falco/test" ]; then echo "Missing $SOURCE_DIR/falco/test directory." >&2 exit 1 fi + + # run tests echo "Running regression tests ..." - cd $SOURCE_DIR/falco/test - ./run_regression_tests.sh $BUILD_DIR/$BUILD_TYPE - docker rmi "$DOCKER_IMAGE_NAME" || true + cd `$SOURCE_DIR/falco/test` + ./run_regression_tests.sh "$BUILD_DIR/$BUILD_TYPE" + + # clean docker images + clean_image "deb" + clean_image "rpm" ;; "bash") CMD=/bin/bash @@ -59,3 +58,27 @@ case "$CMD" in exec "$CMD" "$@" ;; esac + +build_image() { + BUILD_DIR=$1 + BUILD_TYPE=$2 + FALCO_VERSION=$3 + PACKAGE_TYPE=$4 + PACKAGE="$BUILD_DIR/$BUILD_TYPE/falco-$FALCO_VERSION-x86_64.${PACKAGE_TYPE}" + if [ ! -f "$PACKAGE" ]; then + echo "Package not found: ${PACKAGE}." >&2 + exit 1 + fi + DOCKER_IMAGE_NAME="falcosecurity/falco:test-${PACKAGE_TYPE}" + echo "Building local docker image $DOCKER_IMAGE_NAME from latest ${PACKAGE_TYPE} package..." + + mkdir -p /packages + cp "$PACKAGE" /packages + docker build -f "/runners/$PACKAGE_TYPE.Dockerfile" --build-arg FALCO_VERSION="$FALCO_VERSION" -t "$DOCKER_IMAGE_NAME" /packages +} + +clean_image() { + PACKAGE_TYPE=$1 + DOCKER_IMAGE_NAME="falcosecurity/falco:test-${PACKAGE_TYPE}" + docker rmi -f "$DOCKER_IMAGE_NAME" +}