Skip to content

Commit

Permalink
Merge branch '2705-upgrade-island-python-version' into develop
Browse files Browse the repository at this point in the history
Issue #2705
PR #3019
  • Loading branch information
mssalvatore committed Mar 1, 2023
2 parents 21e69ba + 19feb36 commit ede800d
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 280 deletions.
9 changes: 2 additions & 7 deletions build_scripts/appimage/AppRun
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ self="$(readlink -f -- $0)"
here="${self%/*}"
APPDIR="${APPDIR:-${here}}"

# Export TCl/Tk
export TCL_LIBRARY="${APPDIR}/usr/share/tcltk/tcl8.4"
export TK_LIBRARY="${APPDIR}/usr/share/tcltk/tk8.4"
export TKPATH="${TK_LIBRARY}"

# Export SSL certificate
export SSL_CERT_FILE="${APPDIR}/opt/_internal/certs.pem"

Expand All @@ -24,12 +19,12 @@ do
if [[ "${opt}" =~ "I" ]] || [[ "${opt}" =~ "E" ]]; then
# Environment variables are disabled ($PYTHONHOME). Let's run in a safe
# mode from the raw Python binary inside the AppImage
"$APPDIR/opt/python3.7/bin/python3.7" "$@"
"$APPDIR/opt/python3.11/bin/python3.11" "$@"
exit "$?"
fi
done

export PYTHONNOUSERSITE=1
(PYTHONHOME="${APPDIR}/opt/python3.7" exec "${APPDIR}/opt/python3.7/bin/python3.7" "${APPDIR}/usr/src/monkey_island.py" $@)
(PYTHONHOME="${APPDIR}/opt/python3.11" exec "${APPDIR}/opt/python3.11/bin/python3.11" "${APPDIR}/usr/src/monkey_island.py" $@)

exit "$?"
17 changes: 10 additions & 7 deletions build_scripts/appimage/appimage.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/bash

# Changes: python version
LINUXDEPLOY_URL="https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage"
PYTHON_VERSION="3.7.16"
PYTHON_APPIMAGE_URL="https://github.com/niess/python-appimage/releases/download/python3.7/python${PYTHON_VERSION}-cp37-cp37m-manylinux1_x86_64.AppImage"
PYTHON_VERSION="3.11.2"
PYTHON_APPIMAGE_URL="https://github.com/niess/python-appimage/releases/download/python3.11/python${PYTHON_VERSION}-cp311-cp311-manylinux2014_x86_64.AppImage"
APPIMAGE_DIR=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
APPDIR="$APPIMAGE_DIR/squashfs-root"
BUILD_DIR="$APPDIR/usr/src"
Expand Down Expand Up @@ -32,7 +33,7 @@ setup_build_dir() {

pushd "$APPIMAGE_DIR" || handle_error

setup_python_37_appdir
setup_python_appdir

mkdir -p "$BUILD_DIR"

Expand All @@ -53,10 +54,10 @@ setup_build_dir() {
popd || handle_error
}

setup_python_37_appdir() {
setup_python_appdir() {
PYTHON_APPIMAGE="python${PYTHON_VERSION}_x86_64.AppImage"

log_message "downloading Python3.7 Appimage"
log_message "downloading Python Appimage"
curl -L -o "$PYTHON_APPIMAGE" "$PYTHON_APPIMAGE_URL"

chmod u+x "$PYTHON_APPIMAGE"
Expand All @@ -77,12 +78,14 @@ install_monkey_island_python_dependencies() {
log_message "Installing island requirements"

log_message "Installing pipenv"
"$APPDIR"/AppRun -m pip install pipenv==2022.7.4 || handle_error
"$APPDIR"/AppRun -m pip install pipenv || handle_error
export CI=1

log_message "Installing dependencies"
pushd "$BUILD_DIR/monkey_island" || handle_error
"$APPDIR"/AppRun -m pipenv --python "$APPDIR/AppRun" sync --system || handle_error
"$APPDIR"/AppRun -m pipenv --python "$APPDIR/AppRun" requirements > requirements.txt || handle_error
"$APPDIR"/AppRun -m pip install -r requirements.txt || handle_error
rm requirements.txt
popd || handle_error

log_message "Uninstalling pipenv (build dependency only)"
Expand Down
41 changes: 24 additions & 17 deletions build_scripts/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
# Install python dependencies using the bitnami/python:3.7 image, which includes
# development dependencies.
FROM bitnami/python:3.7 as builder
ARG PYTHON_VERSION=3.11
# Install python and some build dependencies
FROM python:$PYTHON_VERSION-slim as builder
COPY ./monkey /monkey
WORKDIR /monkey
RUN virtualenv .
RUN export CI=1
RUN . bin/activate && \
cd monkey_island && \
pip install pipenv==2022.7.4 && \
pipenv sync
RUN apt-get update && apt-get install -y gcc \
&& python -m venv . \
&& export CI=1 \
&& . bin/activate \
&& pip install -U pip \
&& cd monkey_island \
&& pip install pipenv \
&& pipenv sync


# Build the final application using the bitnami/python:3.7-prod image, which
# Build the final application using a second image, which
# does not include development dependencies.
FROM bitnami/python:3.7-prod
RUN apt-get update && apt-get install -y iputils-ping && apt-get clean
FROM python:$PYTHON_VERSION-slim
COPY --from=builder /monkey /monkey
WORKDIR /monkey
EXPOSE 5000
ENV MONKEY_DOCKER_CONTAINER=true
RUN groupadd -r monkey-island && useradd --no-log-init -r -g monkey-island monkey-island
RUN chmod 444 /monkey/monkey_island/cc/server.key
RUN chmod 444 /monkey/monkey_island/cc/server.csr
RUN chmod 444 /monkey/monkey_island/cc/server.crt
RUN mkdir /monkey_island_data && chmod 700 /monkey_island_data && chown -R monkey-island:monkey-island /monkey_island_data
RUN apt-get update \
&& apt-get install -y iputils-ping \
&& apt-get clean \
&& groupadd -r monkey-island \
&& useradd --no-log-init -r -g monkey-island monkey-island \
&& chmod 444 /monkey/monkey_island/cc/server.key \
&& chmod 444 /monkey/monkey_island/cc/server.csr \
&& chmod 444 /monkey/monkey_island/cc/server.crt \
&& mkdir /monkey_island_data \
&& chmod 700 /monkey_island_data \
&& chown -R monkey-island:monkey-island /monkey_island_data
USER monkey-island
ENTRYPOINT ["/monkey/entrypoint.sh"]
6 changes: 3 additions & 3 deletions monkey/monkey_island/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ verify_ssl = true
name = "pypi"

[packages]
pyinstaller = "==4.9"
bcrypt = "==3.2.0"
pyinstaller = "*"
bcrypt = "*"
boto3 = "1.26.13"
botocore = "1.29.13"
dpath = ">=2.0.5"
Expand Down Expand Up @@ -58,4 +58,4 @@ types-pytz = "*"
types-pyyaml = "*"

[requires]
python_version = "3.7"
python_version = "3.11"
Loading

0 comments on commit ede800d

Please sign in to comment.