forked from p34709852/monkey
Build: Add cleanup function to build_package
This commit is contained in:
parent
baa2bd1c34
commit
7356b6cc88
|
@ -110,17 +110,11 @@ remove_python_appdir_artifacts() {
|
|||
}
|
||||
|
||||
build_package() {
|
||||
local commit_id=$2
|
||||
local dist_dir=$3
|
||||
local version=$1
|
||||
local dist_dir=$2
|
||||
|
||||
log_message "Building AppImage"
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
local version="v$1"
|
||||
else
|
||||
local version="$commit_id"
|
||||
fi
|
||||
|
||||
pushd "$APPIMAGE_DIR"
|
||||
ARCH="x86_64" linuxdeploy \
|
||||
--appdir "$APPIMAGE_DIR/squashfs-root" \
|
||||
|
@ -139,3 +133,9 @@ build_package() {
|
|||
move_package_to_dist_dir() {
|
||||
mv Infection*Monkey*.AppImage "$1/$2"
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
echo "Cleaning appimage build dirs"
|
||||
|
||||
rm -rf "$APPIMAGE_DIR/squashfs-root"
|
||||
}
|
||||
|
|
|
@ -105,6 +105,17 @@ install_build_prereqs() {
|
|||
install_nodejs
|
||||
}
|
||||
|
||||
format_version() {
|
||||
local unformatted_version=$1
|
||||
local commit_id=$2
|
||||
|
||||
if [ -n "$unformatted_version" ]; then
|
||||
echo "v$monkey_version"
|
||||
else
|
||||
echo "$commit_id"
|
||||
fi
|
||||
}
|
||||
|
||||
agent_binary_dir=""
|
||||
as_root=false
|
||||
branch="develop"
|
||||
|
@ -209,7 +220,11 @@ fi
|
|||
|
||||
setup_build_dir "$agent_binary_dir" "$monkey_repo" "$deployment_type" "$is_release_build"
|
||||
|
||||
build_package "$monkey_version" "$commit_id" "$DIST_DIR"
|
||||
monkey_version=$(format_version "$monkey_version" "$commit_id")
|
||||
|
||||
build_package "$monkey_version" "$DIST_DIR"
|
||||
|
||||
cleanup "$monkey_version"
|
||||
|
||||
log_message "Finished building package: $package"
|
||||
exit 0
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
DOCKER_DIR="$(realpath $(dirname $BASH_SOURCE[0]))"
|
||||
DOCKER_IMAGE_NAME="guardicore/monkey-island"
|
||||
|
||||
source "$DOCKER_DIR/../common.sh"
|
||||
|
||||
|
@ -37,28 +38,18 @@ copy_server_config_to_build_dir() {
|
|||
|
||||
build_package() {
|
||||
local version=$1
|
||||
local commit_id=$2
|
||||
local dist_dir=$3
|
||||
local dist_dir=$2
|
||||
pushd ./docker
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
version="v$version"
|
||||
else
|
||||
version="$commit_id"
|
||||
fi
|
||||
|
||||
docker_image_name="guardicore/monkey-island:$version"
|
||||
tar_name="$DOCKER_DIR/InfectionMonkey-docker-$version.tar"
|
||||
|
||||
build_docker_image_tar "$docker_image_name" "$tar_name"
|
||||
build_docker_image_tar "$DOCKER_IMAGE_NAME:$version" "$tar_name"
|
||||
|
||||
tgz_name="$DOCKER_DIR/InfectionMonkey-docker-$version.tgz"
|
||||
build_docker_image_tgz "$tar_name" "$tgz_name"
|
||||
|
||||
move_package_to_dist_dir $tgz_name $dist_dir
|
||||
|
||||
clean_stale_images "$docker_image_name"
|
||||
|
||||
popd
|
||||
}
|
||||
|
||||
|
@ -78,9 +69,10 @@ move_package_to_dist_dir() {
|
|||
mv "$1" "$2/"
|
||||
}
|
||||
|
||||
clean_stale_images() {
|
||||
echo "Cleaning images"
|
||||
cleanup() {
|
||||
local tag=$1
|
||||
echo "Cleaning docker images"
|
||||
|
||||
sudo docker rmi $1
|
||||
sudo docker rmi "$DOCKER_IMAGE_NAME:$tag"
|
||||
sudo docker image prune --force
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue