2021-07-28 01:08:55 +08:00
|
|
|
DOCKER_DIR="$(realpath $(dirname $BASH_SOURCE[0]))"
|
2022-06-03 19:10:47 +08:00
|
|
|
DOCKER_IMAGE_NAME="guardicore/monkey-island"
|
2021-07-28 01:08:55 +08:00
|
|
|
|
|
|
|
source "$DOCKER_DIR/../common.sh"
|
|
|
|
|
|
|
|
install_package_specific_build_prereqs() {
|
|
|
|
sudo apt-get install -y docker.io
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_build_dir() {
|
|
|
|
local agent_binary_dir=$1
|
|
|
|
local monkey_repo=$2
|
2022-04-12 20:43:15 +08:00
|
|
|
local is_release_build=$4
|
2021-07-28 01:08:55 +08:00
|
|
|
local build_dir=$DOCKER_DIR/monkey
|
|
|
|
|
|
|
|
mkdir "$build_dir"
|
|
|
|
|
|
|
|
copy_entrypoint_to_build_dir "$build_dir"
|
|
|
|
|
|
|
|
copy_monkey_island_to_build_dir "$monkey_repo/monkey" "$build_dir"
|
|
|
|
copy_server_config_to_build_dir "$build_dir"
|
2021-09-15 20:13:26 +08:00
|
|
|
modify_deployment "$deployment_type" "$build_dir"
|
2021-07-28 01:08:55 +08:00
|
|
|
add_agent_binaries_to_build_dir "$agent_binary_dir" "$build_dir"
|
|
|
|
|
|
|
|
generate_ssl_cert "$build_dir"
|
|
|
|
|
2022-04-12 20:43:15 +08:00
|
|
|
build_frontend "$build_dir" "$is_release_build"
|
2021-07-28 01:08:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
copy_entrypoint_to_build_dir() {
|
|
|
|
cp "$DOCKER_DIR"/entrypoint.sh "$1"
|
|
|
|
chmod 755 "$1/entrypoint.sh"
|
|
|
|
}
|
|
|
|
|
|
|
|
copy_server_config_to_build_dir() {
|
|
|
|
cp "$DOCKER_DIR"/server_config.json "$1"/monkey_island/cc
|
|
|
|
}
|
|
|
|
|
|
|
|
build_package() {
|
|
|
|
local version=$1
|
2022-06-03 19:10:47 +08:00
|
|
|
local dist_dir=$2
|
2021-07-28 01:08:55 +08:00
|
|
|
pushd ./docker
|
|
|
|
|
2021-10-18 22:45:14 +08:00
|
|
|
tar_name="$DOCKER_DIR/InfectionMonkey-docker-$version.tar"
|
2021-07-28 01:08:55 +08:00
|
|
|
|
2022-06-03 19:10:47 +08:00
|
|
|
build_docker_image_tar "$DOCKER_IMAGE_NAME:$version" "$tar_name"
|
2021-07-28 01:08:55 +08:00
|
|
|
|
2021-10-18 22:45:14 +08:00
|
|
|
tgz_name="$DOCKER_DIR/InfectionMonkey-docker-$version.tgz"
|
2021-10-18 21:06:04 +08:00
|
|
|
build_docker_image_tgz "$tar_name" "$tgz_name"
|
|
|
|
|
|
|
|
move_package_to_dist_dir $tgz_name $dist_dir
|
2021-07-28 19:53:33 +08:00
|
|
|
|
2021-07-28 01:08:55 +08:00
|
|
|
popd
|
|
|
|
}
|
|
|
|
|
|
|
|
build_docker_image_tar() {
|
|
|
|
sudo docker build . -t "$1"
|
|
|
|
sudo docker save "$1" > "$2"
|
|
|
|
}
|
|
|
|
|
|
|
|
build_docker_image_tgz() {
|
|
|
|
mkdir tgz
|
|
|
|
mv "$1" ./tgz
|
|
|
|
cp ./DOCKER_README.md ./tgz/README.md
|
2021-10-18 21:06:04 +08:00
|
|
|
tar -C ./tgz -cvf "$2" --gzip .
|
2021-07-28 01:08:55 +08:00
|
|
|
}
|
2021-07-28 19:53:33 +08:00
|
|
|
|
|
|
|
move_package_to_dist_dir() {
|
2021-10-18 21:06:04 +08:00
|
|
|
mv "$1" "$2/"
|
2021-07-28 19:53:33 +08:00
|
|
|
}
|
2022-06-03 18:23:03 +08:00
|
|
|
|
2022-06-03 19:10:47 +08:00
|
|
|
cleanup() {
|
|
|
|
local tag=$1
|
|
|
|
echo "Cleaning docker images"
|
2022-06-03 18:23:03 +08:00
|
|
|
|
2022-06-03 19:10:47 +08:00
|
|
|
sudo docker rmi "$DOCKER_IMAGE_NAME:$tag"
|
2022-06-03 18:23:03 +08:00
|
|
|
sudo docker image prune --force
|
|
|
|
}
|