From 5f843be5032723a3887fb82d958ec09220d7a778 Mon Sep 17 00:00:00 2001 From: superrnovae Date: Sun, 18 Sep 2022 22:44:51 +0200 Subject: [PATCH] Exclude poetry from final image and simplify it's usage --- Dockerfile | 39 +++++++++---------------- docker/entrypoint.sh | 63 ----------------------------------------- permasigner/tcprelay.py | 2 +- 3 files changed, 14 insertions(+), 90 deletions(-) delete mode 100755 docker/entrypoint.sh diff --git a/Dockerfile b/Dockerfile index eb523eb8..b8c4aa1a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,58 +11,45 @@ ENV PYTHONUNBUFFERED=1 \ PIP_DEFAULT_TIMEOUT=100 \ # poetry # https://python-poetry.org/docs/configuration/#using-environment-variables - POETRY_VERSION=1.2.0 \ + POETRY_VERSION=1.2.1 \ POETRY_HOME="/opt/poetry" \ # make poetry create the virtual environment in the project's root # it gets named `.venv` POETRY_VIRTUALENVS_IN_PROJECT=true \ # do not ask any interactive question POETRY_NO_INTERACTION=1 \ - # paths # this is where our requirements + virtual environment will live PYSETUP_PATH="/app" \ - VENV_PATH="/opt/pysetup/.venv" + VENV_PATH="/app/env" # prepend poetry and venv to path ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH" # `builder` stage is used to build deps + create our virtual environment FROM base as builder -RUN apt-get update \ - && apt-get install --no-install-recommends -y \ - # deps for installing poetry - curl \ - # deps for building python deps - build-essential \ - # deps for generating version file - git +RUN apt-get update && apt-get install --no-install-recommends -y curl # install poetry - respects $POETRY_VERSION & $POETRY_HOME RUN curl -sSL https://install.python-poetry.org | python3 - # copy project requirement files here to ensure they will be cached. WORKDIR $PYSETUP_PATH -COPY poetry.lock pyproject.toml ./ +COPY permasigner ./permasigner +COPY LICENSE README.md main.py . +COPY pyproject.toml poetry.lock . -# install runtime deps - uses $POETRY_VIRTUALENVS_IN_PROJECT internally -RUN poetry install --all-extras --without dev +# Build the permasigner +RUN poetry build +RUN python -m venv env +RUN pip install dist/*.whl ### 2ND STAGE BUILD ### FROM base as main -# copy in our built poetry + venv -COPY --from=builder $POETRY_HOME $POETRY_HOME -COPY --from=builder $PYSETUP_PATH $PYSETUP_PATH - -# will become mountpoint of our code -WORKDIR /app - -# copy in project files required to run permasigner -COPY docker ./docker/ -COPY main.py LICENSE ./ -COPY permasigner ./permasigner/ +# copy in the virtual environment +COPY --from=builder $VENV_PATH $VENV_PATH ENV IS_DOCKER_CONTAINER Yes -CMD [ "/app/docker/entrypoint.sh" ] +ENTRYPOINT [ "permasigner" ] diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh deleted file mode 100755 index e277c281..00000000 --- a/docker/entrypoint.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/sh - -ARGS="" - -if [ ! -z "$WINDOWS" ]; then - export HOST_IS_WINDOWS=true -fi - -if [ ! -z "$IPA" ]; then - ARGS="$ARGS -p $IPA" -fi - -if [ ! -z "$URL" ]; then - ARGS="$ARGS -u $URL" -fi - -if [ ! -z "$DEBUG" ]; then - ARGS="$ARGS -d" -fi - -if [ ! -z "$INSTALL" ]; then - ARGS="$ARGS -i" -fi - -if [ ! -z "$BUNDLEID" ]; then - ARGS="$ARGS -b $BUNDLEID" -fi - -if [ ! -z "$NAME" ]; then - ARGS="$ARGS -n $NAME" -fi - -if [ ! -z "$MINVER" ]; then - ARGS="$ARGS -m $MINVER" -fi - -if [ ! -z "$LDIDFORK" ]; then - ARGS="$ARGS -l $LDIDFORK" -fi - -if [ ! -z "$FOLDER" ]; then - ARGS="$ARGS -f $FOLDER" -fi - -if [ ! -z "$TCPRELAY" ]; then - ARGS="$ARGS -t $TCPRELAY" -fi - -if [ ! -z "$ENTITLEMENTS" ]; then - ARGS="$ARGS -e $ENTITLEMENTS" -fi - -if [ ! -z "$NO_LDID_CHECK" ]; then - ARGS="$ARGS -z" -fi - -if [ ! -z "$VERSION" ]; then - ARGS="$ARGS -v" -fi - -echo "Running Permasigner with args:$ARGS" -echo "" -poetry run permasigner $ARGS diff --git a/permasigner/tcprelay.py b/permasigner/tcprelay.py index c46edf4e..41d7d966 100644 --- a/permasigner/tcprelay.py +++ b/permasigner/tcprelay.py @@ -170,7 +170,7 @@ def getpacket(self): class MuxConnection(object): def __init__(self, socketpath, protoclass): self.socketpath = socketpath - if os.environ.get("HOST_IS_WINDOWS", False): + if "WSL" in os.uname().release: family = socket.AF_INET address = ('host.docker.internal', 27015) elif os.name == 'nt':