Skip to content

Commit

Permalink
fix(tests)_: identify containers with BUILD_ID or git sha
Browse files Browse the repository at this point in the history
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-03
  • Loading branch information
siddarthkay committed Jan 29, 2025
1 parent 06d2419 commit 8235e29
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
9 changes: 8 additions & 1 deletion _assets/ci/Jenkinsfile.tests-rpc
Original file line number Diff line number Diff line change
Expand Up @@ -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=${BUILD_ID}" -q | xargs -r docker rm
make git-clean
'''
}
}
} // post
} // pipeline

Expand Down
6 changes: 3 additions & 3 deletions _assets/scripts/run_functional_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "${identifier}" --filter "status=exited" -q | xargs -r docker rm

# Run docker
echo -e "${GRN}Running tests${RST}, HEAD: $(git rev-parse HEAD)"
Expand Down
4 changes: 2 additions & 2 deletions tests-functional/clients/status_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def __init__(self, await_signals=[], privileged=False):
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")

Expand Down

0 comments on commit 8235e29

Please sign in to comment.