jenkins-pipelines/scripts/stop-containers.sh
Davlet Panech 90992db422 Clean up minikube at end of build
stop-containers: when using minikube run "docker system prune" in
minikube's docker, then stop minikube's container. This prevents host
docker's file system from getting filled up with temp FS layers created
by minikube's inner docker (due to building stx-tools builder
containers, mostly).

TESTS
====================
* Manually confirm disk space is indeed freed using this sequence
* Note current disk usage, then run start-containers, followed by
  stop-containers, check jenkins log, then verify disk space has
  decreased on host at the end
* run stop-containers while minikube is stopped; make sure "docker
  system prune" etc is skipped in this case
* run stop-containers with true k8s (not minikube); make sure the new
  steps are skipped

Story: 2010226
Task: 47756

Change-Id: I73ce5b94f575bc5c0467c37ef70453f03cb05e69
Signed-off-by: Davlet Panech <davlet.panech@windriver.com>
2023-03-30 15:03:21 -04:00

34 lines
845 B
Bash
Executable File

#!/bin/bash
#
# Copyright (c) 2022 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
set -e
source $(dirname "$0")/lib/job_utils.sh
require_job_env BUILD_HOME
load_build_config
if [[ ! -f "$BUILD_HOME/$REPO_ROOT_SUBDIR/stx-tools/import-stx" ]] ; then
warn "$BUILD_HOME/$REPO_ROOT_SUBDIR/stx-tools/import-stx: file doesn't exist"
warn "Can't stop containers, bailing out"
exit 0
fi
load_build_env
stx control stop || true
# Prune minikube's docker, then stop minikube's top-level container
if [[ "$STX_PLATFORM" == "minikube" ]] ; then
profile_args=()
[[ -z "$MINIKUBENAME" ]] || profile_args+=("-p" "$MINIKUBENAME")
if minikube "${profile_args[@]}" status >/dev/null ; then
minikube "${profile_args[@]}" ssh -- 'docker system prune -f'
minikube "${profile_args[@]}" stop
fi
fi