8000 Added the prune of docker images when uninstall by ezimuel · Pull Request #59 · elastic/start-local · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Added the prune of docker images when uninstall #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions start-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ parse_args() {
shift 2
;;

-esonly)
--esonly)
esonly=true
shift
;;
Expand Down Expand Up @@ -77,7 +77,7 @@ startup() {
echo

# Version
version="0.9.0"
version="0.9.1"

# Folder name for the installation
installation_folder="elastic-start-local"
Expand Down Expand Up @@ -599,7 +599,7 @@ set -eu
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"

ask_confirmation() {
echo "Do you want to continue? (yes/no)"
echo "Do you confirm? (yes/no)"
read -r answer
case "$answer" in
yes|y|Y|Yes|YES)
Expand Down Expand Up @@ -636,6 +636,38 @@ EOM
if [ -z "\$(ls -A config)" ]; then
rm -d config
fi
echo
echo "Do you want to remove the following Docker images?"
echo "- docker.elastic.co/elasticsearch/elasticsearch:${es_version}"
EOM

if [ -z "${esonly:-}" ]; then
cat >> uninstall.sh <<- EOM
echo "- docker.elastic.co/kibana/kibana:${es_version}"
EOM
fi

cat >> uninstall.sh <<- EOM
if ask_confirmation; then
if docker rmi "docker.elastic.co/elasticsearch/elasticsearch:${es_version}" >/dev/null 2>&1; then
echo "Image docker.elastic.co/elasticsearch/elasticsearch:${es_version} removed successfully"
else
echo "Failed to remove image docker.elastic.co/elasticsearch/elasticsearch:${es_version}. It might be in use."
fi
EOM

if [ -z "${esonly:-}" ]; then
cat >> uninstall.sh <<- EOM
if docker rmi docker.elastic.co/kibana/kibana:${es_version} >/dev/null 2>&1; then
echo "Image docker.elastic.co/kibana/kibana:${es_version} removed successfully"
else
echo "Failed to remove image docker.elastic.co/kibana/kibana:${es_version}. It might be in use."
fi
EOM
fi

cat >> uninstall.sh <<- EOM
fi
echo "Start-local successfully removed"
fi
EOM
Expand Down
4 changes: 2 additions & 2 deletions tests/basic_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ UNINSTALL_FILE="${DEFAULT_DIR}/uninstall.sh"
source "${CURRENT_DIR}/tests/utility.sh"

function set_up_before_script() {
sh "start-local.sh"
sh "${CURRENT_DIR}/start-local.sh"
# shellcheck disable=SC1090
source "${ENV_PATH}"
}

function tear_down_after_script() {
yes | "${DEFAULT_DIR}/uninstall.sh"
printf "yes\nno\n" | "${DEFAULT_DIR}/uninstall.sh"
rm -rf "${DEFAULT_DIR}"
}

Expand Down
4 changes: 2 additions & 2 deletions tests/expire_license_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ ENV_PATH="${DEFAULT_DIR}/.env"
source "${CURRENT_DIR}/tests/utility.sh"

function set_up_before_script() {
sh "start-local.sh"
sh "${CURRENT_DIR}/start-local.sh"
# shellcheck disable=SC1090
source "${ENV_PATH}"
}

function tear_down_after_script() {
yes | "${DEFAULT_DIR}/uninstall.sh"
printf "yes\nno\n" | "${DEFAULT_DIR}/uninstall.sh"
rm -rf "${DEFAULT_DIR}"
}

Expand Down
4 changes: 2 additions & 2 deletions tests/install_esonly_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ UNINSTALL_FILE="${DEFAULT_DIR}/uninstall.sh"
source "${CURRENT_DIR}/tests/utility.sh"

function set_up_before_script() {
sh "start-local.sh" "-esonly"
sh "${CURRENT_DIR}/start-local.sh" "-esonly"
# shellcheck disable=SC1090
source "${ENV_PATH}"
}

function tear_down_after_script() {
yes | "${UNINSTALL_FILE}"
printf "yes\nno\n" | "${UNINSTALL_FILE}"
rm -rf "${DEFAULT_DIR}"
}

Expand Down
2 changes: 1 addition & 1 deletion tests/install_from_curl_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function set_up_before_script() {
}

function tear_down_after_script() {
yes | "${DEFAULT_DIR}/uninstall.sh"
printf "yes\nno\n" | "${DEFAULT_DIR}/uninstall.sh"
rm -rf "${DEFAULT_DIR}"
kill -9 "$PHP_SERVER_PID"
wait "$PHP_SERVER_PID" 2>/dev/null
Expand Down
4 changes: 2 additions & 2 deletions tests/install_with_version_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ ES_VERSION="8.17.0"
source "${CURRENT_DIR}/tests/utility.sh"

function set_up_before_script() {
sh "start-local.sh" "-v" "${ES_VERSION}"
sh "${CURRENT_DIR}/start-local.sh" "-v" "${ES_VERSION}"
# shellcheck disable=SC1090
source "${ENV_PATH}"
}

function tear_down_after_script() {
yes | "${UNINSTALL_FILE}"
printf "yes\nno\n" | "${UNINSTALL_FILE}"
rm -rf "${DEFAULT_DIR}"
}

Expand Down
4 changes: 2 additions & 2 deletions tests/start_stop_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ UNINSTALL_FILE="${DEFAULT_DIR}/uninstall.sh"
source "${CURRENT_DIR}/tests/utility.sh"

function set_up_before_script() {
sh "start-local.sh"
sh "${CURRENT_DIR}/start-local.sh"
# shellcheck disable=SC1090
source "${ENV_PATH}"
}

function tear_down_after_script() {
yes | "${UNINSTALL_FILE}"
printf "yes\nno\n" | "${UNINSTALL_FILE}"
rm -rf "${DEFAULT_DIR}"
}

Expand Down
21 changes: 18 additions & 3 deletions tests/uninstall_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ UNINSTALL_FILE="${DEFAULT_DIR}/uninstall.sh"
source "${CURRENT_DIR}/tests/utility.sh"

function set_up() {
sh "start-local.sh"
sh "${CURRENT_DIR}/start-local.sh"
# shellcheck disable=SC1090
source "${ENV_PATH}"
}
Expand All @@ -35,18 +35,33 @@ function tear_down() {
}

function test_uninstall_outside_installation_folder() {
yes | "${UNINSTALL_FILE}"
printf "yes\nno\n" | "${UNINSTALL_FILE}"
assert_exit_code "1" "$(check_docker_service_running es-local-dev)"
assert_exit_code "1" "$(check_docker_service_running kibana-local-dev)"
assert_exit_code "1" "$(check_docker_service_running kibana_settings)"
assert_is_directory_empty "${TEST_DIR}/${DEFAULT_DIR}"
assert_exit_code "0" "$(check_docker_image_exists docker.elastic.co/elasticsearch/elasticsearch:"${ES_LOCAL_VERSION}")"
assert_exit_code "0" "$(check_docker_image_exists docker.elastic.co/kibana/kibana:"${ES_LOCAL_VERSION}")"
}

function test_uninstall_in_installation_folder() {
cd "${DEFAULT_DIR}" || exit
yes | ./uninstall.sh
printf "yes\nno\n" | ./uninstall.sh
assert_exit_code "1" "$(check_docker_service_running es-local-dev)"
assert_exit_code "1" "$(check_docker_service_running kibana-local-dev)"
assert_exit_code "1" "$(check_docker_service_running kibana_settings)"
assert_is_directory_empty "${DEFAULT_DIR}"
assert_exit_code "0" "$(check_docker_image_exists docker.elastic.co/elasticsearch/elasticsearch:"${ES_LOCAL_VERSION}")"
assert_exit_code "0" "$(check_docker_image_exists docker.elastic.co/kibana/kibana:"${ES_LOCAL_VERSION}")"
}

function test_uninstall_remove_images() {
cd "${DEFAULT_DIR}" || exit
printf "yes\nyes\n" | ./uninstall.sh
assert_exit_code "1" "$(check_docker_service_running es-local-dev)"
assert_exit_code "1" "$(check_docker_service_running kibana-local-dev)"
assert_exit_code "1" "$(check_docker_service_running kibana_settings)"
assert_is_directory_empty "${DEFAULT_DIR}"
assert_exit_code "1" "$(check_docker_image_exists docker.elastic.co/elasticsearch/elasticsearch:"${ES_LOCAL_VERSION}")"
assert_exit_code "1" "$(check_docker_image_exists docker.elastic.co/kibana/kibana:"${ES_LOCAL_VERSION}")"
}
10 changes: 10 additions & 0 deletions tests/utility.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,14 @@ check_docker_service_running() {
else
return 1 # false
fi
}

# Check if a docker image exists
check_docker_image_exists() {
local image_name=$1
if docker image inspect "$image_name" > /dev/null 2>&1; then
return 0 # true
else
return 1 # false
fi
}
Loading
0