Skip to content

Commit

Permalink
Merge branch '2705-agent-build-script' into 2705-upgrade-python-versi…
Browse files Browse the repository at this point in the history
…on-agent

Issue #2705
PR #3007
  • Loading branch information
mssalvatore committed Feb 24, 2023
2 parents 65eb0f5 + 34c5044 commit a728921
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 5 deletions.
1 change: 1 addition & 0 deletions build_scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
agent-dist/
102 changes: 102 additions & 0 deletions build_scripts/build_agent_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#! /bin/bash
#
SCRIPT_NAME="$(basename "$0")"
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)

BRANCH="develop"
LOCAL=false
DIST_DIR="${SCRIPT_DIR}/agent-dist"

die() {
echo "$1" >&2
echo ""
echo_help
exit 1
}

echo_help() {
echo "Builds an Infection Monkey agent for Linux"
echo ""
echo "Usage:"
echo " ${SCRIPT_NAME}"
echo " ${SCRIPT_NAME} --branch <BRANCH>|--local"
echo " ${SCRIPT_NAME} -h|--help"
echo ""
echo "Options:"
echo " --branch Branch to build from. Default: ${BRANCH}"
echo " --local Build from the same repository that contains this script"
}

while (( "$#" )); do
case "$1" in
-h|--help)
echo_help
exit 0
;;
--branch)
BRANCH=$2
shift 2
;;
--local)
LOCAL=true
shift
;;
*)
die "Error: Unsupported parameter \"$1\"."
;;
esac
done

mkdir -p "$DIST_DIR"

setup_environment_commands="
set +x &&
export PYENV_ROOT=\"\${HOME}/.pyenv\" &&
command -v pyenv >/dev/null || export PATH=\"\$PYENV_ROOT/bin:\$PATH\" &&
eval \"\$(pyenv init -)\" &&
python --version &&
pip install pipenv &&
"

clone_commands="
echo \"Cloning branch ${BRANCH}...\" &&
git clone https://github.com/guardicore/monkey.git -b \"${BRANCH}\" --single-branch --depth 1 &&
cd monkey/monkey/infection_monkey &&
"

local_commands="
cd /src/monkey/infection_monkey &&
"

build_commands="
pipenv sync &&
pipenv run bash build_linux.sh &&
echo 'Copying agent binary to \"${DIST_DIR}\"' &&
cp dist/monkey-linux-64 /dist
"

docker_commands=""
if [ "$LOCAL" = true ]; then
echo "Building agent from local source code..."
docker_commands="
${setup_environment_commands}
${local_commands}
${build_commands}
"
else
echo "Building agent from remote branch \"${BRANCH}\"..."
docker_commands="
${setup_environment_commands}
${clone_commands}
${build_commands}
"
fi

TAG="latest"
docker pull infectionmonkey/agent-builder:$TAG
docker run \
--rm \
-v "${DIST_DIR}:/dist" \
-v "${SCRIPT_DIR}/../:/src" \
infectionmonkey/agent-builder:$TAG \
/bin/bash -c "${docker_commands}" | ts '[%Y-%m-%d %H:%M:%S]'
2 changes: 1 addition & 1 deletion monkey/infection_monkey/build_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ then
fi
fi

pyinstaller --log-level=DEBUG --clean monkey.spec
pyinstaller --log-level=DEBUG --clean monkey.spec 2>&1
8 changes: 4 additions & 4 deletions monkey/infection_monkey/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ Tested on Ubuntu 16.04.
- `python3.7 -m pip install -r requirements.txt`

1. To build, run in terminal:
- `cd [code location]/infection_monkey`
- `chmod +x build_linux.sh`
- `pipenv run ./build_linux.sh`
- `cd [code location]/build_scripts`
- `chmod +x build_agent_linux.sh`
- `./build_agent_linux.sh`

Output is placed under `dist/monkey64`.
Output is placed under `build_scripts/agent-dist/monkey64`.

### Troubleshooting

Expand Down

0 comments on commit a728921

Please sign in to comment.