From 711804b5fbb57626aa276bb791d73720ae83bbfd Mon Sep 17 00:00:00 2001 From: David Boreham Date: Sun, 18 Feb 2024 10:44:35 -0700 Subject: [PATCH] Add comment --- .gitea/workflows/test-container-registry.yml | 52 +++++++ .../triggers/test-container-registry | 1 + scripts/quick-deploy-test.sh | 4 +- .../docker-compose-container-registry.yml | 2 +- tests/container-registry/run-test.sh | 141 ++++++++++++++++++ 5 files changed, 197 insertions(+), 3 deletions(-) create mode 100644 .gitea/workflows/test-container-registry.yml create mode 100644 .gitea/workflows/triggers/test-container-registry create mode 100755 tests/container-registry/run-test.sh diff --git a/.gitea/workflows/test-container-registry.yml b/.gitea/workflows/test-container-registry.yml new file mode 100644 index 00000000..8380e83f --- /dev/null +++ b/.gitea/workflows/test-container-registry.yml @@ -0,0 +1,52 @@ +name: Container Registry Test + +on: + push: + branches: '*' + paths: + - '!**' + - '.gitea/workflows/triggers/test-container-registry' + - '.gitea/workflows/test-container-registry.yml' + - 'tests/container-registry/run-test.sh' + schedule: # Note: coordinate with other tests to not overload runners at the same time of day + - cron: '6 19 * * *' + +jobs: + test: + name: "Run contaier registry hosting test on kind/k8s" + runs-on: ubuntu-22.04 + steps: + - name: "Clone project repository" + uses: actions/checkout@v3 + # At present the stock setup-python action fails on Linux/aarch64 + # Conditional steps below workaroud this by using deadsnakes for that case only + - name: "Install Python for ARM on Linux" + if: ${{ runner.arch == 'arm64' && runner.os == 'Linux' }} + uses: deadsnakes/action@v3.0.1 + with: + python-version: '3.8' + - name: "Install Python cases other than ARM on Linux" + if: ${{ ! (runner.arch == 'arm64' && runner.os == 'Linux') }} + uses: actions/setup-python@v4 + with: + python-version: '3.8' + - name: "Print Python version" + run: python3 --version + - name: "Install shiv" + run: pip install shiv + - name: "Generate build version file" + run: ./scripts/create_build_tag_file.sh + - name: "Build local shiv package" + run: ./scripts/build_shiv_package.sh + - name: "Check cgroups version" + run: mount | grep cgroup + - name: "Install kind" + run: ./tests/scripts/install-kind.sh + - name: "Install Kubectl" + run: ./tests/scripts/install-kubectl.sh + - name: "Run container registry deployment test" + run: | + source /opt/bash-utils/cgroup-helper.sh + join_cgroup + ./tests/container-registry/run-test.sh + diff --git a/.gitea/workflows/triggers/test-container-registry b/.gitea/workflows/triggers/test-container-registry new file mode 100644 index 00000000..e5c11f22 --- /dev/null +++ b/.gitea/workflows/triggers/test-container-registry @@ -0,0 +1 @@ +Change this file to trigger running the test-container-registry CI job \ No newline at end of file diff --git a/scripts/quick-deploy-test.sh b/scripts/quick-deploy-test.sh index 597eb6ac..5c32d449 100755 --- a/scripts/quick-deploy-test.sh +++ b/scripts/quick-deploy-test.sh @@ -12,8 +12,8 @@ spec_file_name="${stack_name}-spec.yml" deployment_dir_name="${stack_name}-deployment" rm -f ${spec_file_name} rm -rf ${deployment_dir_name} -laconic-so --stack ${stack_name} deploy --deploy-to k8s-kind init --output ${spec_file_name} -laconic-so --stack ${stack_name} deploy --deploy-to k8s-kind create --deployment-dir ${deployment_dir_name} --spec-file ${spec_file_name} +laconic-so --stack ${stack_name} deploy --deploy-to compose init --output ${spec_file_name} +laconic-so --stack ${stack_name} deploy --deploy-to compose create --deployment-dir ${deployment_dir_name} --spec-file ${spec_file_name} #laconic-so deployment --dir ${deployment_dir_name} start #laconic-so deployment --dir ${deployment_dir_name} ps #laconic-so deployment --dir ${deployment_dir_name} stop diff --git a/stack_orchestrator/data/compose/docker-compose-container-registry.yml b/stack_orchestrator/data/compose/docker-compose-container-registry.yml index a0ad153d..91d6d265 100644 --- a/stack_orchestrator/data/compose/docker-compose-container-registry.yml +++ b/stack_orchestrator/data/compose/docker-compose-container-registry.yml @@ -1,5 +1,5 @@ services: - test: + registry: image: registry:2.8 restart: always environment: diff --git a/tests/container-registry/run-test.sh b/tests/container-registry/run-test.sh new file mode 100755 index 00000000..2aaf887f --- /dev/null +++ b/tests/container-registry/run-test.sh @@ -0,0 +1,141 @@ +#!/usr/bin/env bash +set -e +if [ -n "$CERC_SCRIPT_DEBUG" ]; then + set -x + # Dump environment variables for debugging + echo "Environment variables:" + env +fi + +stack="container-registry" + +# Helper functions: TODO move into a separate file +wait_for_pods_started () { + for i in {1..50} + do + local ps_output=$( $TEST_TARGET_SO deployment --dir $test_deployment_dir ps ) + + if [[ "$ps_output" == *"Running containers:"* ]]; then + # if ready, return + return + else + # if not ready, wait + sleep 5 + fi + done + # Timed out, error exit + echo "waiting for pods to start: FAILED" + delete_cluster_exit +} + +wait_for_log_output () { + for i in {1..50} + do + + local log_output=$( $TEST_TARGET_SO deployment --dir $test_deployment_dir logs ) + + if [[ ! -z "$log_output" ]]; then + # if ready, return + return + else + # if not ready, wait + sleep 5 + fi + done + # Timed out, error exit + echo "waiting for pods log content: FAILED" + delete_cluster_exit +} + + +delete_cluster_exit () { + $TEST_TARGET_SO deployment --dir $test_deployment_dir stop --delete-volumes + exit 1 +} + +# Note: eventually this test should be folded into ../deploy/ +# but keeping it separate for now for convenience +TEST_TARGET_SO=$( ls -t1 ./package/laconic-so* | head -1 ) +# Set a non-default repo dir +export CERC_REPO_BASE_DIR=~/stack-orchestrator-test/repo-base-dir +echo "Testing this package: $TEST_TARGET_SO" +echo "Test version command" +reported_version_string=$( $TEST_TARGET_SO version ) +echo "Version reported is: ${reported_version_string}" +echo "Cloning repositories into: $CERC_REPO_BASE_DIR" +rm -rf $CERC_REPO_BASE_DIR +mkdir -p $CERC_REPO_BASE_DIR +$TEST_TARGET_SO --stack ${stack} setup-repositories +$TEST_TARGET_SO --stack ${stack} build-containers +# Test basic stack-orchestrator deploy to k8s +test_deployment_dir=$CERC_REPO_BASE_DIR/${stack}-deployment-dir +test_deployment_spec=$CERC_REPO_BASE_DIR/${stack}-deployment-spec.yml +$TEST_TARGET_SO --stack ${stack} deploy --deploy-to k8s-kind init --output $test_deployment_spec --config CERC_TEST_PARAM_1=PASSED +# Check the file now exists +if [ ! -f "$test_deployment_spec" ]; then + echo "deploy init test: spec file not present" + echo "deploy init test: FAILED" + exit 1 +fi +echo "deploy init test: passed" + +# Switch to a full path for bind mount. +volume_name="registry-data" +sed -i "s|^\(\s*${volume_name}:$\)$|\1 ${test_deployment_dir}/data/${volume_name}|" $test_deployment_spec + +# Add ingress config to the spec file +ed $test_deployment_spec <