Skip to content

Commit

Permalink
Merge pull request #34 from vnsamsonov/main
Browse files Browse the repository at this point in the history
Add cleanup for tests and remove deprecating `--record` option for kubectl
  • Loading branch information
vnsamsonov authored Dec 13, 2023
2 parents 2a47bf1 + 886915f commit 62c098f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
- name: Run integration tests
run: |
chmod +x scripts/run_tests.sh
./scripts/run_tests.sh
./scripts/run_tests.sh --rm
create-release:
name: Create release
Expand Down
1 change: 0 additions & 1 deletion kubedeployer/kubectl.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def apply_manifests(*paths: PathLike, dry_run: bool = False) -> str:
cmd = (
f"kubectl apply"
f" --v={settings.kube_verbosity.value}"
f" --record" # TODO: replace this flag, because it's deprecated
f" --dry-run={dry_run and 'client' or 'none'}"
f" {' '.join(f'-f {str(p)}' for p in paths)}"
)
Expand Down
63 changes: 58 additions & 5 deletions scripts/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,61 @@
#!/bin/sh

docker stop deployer_runner
docker rm deployer_runner
need_cleanup=false

docker build --progress=plain -t deployer -f tests/containers/Dockerfile .
chmod +x tests/containers/integration_tests/integration_entrypoint.sh
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --add-host=host.docker.internal:host-gateway --entrypoint=tests/containers/integration_tests/integration_entrypoint.sh --name=deployer_runner deployer:latest
cleanup() {
if [ "$need_cleanup" = false ]; then
return
fi

container_output_fmt="{{.ID}} ({{.Image}})"

docker ps --format "$container_output_fmt" | while IFS= read -r container_info; do
container_id=$(echo "$container_info" | cut -d ' ' -f 1)
docker stop "$container_id" > /dev/null \
&& echo "Stopping container $container_info"
done

docker ps -a --format "$container_output_fmt" | while IFS= read -r container_info; do
container_id=$(echo "$container_info" | cut -d ' ' -f 1)
docker rm "$container_id" > /dev/null \
&& echo "Removing container $container_info"
done
}

startup() {
while [ "$#" -gt 0 ]
do
case "$1" in
--rm)
need_cleanup=true
shift
;;
--help|*)
echo "Run integration tests locally. Usage:"
echo " --rm"
echo " Automatically stop and remove all containers when tests done"
echo " --help"
echo " Print usage"
exit 1
;;
esac
done

# Stop and remove running containers for escape conflicts
cleanup
}

run() {
docker build --progress=plain -t deployer -f tests/containers/Dockerfile .
chmod +x tests/containers/integration_tests/integration_entrypoint.sh
docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
--add-host=host.docker.internal:host-gateway \
--entrypoint=tests/containers/integration_tests/integration_entrypoint.sh \
--name=deployer_runner deployer:latest
}


startup "$@"
run
cleanup

0 comments on commit 62c098f

Please sign in to comment.