Skip to content

Commit

Permalink
Exclude poetry from final image and simplify it's usage
Browse files Browse the repository at this point in the history
  • Loading branch information
superrnovae committed Sep 18, 2022
1 parent 9525a4d commit 5f843be
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 90 deletions.
39 changes: 13 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
63 changes: 0 additions & 63 deletions docker/entrypoint.sh

This file was deleted.

2 changes: 1 addition & 1 deletion permasigner/tcprelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down

0 comments on commit 5f843be

Please sign in to comment.