From 1d2b8ad6a737a5e300b70c4a502f8ae2d30562fa Mon Sep 17 00:00:00 2001 From: Michal Tekel Date: Thu, 20 Mar 2025 14:33:58 +0000 Subject: [PATCH 01/15] test: remove custom handling of bpm release BPM release and version is now specified in haproxy manifest. There is no need to handle it in a custom way. --- .gitignore | 1 - acceptance-tests/README.md | 2 -- acceptance-tests/run-local.sh | 5 ----- ci/pipeline.yml | 9 --------- ci/scripts/acceptance-tests | 4 ---- ci/scripts/bpm/.gitkeep | 0 ci/scripts/shell | 4 ---- 7 files changed, 25 deletions(-) delete mode 100644 ci/scripts/bpm/.gitkeep diff --git a/.gitignore b/.gitignore index fe9a628c..5b6f7d4b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ releases/*.tgz releases/**/*.tgz ci/scripts/stemcell/*.tgz ci/scripts/stemcell-bionic/*.tgz -ci/scripts/bpm/*.tgz dev_releases blobs/* .blobs diff --git a/acceptance-tests/README.md b/acceptance-tests/README.md index 1a6797f0..151a1ce1 100644 --- a/acceptance-tests/README.md +++ b/acceptance-tests/README.md @@ -7,8 +7,6 @@ * Get it from https://bosh.io/stemcells/bosh-warden-boshlite-ubuntu-jammy-go_agent * A matching Bionic stemcell tgz downloaded to `ci/scripts/stemcell-bionic` * Get it from https://bosh.io/stemcells/bosh-warden-boshlite-ubuntu-bionic-go_agent -* A BPM release tgz downloaded to `ci/scripts/bpm` - * Get it from https://bosh.io/releases/github.com/cloudfoundry/bpm-release?all=1 ## Running diff --git a/acceptance-tests/run-local.sh b/acceptance-tests/run-local.sh index 282146f6..000ed677 100755 --- a/acceptance-tests/run-local.sh +++ b/acceptance-tests/run-local.sh @@ -35,11 +35,6 @@ check_required_files() { ../ci/scripts/stemcell-bionic/bosh-stemcell-*-ubuntu-bionic-*.tgz!https://bosh.io/d/stemcells/bosh-warden-boshlite-ubuntu-bionic-go_agent ) - # BPM downloads as uuid and needs manually specifying file name - if [ ! -f "../ci/scripts/bpm/bpm-release-latest.tgz" ] ; then - curl -sL https://bosh.io/d/github.com/cloudfoundry/bpm-release -o ../ci/scripts/bpm/bpm-release-latest.tgz - fi - for entry in "${REQUIRED_FILE_PATTERNS[@]}"; do pattern=$(cut -f1 -d! <<<"$entry") url=$(cut -f2 -d! <<<"$entry") diff --git a/ci/pipeline.yml b/ci/pipeline.yml index 98b62f8b..c95d56f0 100644 --- a/ci/pipeline.yml +++ b/ci/pipeline.yml @@ -122,7 +122,6 @@ jobs: - { get: git, trigger: true, passed: [unit-tests] } - { get: stemcell } - { get: stemcell-bionic } - - { get: bpm } - get: haproxy-boshrelease-testflight - task: acceptance-tests privileged: true @@ -133,7 +132,6 @@ jobs: - { name: git } - { name: stemcell } - { name: stemcell-bionic } - - { name: bpm } run: path: ./git/ci/scripts/acceptance-tests args: [] @@ -155,7 +153,6 @@ jobs: - { get: git-pull-requests, trigger: true, version: every } - { get: stemcell } - { get: stemcell-bionic } - - { get: bpm } - get: haproxy-boshrelease-testflight - put: git-pull-requests params: @@ -173,7 +170,6 @@ jobs: - { name: git-pull-requests } - { name: stemcell } - { name: stemcell-bionic } - - { name: bpm } run: path: ./git-pull-requests/ci/scripts/acceptance-tests args: [] @@ -418,11 +414,6 @@ resources: source: name: bosh-warden-boshlite-ubuntu-jammy-go_agent - - name: bpm - type: bosh-io-release - source: - repository: cloudfoundry/bpm-release - - name: version type: semver source : diff --git a/ci/scripts/acceptance-tests b/ci/scripts/acceptance-tests index 6a017c5e..c22ccf15 100755 --- a/ci/scripts/acceptance-tests +++ b/ci/scripts/acceptance-tests @@ -4,7 +4,6 @@ set -e stemcell_jammy_path=$PWD/stemcell/*.tgz stemcell_bionic_path=$PWD/stemcell-bionic/*.tgz -bpm_release_path=$PWD/bpm/*.tgz if [ -n "$FOCUS" ]; then echo "------------------------------------------------------------------" @@ -61,9 +60,6 @@ bosh -n upload-stemcell $stemcell_jammy_path echo "----- Uploading Bionic stemcell" bosh -n upload-stemcell $stemcell_bionic_path -echo "----- Uploading BPM" -bosh -n upload-release $bpm_release_path - echo "----- Uploading os-conf (used for tests only)" bosh -n upload-release --sha1 386293038ae3d00813eaa475b4acf63f8da226ef \ https://bosh.io/d/github.com/cloudfoundry/os-conf-release?v=22.1.2 diff --git a/ci/scripts/bpm/.gitkeep b/ci/scripts/bpm/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/ci/scripts/shell b/ci/scripts/shell index c4efecd1..f91bdac2 100755 --- a/ci/scripts/shell +++ b/ci/scripts/shell @@ -3,7 +3,6 @@ set -eu stemcell_path=$PWD/stemcell/*.tgz -bpm_release_path=$PWD/bpm/*.tgz cd ${REPO_ROOT:?required} echo "----- Pulling in any git submodules..." @@ -36,9 +35,6 @@ echo "----- Created ${RELEASE_VERSION}" echo "----- Uploading stemcell" bosh -n upload-stemcell $stemcell_path -echo "----- Uploading BPM" -bosh -n upload-release $bpm_release_path - echo "----- Uploading os-conf (used for tests only)" bosh -n upload-release --sha1 386293038ae3d00813eaa475b4acf63f8da226ef \ https://bosh.io/d/github.com/cloudfoundry/os-conf-release?v=22.1.2 From 07a407c0fe2d66e7b74f7af735939ec18baea96c Mon Sep 17 00:00:00 2001 From: Michal Tekel Date: Mon, 24 Mar 2025 17:24:41 +0000 Subject: [PATCH 02/15] test: only build testflight if not present This is to avoid rebuilding image on every local run. --- acceptance-tests/run-local.sh | 12 ++++++++---- acceptance-tests/run-shell.sh | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/acceptance-tests/run-local.sh b/acceptance-tests/run-local.sh index 000ed677..68dc13ec 100755 --- a/acceptance-tests/run-local.sh +++ b/acceptance-tests/run-local.sh @@ -71,10 +71,14 @@ if [ "$(uname)" == "Darwin" ]; then docker_mac_check_cgroupsv1 fi -# Build acceptance test image -pushd "$SCRIPT_DIR/../ci" || exit 1 - docker build -t haproxy-boshrelease-testflight . -popd || exit 1 +# Build acceptance test image if not found. +if docker images -a | grep "haproxy-boshrelease-testflight " ; then + echo "Found existing testflight image, skipping docker build. To force rebuild delete this image." +else + pushd "$SCRIPT_DIR/../ci" + docker build -t haproxy-boshrelease-testflight . + popd +fi # Run acceptance tests if [ -n "$FOCUS" ]; then diff --git a/acceptance-tests/run-shell.sh b/acceptance-tests/run-shell.sh index c98a21c6..f33bb69a 100755 --- a/acceptance-tests/run-shell.sh +++ b/acceptance-tests/run-shell.sh @@ -5,10 +5,14 @@ set -e SCRIPT_DIR="$(cd "$(dirname "$0")/" && pwd)" REPO_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" -# Build acceptance test image -pushd "$SCRIPT_DIR/../ci" || exit 1 - docker build -t haproxy-boshrelease-testflight . -popd || exit 1 +# Build acceptance test image if not found. +if docker images -a | grep "haproxy-boshrelease-testflight " ; then + echo "Found existing testflight image, skipping docker build. To force rebuild delete this image." +else + pushd "$SCRIPT_DIR/../ci" + docker build -t haproxy-boshrelease-testflight . + popd +fi # Run local shell docker run -it --rm --privileged -v "$REPO_DIR":/repo -e REPO_ROOT=/repo haproxy-boshrelease-testflight bash -c "cd /repo/ci/scripts && ./shell" From 00863e19f7b0930101b79b3751326e734052a877 Mon Sep 17 00:00:00 2001 From: Michal Tekel Date: Tue, 25 Mar 2025 14:29:29 +0000 Subject: [PATCH 03/15] test: use common functions Put common functions into a file that can be sourced by scripts that need them. --- acceptance-tests/run-local.sh | 10 ++-------- acceptance-tests/run-shell.sh | 10 ++-------- ci/scripts/acceptance-tests | 7 +------ ci/scripts/{skip-ci.sh => functions-ci.sh} | 18 ++++++++++++++++++ ci/scripts/shell | 7 +------ ci/scripts/start-bosh.sh | 5 +---- 6 files changed, 25 insertions(+), 32 deletions(-) rename ci/scripts/{skip-ci.sh => functions-ci.sh} (63%) diff --git a/acceptance-tests/run-local.sh b/acceptance-tests/run-local.sh index 68dc13ec..cc0587f6 100755 --- a/acceptance-tests/run-local.sh +++ b/acceptance-tests/run-local.sh @@ -5,6 +5,7 @@ set -eu SCRIPT_DIR="$(cd "$(dirname "$0")/" && pwd)" REPO_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" +source "${SCRIPT_DIR}/../ci/scripts/functions-ci.sh" if ! [[ $(git status --porcelain=v1 2>/dev/null | wc -l) -eq 0 ]]; then echo "You have changes in your Git repository. Commit or clean (e.g. git clean -f) before running." @@ -71,14 +72,7 @@ if [ "$(uname)" == "Darwin" ]; then docker_mac_check_cgroupsv1 fi -# Build acceptance test image if not found. -if docker images -a | grep "haproxy-boshrelease-testflight " ; then - echo "Found existing testflight image, skipping docker build. To force rebuild delete this image." -else - pushd "$SCRIPT_DIR/../ci" - docker build -t haproxy-boshrelease-testflight . - popd -fi +build_image "${SCRIPT_DIR}/../ci" # Run acceptance tests if [ -n "$FOCUS" ]; then diff --git a/acceptance-tests/run-shell.sh b/acceptance-tests/run-shell.sh index f33bb69a..94c7522d 100755 --- a/acceptance-tests/run-shell.sh +++ b/acceptance-tests/run-shell.sh @@ -4,15 +4,9 @@ set -e SCRIPT_DIR="$(cd "$(dirname "$0")/" && pwd)" REPO_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" +source "${SCRIPT_DIR}/../ci/scripts/functions-ci.sh" -# Build acceptance test image if not found. -if docker images -a | grep "haproxy-boshrelease-testflight " ; then - echo "Found existing testflight image, skipping docker build. To force rebuild delete this image." -else - pushd "$SCRIPT_DIR/../ci" - docker build -t haproxy-boshrelease-testflight . - popd -fi +build_image "${SCRIPT_DIR}/../ci" # Run local shell docker run -it --rm --privileged -v "$REPO_DIR":/repo -e REPO_ROOT=/repo haproxy-boshrelease-testflight bash -c "cd /repo/ci/scripts && ./shell" diff --git a/ci/scripts/acceptance-tests b/ci/scripts/acceptance-tests index c22ccf15..45dd0bef 100755 --- a/ci/scripts/acceptance-tests +++ b/ci/scripts/acceptance-tests @@ -20,7 +20,7 @@ git config --global --add safe.directory /repo/src/ttar git submodule update --init --recursive --force # shellcheck disable=SC1091 -source "ci/scripts/skip-ci.sh" +source "ci/scripts/functions-ci.sh" if [ -f ".git/resource/changed_files" ]; then if skip_ci "ci/.ci-ignore" ".git/resource/changed_files"; then echo "SKIP TEST: Only .ci-ignored changes found." @@ -33,11 +33,6 @@ echo "----- Starting BOSH" ./ci/scripts/start-bosh.sh -function stop_docker() { - echo "----- stopping docker" - service docker stop -} - if [ -z "$FOCUS" ]; then trap stop_docker EXIT fi diff --git a/ci/scripts/skip-ci.sh b/ci/scripts/functions-ci.sh similarity index 63% rename from ci/scripts/skip-ci.sh rename to ci/scripts/functions-ci.sh index 0ba00057..4e660bea 100755 --- a/ci/scripts/skip-ci.sh +++ b/ci/scripts/functions-ci.sh @@ -25,3 +25,21 @@ function skip_ci() { # If we get here, all files are skipped or in skipped dirs. return 0 } + +function stop_docker() { + echo "----- stopping docker" + service docker stop +} + +# Build acceptance test image if not found. +function build_image() { + if docker images -a | grep "haproxy-boshrelease-testflight " ; then + echo "Found existing testflight image, skipping docker build. To force rebuild delete this image." + else + pushd "$1" + docker build -t haproxy-boshrelease-testflight . + popd + fi +} + +echo "Loaded shell script functions..." diff --git a/ci/scripts/shell b/ci/scripts/shell index f91bdac2..4da700f4 100755 --- a/ci/scripts/shell +++ b/ci/scripts/shell @@ -11,14 +11,9 @@ git config --global --add safe.directory /repo/src/ttar git submodule update --init --recursive --force echo "----- Starting BOSH" - ./ci/scripts/start-bosh.sh -function stop_docker() { - echo "----- stopping docker" - service docker stop -} - +source "ci/scripts/functions-ci.sh" trap stop_docker EXIT source /tmp/local-bosh/director/env diff --git a/ci/scripts/start-bosh.sh b/ci/scripts/start-bosh.sh index 7dd9de68..ece904e0 100755 --- a/ci/scripts/start-bosh.sh +++ b/ci/scripts/start-bosh.sh @@ -99,10 +99,7 @@ function sanitize_cgroups() { done } -function stop_docker() { - echo "ERROR: stopping docker" - service docker stop -} +source "ci/scripts/functions-ci.sh" function start_docker() { generate_certs "$1" From bf726163bee1a827d257c9c1846b9ec7438b4452 Mon Sep 17 00:00:00 2001 From: Michal Tekel Date: Tue, 25 Mar 2025 14:48:27 +0000 Subject: [PATCH 04/15] test: dry bosh start message --- ci/scripts/acceptance-tests | 1 - ci/scripts/shell | 1 - ci/scripts/start-bosh.sh | 1 + 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/ci/scripts/acceptance-tests b/ci/scripts/acceptance-tests index 45dd0bef..bd6db8bc 100755 --- a/ci/scripts/acceptance-tests +++ b/ci/scripts/acceptance-tests @@ -29,7 +29,6 @@ if [ -f ".git/resource/changed_files" ]; then echo "RUN TEST: There is at least one non-ignored change found." fi fi -echo "----- Starting BOSH" ./ci/scripts/start-bosh.sh diff --git a/ci/scripts/shell b/ci/scripts/shell index 4da700f4..172af7c3 100755 --- a/ci/scripts/shell +++ b/ci/scripts/shell @@ -10,7 +10,6 @@ git config --global --add safe.directory /repo git config --global --add safe.directory /repo/src/ttar git submodule update --init --recursive --force -echo "----- Starting BOSH" ./ci/scripts/start-bosh.sh source "ci/scripts/functions-ci.sh" diff --git a/ci/scripts/start-bosh.sh b/ci/scripts/start-bosh.sh index ece904e0..53c5fa75 100755 --- a/ci/scripts/start-bosh.sh +++ b/ci/scripts/start-bosh.sh @@ -223,4 +223,5 @@ EOF popd > /dev/null } +echo "----- Starting BOSH" main $@ From c24f133240e23b122bd81c65f5e58af81d5cfe66 Mon Sep 17 00:00:00 2001 From: Michal Tekel Date: Tue, 25 Mar 2025 14:49:50 +0000 Subject: [PATCH 05/15] test: DRY git pull --- ci/scripts/acceptance-tests | 9 ++------- ci/scripts/functions-ci.sh | 8 ++++++++ ci/scripts/shell | 8 ++------ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/ci/scripts/acceptance-tests b/ci/scripts/acceptance-tests index bd6db8bc..f9863780 100755 --- a/ci/scripts/acceptance-tests +++ b/ci/scripts/acceptance-tests @@ -4,6 +4,7 @@ set -e stemcell_jammy_path=$PWD/stemcell/*.tgz stemcell_bionic_path=$PWD/stemcell-bionic/*.tgz +source "${REPO_ROOT}/ci/scripts/functions-ci.sh" if [ -n "$FOCUS" ]; then echo "------------------------------------------------------------------" @@ -13,14 +14,8 @@ if [ -n "$FOCUS" ]; then ADDITIONAL_ARGS=("--focus" "$FOCUS") fi -cd "${REPO_ROOT:?required}" -echo "----- Pulling in any git submodules..." -git config --global --add safe.directory /repo -git config --global --add safe.directory /repo/src/ttar -git submodule update --init --recursive --force +git_pull -# shellcheck disable=SC1091 -source "ci/scripts/functions-ci.sh" if [ -f ".git/resource/changed_files" ]; then if skip_ci "ci/.ci-ignore" ".git/resource/changed_files"; then echo "SKIP TEST: Only .ci-ignored changes found." diff --git a/ci/scripts/functions-ci.sh b/ci/scripts/functions-ci.sh index 4e660bea..4834a1ae 100755 --- a/ci/scripts/functions-ci.sh +++ b/ci/scripts/functions-ci.sh @@ -42,4 +42,12 @@ function build_image() { fi } +function git_pull() { + cd "${REPO_ROOT:?required}" + echo "----- Pulling in any git submodules..." + git config --global --add safe.directory /repo + git config --global --add safe.directory /repo/src/ttar + git submodule update --init --recursive --force +} + echo "Loaded shell script functions..." diff --git a/ci/scripts/shell b/ci/scripts/shell index 172af7c3..68d0cb96 100755 --- a/ci/scripts/shell +++ b/ci/scripts/shell @@ -3,16 +3,12 @@ set -eu stemcell_path=$PWD/stemcell/*.tgz +source "${REPO_ROOT}/ci/scripts/functions-ci.sh" -cd ${REPO_ROOT:?required} -echo "----- Pulling in any git submodules..." -git config --global --add safe.directory /repo -git config --global --add safe.directory /repo/src/ttar -git submodule update --init --recursive --force +git_pull ./ci/scripts/start-bosh.sh -source "ci/scripts/functions-ci.sh" trap stop_docker EXIT source /tmp/local-bosh/director/env From 8b88f32dcdb74f3b9690bfe052cd436e917bb3f8 Mon Sep 17 00:00:00 2001 From: Michal Tekel Date: Tue, 25 Mar 2025 15:05:47 +0000 Subject: [PATCH 06/15] test: dry bosh operations --- ci/scripts/acceptance-tests | 29 +++-------------------------- ci/scripts/functions-ci.sh | 29 ++++++++++++++++++++++++++++- ci/scripts/shell | 23 ++++------------------- 3 files changed, 35 insertions(+), 46 deletions(-) diff --git a/ci/scripts/acceptance-tests b/ci/scripts/acceptance-tests index f9863780..0fa22610 100755 --- a/ci/scripts/acceptance-tests +++ b/ci/scripts/acceptance-tests @@ -1,10 +1,8 @@ #!/bin/bash set -e - -stemcell_jammy_path=$PWD/stemcell/*.tgz -stemcell_bionic_path=$PWD/stemcell-bionic/*.tgz source "${REPO_ROOT}/ci/scripts/functions-ci.sh" +START_DIR="${PWD}" # Differs for CI and manual execution if [ -n "$FOCUS" ]; then echo "------------------------------------------------------------------" @@ -33,29 +31,8 @@ fi # shellcheck disable=SC1091 source /tmp/local-bosh/director/env - -echo "----- Creating candidate BOSH release..." -bosh -n reset-release # in case dev_releases/ is in repo accidentally - -bosh create-release -bosh upload-release --rebase -release_final_version=$(spruce json dev_releases/*/index.yml | jq -r ".builds[].version" | sed -e "s%+.*%%") -export RELEASE_VERSION="${release_final_version}.latest" -echo "----- Created ${RELEASE_VERSION}" - -echo "----- Uploading Jammy stemcell" -bosh -n upload-stemcell $stemcell_jammy_path - -echo "----- Uploading Bionic stemcell" -bosh -n upload-stemcell $stemcell_bionic_path - -echo "----- Uploading os-conf (used for tests only)" -bosh -n upload-release --sha1 386293038ae3d00813eaa475b4acf63f8da226ef \ - https://bosh.io/d/github.com/cloudfoundry/os-conf-release?v=22.1.2 - -# shellcheck disable=SC2155 -export BOSH_PATH=$(which bosh) -export BASE_MANIFEST_PATH="$PWD/manifests/haproxy.yml" +bosh_release +bosh_assets cd "acceptance-tests" diff --git a/ci/scripts/functions-ci.sh b/ci/scripts/functions-ci.sh index 4834a1ae..90d82bd1 100755 --- a/ci/scripts/functions-ci.sh +++ b/ci/scripts/functions-ci.sh @@ -50,4 +50,31 @@ function git_pull() { git submodule update --init --recursive --force } -echo "Loaded shell script functions..." +function bosh_release() { + echo "----- Creating candidate BOSH release..." + bosh -n reset-release # in case dev_releases/ is in repo accidentally + + bosh create-release + bosh upload-release --rebase + release_final_version=$(spruce json dev_releases/*/index.yml | jq -r ".builds[].version" | sed -e "s%+.*%%") + export RELEASE_VERSION="${release_final_version}.latest" + echo "----- Created ${RELEASE_VERSION}" +} + +function bosh_assets() { + stemcell_jammy_path=$START_DIR/stemcell/*.tgz + stemcell_bionic_path=$START_DIR/stemcell-bionic/*.tgz + + echo "----- Uploading Jammy stemcell" + bosh -n upload-stemcell $stemcell_jammy_path + + echo "----- Uploading Bionic stemcell" + bosh -n upload-stemcell $stemcell_bionic_path + + echo "----- Uploading os-conf (used for tests only)" + bosh -n upload-release --sha1 386293038ae3d00813eaa475b4acf63f8da226ef \ + https://bosh.io/d/github.com/cloudfoundry/os-conf-release?v=22.1.2 + + export BOSH_PATH=$(which bosh) + export BASE_MANIFEST_PATH="$PWD/manifests/haproxy.yml" +} diff --git a/ci/scripts/shell b/ci/scripts/shell index 68d0cb96..2c17bb28 100755 --- a/ci/scripts/shell +++ b/ci/scripts/shell @@ -4,6 +4,7 @@ set -eu stemcell_path=$PWD/stemcell/*.tgz source "${REPO_ROOT}/ci/scripts/functions-ci.sh" +START_DIR="${PWD}" # Differs for CI and manual execution git_pull @@ -11,25 +12,9 @@ git_pull trap stop_docker EXIT +# shellcheck disable=SC1091 source /tmp/local-bosh/director/env - -echo "----- Creating candidate BOSH release..." -bosh -n reset-release # in case dev_releases/ is in repo accidentally - -bosh create-release -bosh upload-release --rebase -release_final_version=$(spruce json dev_releases/*/index.yml | jq -r ".builds[].version" | sed -e "s%+.*%%") -export RELEASE_VERSION="${release_final_version}.latest" -echo "----- Created ${RELEASE_VERSION}" - -echo "----- Uploading stemcell" -bosh -n upload-stemcell $stemcell_path - -echo "----- Uploading os-conf (used for tests only)" -bosh -n upload-release --sha1 386293038ae3d00813eaa475b4acf63f8da226ef \ - https://bosh.io/d/github.com/cloudfoundry/os-conf-release?v=22.1.2 - -export BOSH_PATH=$(which bosh) -export BASE_MANIFEST_PATH="$PWD/manifests/haproxy.yml" +bosh_release +bosh_assets bash From 9f3dacc40c162af2c9ce9341c2d51d1c632a893e Mon Sep 17 00:00:00 2001 From: Michal Tekel Date: Tue, 25 Mar 2025 16:03:02 +0000 Subject: [PATCH 07/15] test: remove SCRIPT_DIR variable --- acceptance-tests/run-local.sh | 13 ++++++------- acceptance-tests/run-shell.sh | 7 +++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/acceptance-tests/run-local.sh b/acceptance-tests/run-local.sh index cc0587f6..1af0ea78 100755 --- a/acceptance-tests/run-local.sh +++ b/acceptance-tests/run-local.sh @@ -3,9 +3,8 @@ FOCUS="$1" set -eu -SCRIPT_DIR="$(cd "$(dirname "$0")/" && pwd)" -REPO_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" -source "${SCRIPT_DIR}/../ci/scripts/functions-ci.sh" +REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)" +source "${REPO_DIR}/ci/scripts/functions-ci.sh" if ! [[ $(git status --porcelain=v1 2>/dev/null | wc -l) -eq 0 ]]; then echo "You have changes in your Git repository. Commit or clean (e.g. git clean -f) before running." @@ -32,14 +31,14 @@ docker_mac_check_cgroupsv1() { check_required_files() { PIDS="" REQUIRED_FILE_PATTERNS=( - ../ci/scripts/stemcell/bosh-stemcell-*-ubuntu-jammy-*.tgz!https://bosh.io/d/stemcells/bosh-warden-boshlite-ubuntu-jammy-go_agent - ../ci/scripts/stemcell-bionic/bosh-stemcell-*-ubuntu-bionic-*.tgz!https://bosh.io/d/stemcells/bosh-warden-boshlite-ubuntu-bionic-go_agent + ci/scripts/stemcell/bosh-stemcell-*-ubuntu-jammy-*.tgz!https://bosh.io/d/stemcells/bosh-warden-boshlite-ubuntu-jammy-go_agent + ci/scripts/stemcell-bionic/bosh-stemcell-*-ubuntu-bionic-*.tgz!https://bosh.io/d/stemcells/bosh-warden-boshlite-ubuntu-bionic-go_agent ) for entry in "${REQUIRED_FILE_PATTERNS[@]}"; do pattern=$(cut -f1 -d! <<<"$entry") url=$(cut -f2 -d! <<<"$entry") - folder=$(realpath "$(dirname "$SCRIPT_DIR/$pattern")") + folder=$(realpath "$(dirname "$REPO_DIR/$pattern")") filepattern=$(basename "$pattern") pattern=$folder/$filepattern @@ -72,7 +71,7 @@ if [ "$(uname)" == "Darwin" ]; then docker_mac_check_cgroupsv1 fi -build_image "${SCRIPT_DIR}/../ci" +build_image "${REPO_DIR}/ci" # Run acceptance tests if [ -n "$FOCUS" ]; then diff --git a/acceptance-tests/run-shell.sh b/acceptance-tests/run-shell.sh index 94c7522d..70d78130 100755 --- a/acceptance-tests/run-shell.sh +++ b/acceptance-tests/run-shell.sh @@ -2,11 +2,10 @@ set -e -SCRIPT_DIR="$(cd "$(dirname "$0")/" && pwd)" -REPO_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" -source "${SCRIPT_DIR}/../ci/scripts/functions-ci.sh" +REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)" +source "${REPO_DIR}/ci/scripts/functions-ci.sh" -build_image "${SCRIPT_DIR}/../ci" +build_image "${REPO_DIR}/ci" # Run local shell docker run -it --rm --privileged -v "$REPO_DIR":/repo -e REPO_ROOT=/repo haproxy-boshrelease-testflight bash -c "cd /repo/ci/scripts && ./shell" From 19385c401d2e9f4d27537e858fe194778f2ffaff Mon Sep 17 00:00:00 2001 From: Michal Tekel Date: Tue, 25 Mar 2025 16:41:34 +0000 Subject: [PATCH 08/15] test: run-local with pending changes When developing, do not check for clean repository. --- acceptance-tests/run-local.sh | 8 -------- ci/scripts/functions-ci.sh | 4 ++-- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/acceptance-tests/run-local.sh b/acceptance-tests/run-local.sh index 1af0ea78..b9df2f36 100755 --- a/acceptance-tests/run-local.sh +++ b/acceptance-tests/run-local.sh @@ -6,14 +6,6 @@ set -eu REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)" source "${REPO_DIR}/ci/scripts/functions-ci.sh" -if ! [[ $(git status --porcelain=v1 2>/dev/null | wc -l) -eq 0 ]]; then - echo "You have changes in your Git repository. Commit or clean (e.g. git clean -f) before running." - echo "The build will fail otherwise." - echo "Git Status:" - git status - exit 1 -fi - docker_mac_check_cgroupsv1() { # Force cgroups v1 on Docker for Mac # inspired by https://github.com/docker/for-mac/issues/6073#issuecomment-1018793677 diff --git a/ci/scripts/functions-ci.sh b/ci/scripts/functions-ci.sh index 90d82bd1..fc913b1c 100755 --- a/ci/scripts/functions-ci.sh +++ b/ci/scripts/functions-ci.sh @@ -54,7 +54,7 @@ function bosh_release() { echo "----- Creating candidate BOSH release..." bosh -n reset-release # in case dev_releases/ is in repo accidentally - bosh create-release + bosh create-release --force bosh upload-release --rebase release_final_version=$(spruce json dev_releases/*/index.yml | jq -r ".builds[].version" | sed -e "s%+.*%%") export RELEASE_VERSION="${release_final_version}.latest" @@ -75,6 +75,6 @@ function bosh_assets() { bosh -n upload-release --sha1 386293038ae3d00813eaa475b4acf63f8da226ef \ https://bosh.io/d/github.com/cloudfoundry/os-conf-release?v=22.1.2 - export BOSH_PATH=$(which bosh) + export BOSH_PATH=$(command -v bosh) export BASE_MANIFEST_PATH="$PWD/manifests/haproxy.yml" } From e8e0eb211dfc5dbff12cbb6fe7399efd306c4448 Mon Sep 17 00:00:00 2001 From: Michal Tekel Date: Wed, 26 Mar 2025 15:32:52 +0000 Subject: [PATCH 09/15] test: no parallelism when focused Run only on one node when specifying focus. This is to simplifly debug. co-authored-by: Alexander Lais --- ci/scripts/acceptance-tests | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ci/scripts/acceptance-tests b/ci/scripts/acceptance-tests index 0fa22610..402d7eaa 100755 --- a/ci/scripts/acceptance-tests +++ b/ci/scripts/acceptance-tests @@ -44,4 +44,10 @@ echo "----- Running tests" export PATH=$PATH:$GOPATH/bin ginkgo version -ginkgo -v -p -r --trace --show-node-events --randomize-all --flake-attempts 5 "${ADDITIONAL_ARGS[@]}" + +PARALLELISM="-p" +if [ -n "$FOCUS" ]; then + PARALLELISM="--nodes=1" +fi + +ginkgo -v "$PARALLELISM" -r --trace --show-node-events --randomize-all --flake-attempts 5 "${ADDITIONAL_ARGS[@]}" From 19e3eece8b4326a2c9854291bf8114437bd22b34 Mon Sep 17 00:00:00 2001 From: Michal Tekel Date: Wed, 26 Mar 2025 17:32:19 +0000 Subject: [PATCH 10/15] test: keep test bosh running when focused When doing manual debug, we want bosh container to keep running, so that we can easily run multiple focused tests. --- acceptance-tests/run-local.sh | 32 +++++++++++++++++++++++++++----- acceptance-tests/run-shell.sh | 26 +++++++++++++++++++++++--- ci/scripts/acceptance-tests | 14 +++----------- ci/scripts/functions-ci.sh | 24 ++++++++++++++++++++++++ ci/scripts/shell | 14 +++----------- ci/scripts/start-bosh.sh | 4 +++- 6 files changed, 83 insertions(+), 31 deletions(-) diff --git a/acceptance-tests/run-local.sh b/acceptance-tests/run-local.sh index b9df2f36..3c433951 100755 --- a/acceptance-tests/run-local.sh +++ b/acceptance-tests/run-local.sh @@ -1,10 +1,32 @@ #!/usr/bin/env bash -FOCUS="$1" set -eu - REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)" source "${REPO_DIR}/ci/scripts/functions-ci.sh" +KEEP_RUNNING="" + +usage() { + echo -e "Usage: $0 [-F ] [-k] + + -F Focus on a particular test. Expects a Ginkgo test name. Keep bosh running afterwards. + -k Keep bosh container running. Useful for debug." 1>&2; exit 1; +} + +while getopts ":F:k" o; do + case "${o}" in + F) + FOCUS=${OPTARG} + KEEP_RUNNING=true + ;; + k) + KEEP_RUNNING=true + ;; + *) + usage + ;; + esac +done +shift $((OPTIND-1)) docker_mac_check_cgroupsv1() { # Force cgroups v1 on Docker for Mac @@ -66,8 +88,8 @@ fi build_image "${REPO_DIR}/ci" # Run acceptance tests -if [ -n "$FOCUS" ]; then - docker run --privileged -v "$REPO_DIR":/repo -e REPO_ROOT=/repo -e FOCUS="$FOCUS" haproxy-boshrelease-testflight bash -c "cd /repo/ci/scripts && ./acceptance-tests ; sleep infinity" +if [ -n "$KEEP_RUNNING" ] ; then + docker run --privileged -v "$REPO_DIR":/repo -e REPO_ROOT=/repo -e FOCUS="$FOCUS" -e KEEP_RUNNING="${KEEP_RUNNING}" haproxy-boshrelease-testflight bash -c "cd /repo/ci/scripts && ./acceptance-tests ; sleep infinity" else - docker run --rm --privileged -v "$REPO_DIR":/repo -e REPO_ROOT=/repo haproxy-boshrelease-testflight bash -c "cd /repo/ci/scripts && ./acceptance-tests" + docker run --rm --privileged -v "$REPO_DIR":/repo -e REPO_ROOT=/repo -e KEEP_RUNNING="" haproxy-boshrelease-testflight bash -c "cd /repo/ci/scripts && ./acceptance-tests" fi diff --git a/acceptance-tests/run-shell.sh b/acceptance-tests/run-shell.sh index 70d78130..e0926821 100755 --- a/acceptance-tests/run-shell.sh +++ b/acceptance-tests/run-shell.sh @@ -1,11 +1,31 @@ #!/usr/bin/env bash set -e - REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)" source "${REPO_DIR}/ci/scripts/functions-ci.sh" +usage() { + echo -e "Usage: $0 [-k] + + -k Keep bosh container running. Useful for debug." 1>&2; exit 1; +} + +while getopts ":k" o; do + case "${o}" in + k) + KEEP_RUNNING=true + ;; + *) + usage + ;; + esac +done + build_image "${REPO_DIR}/ci" -# Run local shell -docker run -it --rm --privileged -v "$REPO_DIR":/repo -e REPO_ROOT=/repo haproxy-boshrelease-testflight bash -c "cd /repo/ci/scripts && ./shell" +# Run local shell - start new container with bosh +if [ -n "${KEEP_RUNNING}" ] ; then + docker run -it --privileged -v "$REPO_DIR":/repo -e KEEP_RUNNING="${KEEP_RUNNING}" -e REPO_ROOT=/repo haproxy-boshrelease-testflight bash -c "cd /repo/ci/scripts && ./shell ; sleep infinity" +else + docker run -it --rm --privileged -v "$REPO_DIR":/repo -e KEEP_RUNNING="" -e REPO_ROOT=/repo haproxy-boshrelease-testflight bash -c "cd /repo/ci/scripts && ./shell" +fi diff --git a/ci/scripts/acceptance-tests b/ci/scripts/acceptance-tests index 402d7eaa..9cc17e83 100755 --- a/ci/scripts/acceptance-tests +++ b/ci/scripts/acceptance-tests @@ -7,7 +7,6 @@ START_DIR="${PWD}" # Differs for CI and manual execution if [ -n "$FOCUS" ]; then echo "------------------------------------------------------------------" echo "FOCUS is set. Will only run tests matching '$FOCUS'" - echo "Docker won't be stopped afterwards, so you can debug the test." echo "------------------------------------------------------------------" ADDITIONAL_ARGS=("--focus" "$FOCUS") fi @@ -23,16 +22,7 @@ if [ -f ".git/resource/changed_files" ]; then fi fi -./ci/scripts/start-bosh.sh - -if [ -z "$FOCUS" ]; then - trap stop_docker EXIT -fi - -# shellcheck disable=SC1091 -source /tmp/local-bosh/director/env -bosh_release -bosh_assets +prepare_bosh cd "acceptance-tests" @@ -51,3 +41,5 @@ if [ -n "$FOCUS" ]; then fi ginkgo -v "$PARALLELISM" -r --trace --show-node-events --randomize-all --flake-attempts 5 "${ADDITIONAL_ARGS[@]}" + +keep_running_info diff --git a/ci/scripts/functions-ci.sh b/ci/scripts/functions-ci.sh index fc913b1c..19618eb5 100755 --- a/ci/scripts/functions-ci.sh +++ b/ci/scripts/functions-ci.sh @@ -78,3 +78,27 @@ function bosh_assets() { export BOSH_PATH=$(command -v bosh) export BASE_MANIFEST_PATH="$PWD/manifests/haproxy.yml" } + +function prepare_bosh() { + if [ -z "${KEEP_RUNNING}" ] ; then + ./ci/scripts/start-bosh.sh + trap stop_docker EXIT + elif ! bosh deployments &>/dev/null ; then # With KEEP_RUNNING only start when not running already + ./ci/scripts/start-bosh.sh + fi + + # shellcheck disable=SC1091 + source /tmp/local-bosh/director/env + bosh_release + bosh_assets +} + +function keep_running_info() { + if [ -n "${KEEP_RUNNING}" ] ; then + echo + echo "KEEP_RUNNING is ${KEEP_RUNNING} and bosh remains running." + echo "Re-enter container via: docker exec -it `hostname` bash" + echo + echo "Stop with: docker stop `hostname`" + fi +} diff --git a/ci/scripts/shell b/ci/scripts/shell index 2c17bb28..6e159d69 100755 --- a/ci/scripts/shell +++ b/ci/scripts/shell @@ -1,20 +1,12 @@ #!/bin/bash set -eu - -stemcell_path=$PWD/stemcell/*.tgz source "${REPO_ROOT}/ci/scripts/functions-ci.sh" START_DIR="${PWD}" # Differs for CI and manual execution git_pull - -./ci/scripts/start-bosh.sh - -trap stop_docker EXIT - -# shellcheck disable=SC1091 -source /tmp/local-bosh/director/env -bosh_release -bosh_assets +prepare_bosh bash + +keep_running_info diff --git a/ci/scripts/start-bosh.sh b/ci/scripts/start-bosh.sh index 53c5fa75..c693ada5 100755 --- a/ci/scripts/start-bosh.sh +++ b/ci/scripts/start-bosh.sh @@ -162,7 +162,9 @@ EOF exit 1 fi - trap stop_docker ERR + if [ -z "${KEEP_RUNNING}" ] ; then + trap stop_docker ERR + fi echo $certs_dir } From 4d5ecd4fe1a6d591d074c3385a9b2705f091eed5 Mon Sep 17 00:00:00 2001 From: Michal Tekel Date: Thu, 27 Mar 2025 10:59:37 +0000 Subject: [PATCH 11/15] test: reduce compilation VMs Creating VMs with docker-cpi, when running in docker, is I/O heavy and slow. There is no need for 5 compilation VMs, there is not much to compile in this release. Reduce to 2 to speed up deployment (and overall acceptance tests run time). --- ci/compilation.yml | 3 +++ ci/scripts/start-bosh.sh | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 ci/compilation.yml diff --git a/ci/compilation.yml b/ci/compilation.yml new file mode 100644 index 00000000..a8fa4e0c --- /dev/null +++ b/ci/compilation.yml @@ -0,0 +1,3 @@ +- path: /compilation/workers + type: replace + value: 2 diff --git a/ci/scripts/start-bosh.sh b/ci/scripts/start-bosh.sh index c693ada5..7c5a6f07 100755 --- a/ci/scripts/start-bosh.sh +++ b/ci/scripts/start-bosh.sh @@ -186,6 +186,7 @@ function main() { docker network create -d bridge --subnet=10.245.0.0/16 director_network fi + compilation_ops="$PWD/ci/compilation.yml" pushd ${BOSH_DEPLOYMENT_PATH:-/usr/local/bosh-deployment} > /dev/null export BOSH_DIRECTOR_IP="10.245.0.3" export BOSH_ENVIRONMENT="docker-director" @@ -220,7 +221,7 @@ function main() { EOF source "${local_bosh_dir}/env" - bosh -n update-cloud-config docker/cloud-config.yml -v network=director_network + bosh -n update-cloud-config docker/cloud-config.yml -v network=director_network -o "${compilation_ops}" popd > /dev/null } From 12e8ab4c8e2cc7ef91568c778bf64dcd0c8b3819 Mon Sep 17 00:00:00 2001 From: Michal Tekel Date: Thu, 27 Mar 2025 15:46:43 +0000 Subject: [PATCH 12/15] test: use external scratch for internal docker Mouting ext4 scratch inside docker means that internal docker can run overlay2 filesystem, meaning it doesn't need to copy data on container creation like with VFS. --- acceptance-tests/run-local.sh | 10 ++++++++-- acceptance-tests/run-shell.sh | 10 ++++++++-- ci/scripts/functions-ci.sh | 6 ++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/acceptance-tests/run-local.sh b/acceptance-tests/run-local.sh index 3c433951..391a8acd 100755 --- a/acceptance-tests/run-local.sh +++ b/acceptance-tests/run-local.sh @@ -86,10 +86,16 @@ if [ "$(uname)" == "Darwin" ]; then fi build_image "${REPO_DIR}/ci" +prepare_docker_scratch # Run acceptance tests if [ -n "$KEEP_RUNNING" ] ; then - docker run --privileged -v "$REPO_DIR":/repo -e REPO_ROOT=/repo -e FOCUS="$FOCUS" -e KEEP_RUNNING="${KEEP_RUNNING}" haproxy-boshrelease-testflight bash -c "cd /repo/ci/scripts && ./acceptance-tests ; sleep infinity" + echo + echo "*** KEEP_RUNNING enabled. Please clean up docker scratch after removing containers: ${DOCKER_SCRATCH}" + echo + docker run --privileged -v "$REPO_DIR":/repo -v "${DOCKER_SCRATCH}":/scratch/docker -e REPO_ROOT=/repo -e FOCUS="$FOCUS" -e KEEP_RUNNING="${KEEP_RUNNING}" haproxy-boshrelease-testflight bash -c "cd /repo/ci/scripts && ./acceptance-tests ; sleep infinity" else - docker run --rm --privileged -v "$REPO_DIR":/repo -e REPO_ROOT=/repo -e KEEP_RUNNING="" haproxy-boshrelease-testflight bash -c "cd /repo/ci/scripts && ./acceptance-tests" + docker run --rm --privileged -v "$REPO_DIR":/repo -v "${DOCKER_SCRATCH}":/scratch/docker -e REPO_ROOT=/repo -e KEEP_RUNNING="" haproxy-boshrelease-testflight bash -c "cd /repo/ci/scripts && ./acceptance-tests" + echo "Cleaning up docker scratch: ${DOCKER_SCRATCH}" + sudo rm -rf "${DOCKER_SCRATCH}" fi diff --git a/acceptance-tests/run-shell.sh b/acceptance-tests/run-shell.sh index e0926821..b0d094d9 100755 --- a/acceptance-tests/run-shell.sh +++ b/acceptance-tests/run-shell.sh @@ -22,10 +22,16 @@ while getopts ":k" o; do done build_image "${REPO_DIR}/ci" +prepare_docker_scratch # Run local shell - start new container with bosh if [ -n "${KEEP_RUNNING}" ] ; then - docker run -it --privileged -v "$REPO_DIR":/repo -e KEEP_RUNNING="${KEEP_RUNNING}" -e REPO_ROOT=/repo haproxy-boshrelease-testflight bash -c "cd /repo/ci/scripts && ./shell ; sleep infinity" + echo + echo "*** KEEP_RUNNING enabled. Please clean up docker scratch after removing containers: ${DOCKER_SCRATCH}" + echo + docker run -it --privileged -v "$REPO_DIR":/repo -v "${DOCKER_SCRATCH}":/scratch/docker -e KEEP_RUNNING="${KEEP_RUNNING}" -e REPO_ROOT=/repo haproxy-boshrelease-testflight bash -c "cd /repo/ci/scripts && ./shell ; sleep infinity" else - docker run -it --rm --privileged -v "$REPO_DIR":/repo -e KEEP_RUNNING="" -e REPO_ROOT=/repo haproxy-boshrelease-testflight bash -c "cd /repo/ci/scripts && ./shell" + docker run -it --rm --privileged -v "$REPO_DIR":/repo -v "${DOCKER_SCRATCH}":/scratch/docker -e KEEP_RUNNING="" -e REPO_ROOT=/repo haproxy-boshrelease-testflight bash -c "cd /repo/ci/scripts && ./shell" + echo "Cleaning up docker scratch: ${DOCKER_SCRATCH}" + sudo rm -rf "${DOCKER_SCRATCH}" fi diff --git a/ci/scripts/functions-ci.sh b/ci/scripts/functions-ci.sh index 19618eb5..a250cc7e 100755 --- a/ci/scripts/functions-ci.sh +++ b/ci/scripts/functions-ci.sh @@ -102,3 +102,9 @@ function keep_running_info() { echo "Stop with: docker stop `hostname`" fi } + +# Prepare ext4 based scratch for internal docker. This is so that it can run overlay2 FS for its containers. +function prepare_docker_scratch() { + DOCKER_SCRATCH="/workspace/docker-in/scratch-$RANDOM" + mkdir $DOCKER_SCRATCH +} From ee49e1bfe483df12ab55cb02c2911ec70783f76f Mon Sep 17 00:00:00 2001 From: Michal Tekel Date: Mon, 31 Mar 2025 16:51:45 +0100 Subject: [PATCH 13/15] doc: Update acceptace tests docs Reflect updated scripts and describe new persistence options. --- acceptance-tests/README.md | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/acceptance-tests/README.md b/acceptance-tests/README.md index 151a1ce1..a6080821 100644 --- a/acceptance-tests/README.md +++ b/acceptance-tests/README.md @@ -3,10 +3,7 @@ ## Requirements * Docker installed locally -* A matching Jammy stemcell tgz downloaded to `ci/scripts/stemcell` - * Get it from https://bosh.io/stemcells/bosh-warden-boshlite-ubuntu-jammy-go_agent -* A matching Bionic stemcell tgz downloaded to `ci/scripts/stemcell-bionic` - * Get it from https://bosh.io/stemcells/bosh-warden-boshlite-ubuntu-bionic-go_agent +* x86 based computer (cloudfoundry currently doesn't build/run on arm; rosetta can't run docker in docker for x86) ## Running @@ -17,6 +14,8 @@ cd acceptance-tests ### Running on Docker for Mac +Unfortunately rosetta on arm based macs doesn't support docker in docker required for bosh docker-cpi used in this test setup. You will either have to run on x86 based mac or some remote x86 workstation. Virtualization using QUEMU is possible, but so slow the tests fail on timeouts. + The BOSH Docker CPI requires cgroups v1 to be active. Docker for Mac since 4.3.x uses cgroups v2 by default. v1 can be restored with the flag `deprecatedCgroupv1` to `true` in `~/Library/Group Containers/group.com.docker/settings.json`. @@ -80,24 +79,40 @@ The output at the end should be: If you want to run only a specific part of the suite, you can use [focussed specs](https://onsi.github.io/ginkgo/#focused-specs) -The easiest way is to just provide the name of the tests you want to run as a command line argument like so: +The easiest way is to just provide the name of the tests you want to run as a `-F` command line argument: ```shell -./run-local.sh "description of the test to run" +./run-local.sh -F "description of the test to run" ``` The argument is passed as a regular expression that will match all `Describe`, `Context` or `It` closure descriptions in the suite. So, e.g. if you want to run all tests that use mTLS, you can run: ```shell -./run-local.sh mTLS +./run-local.sh -F mTLS ``` However, if you want to run exactly one specific test, make sure you pass the exact description of the matching `It` closure: ```shell -./run-local.sh "Correctly terminates mTLS requests" +./run-local.sh -F "Correctly terminates mTLS requests" ``` -Alternatively, you add an `F` to your `Describe`, `Context` or `It` closures. -Don't forget to do a local commit before running the tests, else BOSH will fail to produce a release. The git repo must be clean before running the tests. +Running tests in focus will also preserve bosh container running after tests complete, so that you can easily run tests again without having to wait for bosh set-up again. + +### Bosh persistence + +Because BOSH setup takes a while (it starts from scratch with bosh create-env), it is useful to preserve container with bosh already configured to run tests. This can be done either by providing test focus as described above, or `-k` (keep) switch to `run-local.sh` and `run-shell.sh` scripts, e.g. `run-shell.sh -k`. Once initial setup is complete, scripts will output message about how to get back into running container: + +```text +KEEP_RUNNING is true and bosh remains running. +Re-enter container via: docker exec -it b7c767c5c0e4 bash + +Stop with: docker stop b7c767c5c0e4 +``` + +After you have completed your work and have stopped the container, it is required you do further cleanup. In order to have working overlay2 filesystem for docker-cpi, it is necessary to mount ext4 based storage from `/workspace/docker-in` into bosh container. Each container gets its own temporary space, which in case of containers that keep running is not deleted when the tests complete. The scripts will output location of this temporary storage: + +```text +*** KEEP_RUNNING enabled. Please clean up docker scratch after removing containers: /workspace/docker-in/scratch-19517 +``` From d040b090ebd90098804cc5a50cd8b3a52a5aecde Mon Sep 17 00:00:00 2001 From: mtekel Date: Wed, 2 Apr 2025 12:46:27 +0100 Subject: [PATCH 14/15] doc: Fix spelling, articles and other minor things Co-authored-by: Alexander Lais --- acceptance-tests/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/acceptance-tests/README.md b/acceptance-tests/README.md index a6080821..637bd45c 100644 --- a/acceptance-tests/README.md +++ b/acceptance-tests/README.md @@ -14,7 +14,7 @@ cd acceptance-tests ### Running on Docker for Mac -Unfortunately rosetta on arm based macs doesn't support docker in docker required for bosh docker-cpi used in this test setup. You will either have to run on x86 based mac or some remote x86 workstation. Virtualization using QUEMU is possible, but so slow the tests fail on timeouts. +Unfortunately rosetta on arm based macs doesn't support docker in docker required for bosh docker-cpi used in this test setup. You will either have to run on x86 based mac or some remote x86 workstation. Virtualization using QEMU is possible, but so slow the tests fail on timeouts. The BOSH Docker CPI requires cgroups v1 to be active. Docker for Mac since 4.3.x uses cgroups v2 by default. @@ -98,11 +98,11 @@ However, if you want to run exactly one specific test, make sure you pass the ex ./run-local.sh -F "Correctly terminates mTLS requests" ``` -Running tests in focus will also preserve bosh container running after tests complete, so that you can easily run tests again without having to wait for bosh set-up again. +Running tests in focus will also preserve the bosh container running after tests complete, so that you can easily run tests again without having to wait for bosh set-up again. -### Bosh persistence +### Persistent BOSH -Because BOSH setup takes a while (it starts from scratch with bosh create-env), it is useful to preserve container with bosh already configured to run tests. This can be done either by providing test focus as described above, or `-k` (keep) switch to `run-local.sh` and `run-shell.sh` scripts, e.g. `run-shell.sh -k`. Once initial setup is complete, scripts will output message about how to get back into running container: +Because BOSH setup takes a while (it starts from scratch with bosh create-env), it is useful to preserve the container with bosh already configured to run tests. This can be done either by providing test focus as described above, or `-k` (keep) switch to `run-local.sh` and `run-shell.sh` scripts, e.g. `run-shell.sh -k`. Once initial setup is complete, scripts will output a message about how to get back into the running container: ```text KEEP_RUNNING is true and bosh remains running. @@ -111,7 +111,7 @@ Re-enter container via: docker exec -it b7c767c5c0e4 bash Stop with: docker stop b7c767c5c0e4 ``` -After you have completed your work and have stopped the container, it is required you do further cleanup. In order to have working overlay2 filesystem for docker-cpi, it is necessary to mount ext4 based storage from `/workspace/docker-in` into bosh container. Each container gets its own temporary space, which in case of containers that keep running is not deleted when the tests complete. The scripts will output location of this temporary storage: +After you have completed your work and have stopped the container, it is required you do further cleanup. In order to have a working overlay2 filesystem for docker-cpi, it is necessary to mount ext4 based storage from `/workspace/docker-in` into the bosh container. Each container gets its own temporary space, which in case of containers that keep running is not deleted when the tests complete. The scripts will output the location of this temporary storage: ```text *** KEEP_RUNNING enabled. Please clean up docker scratch after removing containers: /workspace/docker-in/scratch-19517 From d02c41197e3d4047f4c793d15c08903dfa527fe5 Mon Sep 17 00:00:00 2001 From: Michal Tekel Date: Mon, 7 Apr 2025 12:41:30 +0100 Subject: [PATCH 15/15] test: apply shellcheck recommendations SC2086 (info): Double quote to prevent globbing and word splitting. and similar. Note that in some cases scripts do depend on various side effect, so not all SC recommendations are applied. --- ci/scripts/functions-ci.sh | 8 ++++---- ci/scripts/lint | 2 +- ci/scripts/start-bosh.sh | 8 ++++---- ci/scripts/unit-tests | 2 +- ci/scripts/update-blob | 28 ++++++++++++++-------------- ci/scripts/update-manifest | 7 +++---- 6 files changed, 27 insertions(+), 28 deletions(-) diff --git a/ci/scripts/functions-ci.sh b/ci/scripts/functions-ci.sh index a250cc7e..d3e64d50 100755 --- a/ci/scripts/functions-ci.sh +++ b/ci/scripts/functions-ci.sh @@ -62,8 +62,8 @@ function bosh_release() { } function bosh_assets() { - stemcell_jammy_path=$START_DIR/stemcell/*.tgz - stemcell_bionic_path=$START_DIR/stemcell-bionic/*.tgz + stemcell_jammy_path="$START_DIR/stemcell/*.tgz" + stemcell_bionic_path="$START_DIR/stemcell-bionic/*.tgz" echo "----- Uploading Jammy stemcell" bosh -n upload-stemcell $stemcell_jammy_path @@ -97,9 +97,9 @@ function keep_running_info() { if [ -n "${KEEP_RUNNING}" ] ; then echo echo "KEEP_RUNNING is ${KEEP_RUNNING} and bosh remains running." - echo "Re-enter container via: docker exec -it `hostname` bash" + echo "Re-enter container via: docker exec -it $(hostname) bash" echo - echo "Stop with: docker stop `hostname`" + echo "Stop with: docker stop $(hostname)" fi } diff --git a/ci/scripts/lint b/ci/scripts/lint index cdba86b7..9b8a4419 100755 --- a/ci/scripts/lint +++ b/ci/scripts/lint @@ -2,7 +2,7 @@ set -euo pipefail -cd ${REPO_ROOT} +cd "${REPO_ROOT}" bundle package bundle exec rake lint diff --git a/ci/scripts/start-bosh.sh b/ci/scripts/start-bosh.sh index 7c5a6f07..3bda28f6 100755 --- a/ci/scripts/start-bosh.sh +++ b/ci/scripts/start-bosh.sh @@ -165,7 +165,7 @@ EOF if [ -z "${KEEP_RUNNING}" ] ; then trap stop_docker ERR fi - echo $certs_dir + echo "$certs_dir" } function main() { @@ -187,7 +187,7 @@ function main() { fi compilation_ops="$PWD/ci/compilation.yml" - pushd ${BOSH_DEPLOYMENT_PATH:-/usr/local/bosh-deployment} > /dev/null + pushd "${BOSH_DEPLOYMENT_PATH:-/usr/local/bosh-deployment}" > /dev/null export BOSH_DIRECTOR_IP="10.245.0.3" export BOSH_ENVIRONMENT="docker-director" @@ -202,7 +202,7 @@ function main() { -v internal_ip="${BOSH_DIRECTOR_IP}" \ -v docker_host="${DOCKER_HOST}" \ -v network=director_network \ - -v docker_tls="{\"ca\": \"$(cat ${certs_dir}/ca_json_safe.pem)\",\"certificate\": \"$(cat ${certs_dir}/client_certificate_json_safe.pem)\",\"private_key\": \"$(cat ${certs_dir}/client_private_key_json_safe.pem)\"}" \ + -v docker_tls="{\"ca\": \"$(cat "${certs_dir}"/ca_json_safe.pem)\",\"certificate\": \"$(cat "${certs_dir}"/client_certificate_json_safe.pem)\",\"private_key\": \"$(cat "${certs_dir}"/client_private_key_json_safe.pem)\"}" \ ${@} > "${local_bosh_dir}/bosh-director.yml" command bosh create-env "${local_bosh_dir}/bosh-director.yml" \ @@ -215,7 +215,7 @@ function main() { cat < "${local_bosh_dir}/env" export BOSH_ENVIRONMENT="${BOSH_ENVIRONMENT}" export BOSH_CLIENT=admin - export BOSH_CLIENT_SECRET=`bosh int "${local_bosh_dir}/creds.yml" --path /admin_password` + export BOSH_CLIENT_SECRET=$(bosh int "${local_bosh_dir}/creds.yml" --path /admin_password) export BOSH_CA_CERT="${local_bosh_dir}/ca.crt" EOF diff --git a/ci/scripts/unit-tests b/ci/scripts/unit-tests index 0cca6285..dc9d50fa 100755 --- a/ci/scripts/unit-tests +++ b/ci/scripts/unit-tests @@ -2,7 +2,7 @@ set -euo pipefail -cd ${REPO_ROOT} +cd "${REPO_ROOT}" bundle install bundle exec rake spec diff --git a/ci/scripts/update-blob b/ci/scripts/update-blob index f23d825b..976b504b 100755 --- a/ci/scripts/update-blob +++ b/ci/scripts/update-blob @@ -2,15 +2,15 @@ set -e -: ${BLOB_DIR:?required} -: ${BLOB_NAME:?required} -: ${BLOB_BINARY:?required} -: ${BLOB_CLEANUP:?required} -: ${BLOB_DESTINATION:?required} +: "${BLOB_DIR:?required}" +: "${BLOB_NAME:?required}" +: "${BLOB_BINARY:?required}" +: "${BLOB_CLEANUP:?required}" +: "${BLOB_DESTINATION:?required}" -VERSION=$(cat ${BLOB_DIR}/version) +VERSION=$(cat "${BLOB_DIR}"/version) -pushd ${REPO_ROOT:?required} +pushd "${REPO_ROOT:?required}" cat <config/private.yml --- @@ -22,19 +22,19 @@ blobstore: EOF blobs_to_remove=$(spruce json config/blobs.yml | jq -r "keys[] | select(test(\"${BLOB_CLEANUP}\"))") -if [[ ! -z $blobs_to_remove ]]; then +if [[ -n $blobs_to_remove ]]; then echo "$blobs_to_remove" | xargs -L1 bosh remove-blob fi # expand ${VERSION} env var into file path eval "blob_destination=${BLOB_DESTINATION}" -bosh add-blob ../${BLOB_DIR}/${BLOB_BINARY} "${blob_destination}" +bosh add-blob "../${BLOB_DIR}/${BLOB_BINARY}" "${blob_destination}" bosh -n upload-blobs rm config/private.yml popd -if [[ -n "$(cd ${REPO_ROOT}; git status --porcelain)" ]]; then - pushd ${REPO_ROOT} +if [[ -n "$(cd "${REPO_ROOT}"; git status --porcelain)" ]]; then + pushd "${REPO_ROOT}" cat <>ci/release_notes.md # ${BLOB_NAME} @@ -50,12 +50,12 @@ EOF git config --global user.name "CI Bot" fi - (cd ${REPO_ROOT} - git merge --no-edit ${BRANCH} + (cd "${REPO_ROOT}" + git merge --no-edit "${BRANCH}" git add -A git status git commit -m "Bumped ${BLOB_NAME} to v${VERSION}") fi # so that future steps in the pipeline can push our changes -cp -a ${REPO_ROOT} ${REPO_OUT} +cp -a "${REPO_ROOT}" "${REPO_OUT}" diff --git a/ci/scripts/update-manifest b/ci/scripts/update-manifest index 40a58afc..dc887733 100755 --- a/ci/scripts/update-manifest +++ b/ci/scripts/update-manifest @@ -5,13 +5,12 @@ RELEASE_NAME=$2 VERSION=$3 SHA1=$4 MANIFEST_PATH=$5 -: ${MANIFEST_PATH:?USAGE: ./ci/scripts/update-manifest GITHUB_OWNER RELEASE_NAME VERSION SHA1 MANIFEST_PATH} +: "${MANIFEST_PATH:?USAGE: ./ci/scripts/update-manifest GITHUB_OWNER RELEASE_NAME VERSION SHA1 MANIFEST_PATH}" set -e -u -manifest_len=$(wc -l $MANIFEST_PATH | awk '{print $1}') -manifest_head=$(head -n `expr $manifest_len - 4` $MANIFEST_PATH) -cat > $MANIFEST_PATH < "$MANIFEST_PATH" <