From b8a5245c1b19582db5eea9173643297ca154220f Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 9 Jun 2022 11:15:07 -0400 Subject: [PATCH 1/6] Build: Use `pipenv sync --system` instead of requirements.txt When pipenv dumps the lock file to a requirements.txt, it does not include the `sys_platform` directive. This causes pip to attempt to install win32 packages, which fails. By using `pypenv sync --system` instead, only packages applicable to Linux are installed. Fixes #1993 --- build_scripts/appimage/appimage.sh | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/build_scripts/appimage/appimage.sh b/build_scripts/appimage/appimage.sh index 3602b46a1..60179164d 100755 --- a/build_scripts/appimage/appimage.sh +++ b/build_scripts/appimage/appimage.sh @@ -79,20 +79,10 @@ install_monkey_island_python_dependencies() { log_message "Installing pipenv" "$APPDIR"/AppRun -m pip install pipenv || handle_error - requirements_island="$BUILD_DIR/monkey_island/requirements.txt" - generate_requirements_from_pipenv_lock "$requirements_island" - - log_message "Installing island python requirements" - "$APPDIR"/AppRun -m pip install -r "${requirements_island}" --ignore-installed || handle_error -} - -generate_requirements_from_pipenv_lock () { - local requirements_island=$1 - - log_message "Generating a requirements.txt file with 'pipenv requirements'" - pushd "$BUILD_DIR/monkey_island" - "$APPDIR"/AppRun -m pipenv --python "$APPDIR/AppRun" requirements --hash > "$requirements_island" || handle_error - popd + log_message "Installing dependencies" + pushd "$BUILD_DIR/monkey_island" || handle_error + "$APPDIR"/AppRun -m pipenv --python "$APPDIR/AppRun" sync --system || handle_error + popd || handle_error } From f7ad99f5921244c79028f85edf3d145eb9d9a93e Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 9 Jun 2022 11:18:18 -0400 Subject: [PATCH 2/6] Build: Handle errors if pushd or popd fail --- build_scripts/appimage/appimage.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build_scripts/appimage/appimage.sh b/build_scripts/appimage/appimage.sh index 60179164d..2928b2d64 100755 --- a/build_scripts/appimage/appimage.sh +++ b/build_scripts/appimage/appimage.sh @@ -30,7 +30,7 @@ setup_build_dir() { local deployment_type=$3 local is_release_build=$4 - pushd $APPIMAGE_DIR + pushd $APPIMAGE_DIR || handle_error setup_python_37_appdir @@ -50,7 +50,7 @@ setup_build_dir() { remove_python_appdir_artifacts - popd + popd || handle_error } setup_python_37_appdir() { @@ -105,7 +105,7 @@ build_package() { log_message "Building AppImage" - pushd "$APPIMAGE_DIR" + pushd "$APPIMAGE_DIR" || handle_error ARCH="x86_64" linuxdeploy \ --appdir "$APPIMAGE_DIR/squashfs-root" \ --icon-file "$ICON_PATH" \ @@ -117,7 +117,7 @@ build_package() { dst_name="InfectionMonkey-$version.AppImage" move_package_to_dist_dir $dist_dir $dst_name - popd + popd || handle_error } move_package_to_dist_dir() { From 1b6856b0c20105c1d8c66dd4cc5a89a1a151ca0c Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 9 Jun 2022 11:22:37 -0400 Subject: [PATCH 3/6] Build: Double quote variables to prevent splitting --- build_scripts/appimage/appimage.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build_scripts/appimage/appimage.sh b/build_scripts/appimage/appimage.sh index 2928b2d64..d61e11fb7 100755 --- a/build_scripts/appimage/appimage.sh +++ b/build_scripts/appimage/appimage.sh @@ -3,7 +3,7 @@ LINUXDEPLOY_URL="https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage" PYTHON_VERSION="3.7.13" PYTHON_APPIMAGE_URL="https://github.com/niess/python-appimage/releases/download/python3.7/python${PYTHON_VERSION}-cp37-cp37m-manylinux1_x86_64.AppImage" -APPIMAGE_DIR="$(realpath $(dirname $BASH_SOURCE[0]))" +APPIMAGE_DIR=$(realpath "$(dirname "$BASH_SOURCE[0]")") APPDIR="$APPIMAGE_DIR/squashfs-root" BUILD_DIR="$APPDIR/usr/src" @@ -30,7 +30,7 @@ setup_build_dir() { local deployment_type=$3 local is_release_build=$4 - pushd $APPIMAGE_DIR || handle_error + pushd "$APPIMAGE_DIR" || handle_error setup_python_37_appdir @@ -115,7 +115,7 @@ build_package() { --output appimage dst_name="InfectionMonkey-$version.AppImage" - move_package_to_dist_dir $dist_dir $dst_name + move_package_to_dist_dir "$dist_dir" "$dst_name" popd || handle_error } From cd1d7b28a87fe60362438516f06a84ecd1c91a6a Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 9 Jun 2022 11:25:25 -0400 Subject: [PATCH 4/6] Build: Use braces to expand array --- build_scripts/appimage/appimage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_scripts/appimage/appimage.sh b/build_scripts/appimage/appimage.sh index d61e11fb7..388bc9bcb 100755 --- a/build_scripts/appimage/appimage.sh +++ b/build_scripts/appimage/appimage.sh @@ -3,7 +3,7 @@ LINUXDEPLOY_URL="https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage" PYTHON_VERSION="3.7.13" PYTHON_APPIMAGE_URL="https://github.com/niess/python-appimage/releases/download/python3.7/python${PYTHON_VERSION}-cp37-cp37m-manylinux1_x86_64.AppImage" -APPIMAGE_DIR=$(realpath "$(dirname "$BASH_SOURCE[0]")") +APPIMAGE_DIR=$(realpath "$(dirname "${BASH_SOURCE[0]}")") APPDIR="$APPIMAGE_DIR/squashfs-root" BUILD_DIR="$APPDIR/usr/src" From 73d20a6a6afaca43c6a2d18de286bfa861a42172 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 9 Jun 2022 11:27:41 -0400 Subject: [PATCH 5/6] Build: Uninstall pipenv from AppImage after dependencies are installed --- build_scripts/appimage/appimage.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build_scripts/appimage/appimage.sh b/build_scripts/appimage/appimage.sh index 388bc9bcb..ce926586d 100755 --- a/build_scripts/appimage/appimage.sh +++ b/build_scripts/appimage/appimage.sh @@ -83,6 +83,9 @@ install_monkey_island_python_dependencies() { pushd "$BUILD_DIR/monkey_island" || handle_error "$APPDIR"/AppRun -m pipenv --python "$APPDIR/AppRun" sync --system || handle_error popd || handle_error + + log_message "Uninstalling pipenv (build dependency only)" + "$APPDIR"/AppRun -m pip uninstall pipenv virtualenv || handle_error } From cacd064893b15662f49119065a137b6a5ced6f90 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 9 Jun 2022 11:35:25 -0400 Subject: [PATCH 6/6] Build: Uninstall pipenv and virtualenv after dependencies are installed This reduces the size of the AppImage by 7.4% --- build_scripts/appimage/appimage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_scripts/appimage/appimage.sh b/build_scripts/appimage/appimage.sh index ce926586d..a7415593c 100755 --- a/build_scripts/appimage/appimage.sh +++ b/build_scripts/appimage/appimage.sh @@ -85,7 +85,7 @@ install_monkey_island_python_dependencies() { popd || handle_error log_message "Uninstalling pipenv (build dependency only)" - "$APPDIR"/AppRun -m pip uninstall pipenv virtualenv || handle_error + "$APPDIR"/AppRun -m pip uninstall --yes pipenv virtualenv || handle_error }