forked from p15670423/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() {
|
build_package() {
|
||||||
local commit_id=$2
|
local version=$1
|
||||||
local dist_dir=$3
|
local dist_dir=$2
|
||||||
|
|
||||||
log_message "Building AppImage"
|
log_message "Building AppImage"
|
||||||
|
|
||||||
if [ -n "$1" ]; then
|
|
||||||
local version="v$1"
|
|
||||||
else
|
|
||||||
local version="$commit_id"
|
|
||||||
fi
|
|
||||||
|
|
||||||
pushd "$APPIMAGE_DIR"
|
pushd "$APPIMAGE_DIR"
|
||||||
ARCH="x86_64" linuxdeploy \
|
ARCH="x86_64" linuxdeploy \
|
||||||
--appdir "$APPIMAGE_DIR/squashfs-root" \
|
--appdir "$APPIMAGE_DIR/squashfs-root" \
|
||||||
|
@ -139,3 +133,9 @@ build_package() {
|
||||||
move_package_to_dist_dir() {
|
move_package_to_dist_dir() {
|
||||||
mv Infection*Monkey*.AppImage "$1/$2"
|
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
|
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=""
|
agent_binary_dir=""
|
||||||
as_root=false
|
as_root=false
|
||||||
branch="develop"
|
branch="develop"
|
||||||
|
@ -209,7 +220,11 @@ fi
|
||||||
|
|
||||||
setup_build_dir "$agent_binary_dir" "$monkey_repo" "$deployment_type" "$is_release_build"
|
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"
|
log_message "Finished building package: $package"
|
||||||
exit 0
|
exit 0
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
DOCKER_DIR="$(realpath $(dirname $BASH_SOURCE[0]))"
|
DOCKER_DIR="$(realpath $(dirname $BASH_SOURCE[0]))"
|
||||||
|
DOCKER_IMAGE_NAME="guardicore/monkey-island"
|
||||||
|
|
||||||
source "$DOCKER_DIR/../common.sh"
|
source "$DOCKER_DIR/../common.sh"
|
||||||
|
|
||||||
|
@ -37,28 +38,18 @@ copy_server_config_to_build_dir() {
|
||||||
|
|
||||||
build_package() {
|
build_package() {
|
||||||
local version=$1
|
local version=$1
|
||||||
local commit_id=$2
|
local dist_dir=$2
|
||||||
local dist_dir=$3
|
|
||||||
pushd ./docker
|
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"
|
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"
|
tgz_name="$DOCKER_DIR/InfectionMonkey-docker-$version.tgz"
|
||||||
build_docker_image_tgz "$tar_name" "$tgz_name"
|
build_docker_image_tgz "$tar_name" "$tgz_name"
|
||||||
|
|
||||||
move_package_to_dist_dir $tgz_name $dist_dir
|
move_package_to_dist_dir $tgz_name $dist_dir
|
||||||
|
|
||||||
clean_stale_images "$docker_image_name"
|
|
||||||
|
|
||||||
popd
|
popd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,9 +69,10 @@ move_package_to_dist_dir() {
|
||||||
mv "$1" "$2/"
|
mv "$1" "$2/"
|
||||||
}
|
}
|
||||||
|
|
||||||
clean_stale_images() {
|
cleanup() {
|
||||||
echo "Cleaning images"
|
local tag=$1
|
||||||
|
echo "Cleaning docker images"
|
||||||
|
|
||||||
sudo docker rmi $1
|
sudo docker rmi "$DOCKER_IMAGE_NAME:$tag"
|
||||||
sudo docker image prune --force
|
sudo docker image prune --force
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue