From 6aff4a16b263a635f0f32ac4d976b696db01bbf5 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 28 Jul 2021 07:53:33 -0400 Subject: [PATCH] Build: Move final build artifact to dist/ directory --- build_scripts/README.md | 5 +++-- build_scripts/appimage/appimage.sh | 10 +++++++++- build_scripts/build_package.sh | 8 +++++++- build_scripts/docker/docker.sh | 7 +++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/build_scripts/README.md b/build_scripts/README.md index f5009e498..e08b7ea86 100644 --- a/build_scripts/README.md +++ b/build_scripts/README.md @@ -22,7 +22,7 @@ remove build artifacts by running `appimage/clean.sh` ### Running the AppImage The build script will produce an AppImage executable named -`Infection_Monkey-x86_64.AppImage`. Simply execute this file and you're off to +`./dist/Infection_Monkey-x86_64.AppImage`. Simply execute this file and you're off to the races. A new directory, `$HOME/.monkey_island` will be created to store runtime @@ -42,4 +42,5 @@ NOTE: This script is intended to be run from a clean VM. You can also manually remove build artifacts by running `docker/clean.sh` ### Running the Docker Image -See `docker/DOCKER_README.md` for instructions on running the docker image. +The build script will produce a `.tgz` file in `./dist/`. See +`docker/DOCKER_README.md` for instructions on running the docker image. diff --git a/build_scripts/appimage/appimage.sh b/build_scripts/appimage/appimage.sh index eb4bee130..c1cf3b922 100755 --- a/build_scripts/appimage/appimage.sh +++ b/build_scripts/appimage/appimage.sh @@ -122,11 +122,15 @@ add_apprun() { } build_package() { + local version=$1 + local dist_dir=$2 log_message "Building AppImage" pushd "$APPIMAGE_DIR" ARCH="x86_64" appimagetool "$APPIMAGE_DIR/squashfs-root" - apply_version_to_appimage "$1" + apply_version_to_appimage "$version" + + move_package_to_dist_dir $dist_dir popd } @@ -135,3 +139,7 @@ apply_version_to_appimage() { log_message "Renaming Infection_Monkey-x86_64.AppImage -> Infection_Monkey-$1-x86_64.AppImage" mv "Infection_Monkey-x86_64.AppImage" "Infection_Monkey-$1-x86_64.AppImage" } + +move_package_to_dist_dir() { + mv Infection_Monkey*.AppImage "$1/" +} diff --git a/build_scripts/build_package.sh b/build_scripts/build_package.sh index ee466d68c..957c43e1a 100755 --- a/build_scripts/build_package.sh +++ b/build_scripts/build_package.sh @@ -2,6 +2,8 @@ WORKSPACE=${WORKSPACE:-$HOME} DEFAULT_REPO_MONKEY_HOME=$WORKSPACE/git/monkey MONKEY_ORIGIN_URL="https://github.com/guardicore/monkey.git" NODE_SRC=https://deb.nodesource.com/setup_12.x +BUILD_SCRIPTS_DIR="$(realpath $(dirname $BASH_SOURCE[0]))" +DIST_DIR="$BUILD_SCRIPTS_DIR/dist" log_message() { echo -e "\n\n" @@ -187,12 +189,16 @@ if ! is_valid_git_repo "$monkey_repo"; then clone_monkey_repo "$monkey_repo" "$branch" fi +if [ ! -d "$DIST_DIR" ]; then + mkdir "$DIST_DIR" +fi + install_build_prereqs install_package_specific_build_prereqs "$WORKSPACE" setup_build_dir "$agent_binary_dir" "$monkey_repo" -build_package "$monkey_version" +build_package "$monkey_version" "$DIST_DIR" log_message "Finished building package: $package" exit 0 diff --git a/build_scripts/docker/docker.sh b/build_scripts/docker/docker.sh index 7e7c9ae91..bf7e78cee 100755 --- a/build_scripts/docker/docker.sh +++ b/build_scripts/docker/docker.sh @@ -36,6 +36,7 @@ copy_server_config_to_build_dir() { build_package() { local version=$1 + local dist_dir=$2 pushd ./docker docker_image_name="guardicore/monkey-island:$version" @@ -44,6 +45,8 @@ build_package() { build_docker_image_tar "$docker_image_name" "$tar_name" build_docker_image_tgz "$tar_name" "$version" + move_package_to_dist_dir $dist_dir + popd } @@ -58,3 +61,7 @@ build_docker_image_tgz() { cp ./DOCKER_README.md ./tgz/README.md tar -C ./tgz -cvf "$OUTPUT_NAME_TGZ" --gzip . } + +move_package_to_dist_dir() { + mv $OUTPUT_NAME_TGZ "$1/" +}