fix(tests)_: identify containers with BUILD_ID or git sha

This commit:
- updates both status docker container names to include short git sha locally and BUILD_ID on CI
- updates cleanup command to filter by identifier which could be either git sha or BUILD_ID
- updates the cleanup stage in `jenkins` file to remove docker container via this identifier

This approach is more reliable in cleaning up docker containers and was tested by me on linux-05
This commit is contained in:
Siddarth Kumar 2025-01-28 09:34:24 +05:30
parent 06d2419a25
commit c993c7f6f1
3 changed files with 14 additions and 7 deletions

View File

@ -76,7 +76,14 @@ pipeline {
}
success { script { github.notifyPR(true) } }
failure { script { github.notifyPR(false) } }
cleanup { sh 'make git-clean' }
cleanup {
script {
sh '''
docker ps -a --filter "name=status-go-func-tests-${BUILD_ID}" -q | xargs -r docker rm
make git-clean
'''
}
}
} // post
} // pipeline

View File

@ -24,13 +24,13 @@ mkdir -p "${merged_coverage_reports_path}"
mkdir -p "${test_results_path}"
all_compose_files="-f ${root_path}/docker-compose.anvil.yml -f ${root_path}/docker-compose.test.status-go.yml"
timestamp=$(python3 -c "import time; print(int(time.time() * 1000))") # Keep in sync with status_backend.py
project_name="status-go-func-tests-${timestamp}"
identifier=${BUILD_ID:-$(git rev-parse --short HEAD)}
project_name="status-go-func-tests-${identifier}"
export STATUS_BACKEND_URLS=$(eval echo http://${project_name}-status-backend-{1..${STATUS_BACKEND_COUNT}}:3333 | tr ' ' ,)
# Remove orphans
docker ps -a --filter "name=status-go-func-tests-*-status-backend-*" --filter "status=exited" -q | xargs -r docker rm
docker ps -a --filter "status-go-func-tests-${identifier}" --filter "status=exited" -q | xargs -r docker rm
# Run docker
echo -e "${GRN}Running tests${RST}, HEAD: $(git rev-parse HEAD)"
@ -83,4 +83,4 @@ if [[ ${FUNCTIONAL_TESTS_REPORT_CODECOV} == 'true' ]]; then
fi
echo -e "${GRN}Testing finished${RST}"
exit $exit_code
exit $exit_code

View File

@ -63,9 +63,9 @@ class StatusBackend(RpcClient, SignalClient):
def _start_container(self, host_port, privileged):
docker_project_name = option.docker_project_name
timestamp = int(time.time() * 1000) # Keep in sync with run_functional_tests.sh
identifier = os.environ.get("BUILD_ID") if os.environ.get("CI") else os.popen("git rev-parse --short HEAD").read().strip()
image_name = f"{docker_project_name}-status-backend:latest"
container_name = f"{docker_project_name}-status-backend-{timestamp}"
container_name = f"{docker_project_name}-{identifier}-status-backend-{host_port}"
coverage_path = option.codecov_dir if option.codecov_dir else os.path.abspath("./coverage/binary")