Sha256: a521537676f6598b91cdf2fdab00c6857ce1c7919bf1f0f60868735cf05e65e0

Contents?: true

Size: 1.91 KB

Versions: 28

Compression:

Stored size: 1.91 KB

Contents

#!/usr/bin/env bash
#
# Shared cleanup routines between different steps
#
# Please source .ci/functions/imports.sh as a whole not just this file
#
# Version 1.0.0
# - Initial version after refactor

function cleanup_volume {
  if [[ "$(docker volume ls -q -f name=$1)" ]]; then
    echo -e "\033[34;1mINFO:\033[0m Removing volume $1\033[0m"
    (docker volume rm "$1") || true
  fi
}
function container_running {
  if [[ "$(docker ps -q -f name=$1)" ]]; then
    return 0;
    else return 1;
  fi
}
function cleanup_node {
  if container_running "$1"; then
    echo -e "\033[34;1mINFO:\033[0m Removing container $1\033[0m"
    (docker container rm --force --volumes "$1") || true
  fi
  if [[ -n "$1" ]]; then
    echo -e "\033[34;1mINFO:\033[0m Removing volume $1-${suffix}-data\033[0m"
    cleanup_volume "$1-${suffix}-data"
  fi
}
function cleanup_network {
  if [[ "$(docker network ls -q -f name=$1)" ]]; then
    echo -e "\033[34;1mINFO:\033[0m Removing network $1\033[0m"
    (docker network rm "$1") || true
  fi
}

function cleanup_trap {
  status=$?
  set +x
  if [[ "$DETACH" != "true" ]]; then
    echo -e "\033[34;1mINFO:\033[0m clean the network if not detached (start and exit)\033[0m"
    cleanup_all_in_network "$1"
  fi
  # status is 0 or SIGINT
  if [[ "$status" == "0" || "$status" == "130" ]]; then
    echo -e "\n\033[32;1mSUCCESS run-tests\033[0m"
    exit 0
  else
    echo -e "\n\033[31;1mFAILURE during run-tests\033[0m"
    exit ${status}
  fi
};
function cleanup_all_in_network {

  if [[ -z "$(docker network ls -q -f name="^$1\$")" ]]; then
    echo -e "\033[34;1mINFO:\033[0m $1 is already deleted\033[0m"
    return 0
  fi
  containers=$(docker network inspect -f '{{ range $key, $value := .Containers }}{{ printf "%s\n" .Name}}{{ end }}' $1)
  while read -r container; do
    cleanup_node "$container"
  done <<< "$containers"
  cleanup_network $1
  echo -e "\033[32;1mSUCCESS:\033[0m Cleaned up and exiting\033[0m"
};

Version data entries

28 entries across 27 versions & 1 rubygems

Version Path
elastic-enterprise-search-8.9.0 .buildkite/functions/cleanup.sh
elastic-enterprise-search-8.8.0 .buildkite/functions/cleanup.sh
elastic-enterprise-search-8.7.0 .buildkite/functions/cleanup.sh
elastic-enterprise-search-8.6.0 .ci/functions/cleanup.sh
elastic-enterprise-search-8.6.0 .buildkite/functions/cleanup.sh
elastic-enterprise-search-8.5.0 .ci/functions/cleanup.sh
elastic-enterprise-search-7.17.1 .ci/functions/cleanup.sh
elastic-enterprise-search-8.4.0 .ci/functions/cleanup.sh
elastic-enterprise-search-8.3.0 .ci/functions/cleanup.sh
elastic-enterprise-search-8.2.1 .ci/functions/cleanup.sh
elastic-enterprise-search-8.1.1 .ci/functions/cleanup.sh
elastic-enterprise-search-8.0.1 .ci/functions/cleanup.sh
elastic-enterprise-search-8.2.0 .ci/functions/cleanup.sh
elastic-enterprise-search-8.1.0 .ci/functions/cleanup.sh
elastic-enterprise-search-8.0.0 .ci/functions/cleanup.sh
elastic-enterprise-search-8.0.0.pre .ci/functions/cleanup.sh
elastic-enterprise-search-7.17.0 .ci/functions/cleanup.sh
elastic-enterprise-search-7.16.0 .ci/functions/cleanup.sh
elastic-enterprise-search-7.15.1 .ci/functions/cleanup.sh
elastic-enterprise-search-7.14.1 .ci/functions/cleanup.sh