From 350df44731875c4e8b28fc509d83b431cfefbc5c Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Thu, 1 Sep 2022 21:31:33 +0100 Subject: Use venvs with poetry in Dockerfile This is required due to a regression in poetry, see https://github.com/HassanAbouelela/actions/pull/7 --- Dockerfile | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5bb400658..20b099a0b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,26 @@ FROM --platform=linux/amd64 python:3.10-slim # Set pip to have no saved cache -ENV PIP_NO_CACHE_DIR=false \ - POETRY_VIRTUALENVS_CREATE=false +ENV PIP_NO_CACHE_DIR=1 \ + PIP_DISABLE_PIP_VERSION_CHECK=on \ + POETRY_VERSION=1.1.15 \ + POETRY_HOME="/opt/poetry" \ + POETRY_VIRTUALENVS_IN_PROJECT=true \ + POETRY_NO_INTERACTION=1 \ + INSTALL_DIR="/opt/dependencies" \ + APP_DIR="/bot" +ENV PATH="$POETRY_HOME/bin:/$INSTALL_DIR/.venv/bin:$PATH" -# Install poetry -RUN pip install -U poetry +RUN apt-get update \ + && apt-get -y upgrade \ + && apt-get install --no-install-recommends -y curl \ + && apt-get clean && rm -rf /var/lib/apt/lists/* -# Create the working directory -WORKDIR /bot +RUN curl -sSL https://install.python-poetry.org | python # Install project dependencies +WORKDIR $INSTALL_DIR COPY pyproject.toml poetry.lock ./ RUN poetry install --no-dev @@ -22,6 +31,7 @@ ARG git_sha="development" ENV GIT_SHA=$git_sha # Copy the source code in last to optimize rebuilding the image +WORKDIR $APP_DIR COPY . . ENTRYPOINT ["python3"] -- cgit v1.2.3 From e12e5911f971beae0c07c12f9cf632bbaf4e6629 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Thu, 1 Sep 2022 21:31:59 +0100 Subject: Use HassanAbouelela/setup-python for CI --- .github/workflows/lint-test.yml | 62 ++++------------------------------------- 1 file changed, 5 insertions(+), 57 deletions(-) diff --git a/.github/workflows/lint-test.yml b/.github/workflows/lint-test.yml index 2b3dd5b4f..a331659e6 100644 --- a/.github/workflows/lint-test.yml +++ b/.github/workflows/lint-test.yml @@ -33,57 +33,16 @@ jobs: REDDIT_SECRET: ham REDIS_PASSWORD: '' - # Configure pip to cache dependencies and do a user install - PIP_NO_CACHE_DIR: false - PIP_USER: 1 - - # Make sure package manager does not use virtualenv - POETRY_VIRTUALENVS_CREATE: false - - # Specify explicit paths for python dependencies and the pre-commit - # environment so we know which directories to cache - POETRY_CACHE_DIR: ${{ github.workspace }}/.cache/py-user-base - PYTHONUSERBASE: ${{ github.workspace }}/.cache/py-user-base - PRE_COMMIT_HOME: ${{ github.workspace }}/.cache/pre-commit-cache - - # See https://github.com/pre-commit/pre-commit/issues/2178#issuecomment-1002163763 - # for why we set this. - SETUPTOOLS_USE_DISTUTILS: stdlib - steps: - - name: Add custom PYTHONUSERBASE to PATH - run: echo '${{ env.PYTHONUSERBASE }}/bin/' >> $GITHUB_PATH - - name: Checkout repository uses: actions/checkout@v2 - - name: Setup python - id: python - uses: actions/setup-python@v2 - with: - python-version: '3.10' - - # This step caches our Python dependencies. To make sure we - # only restore a cache when the dependencies, the python version, - # the runner operating system, and the dependency location haven't - # changed, we create a cache key that is a composite of those states. - # - # Only when the context is exactly the same, we will restore the cache. - - name: Python Dependency Caching - uses: actions/cache@v2 - id: python_cache + - name: Install Python Dependencies + uses: HassanAbouelela/actions/setup-python@setup-python_v1.3.1 with: - path: ${{ env.PYTHONUSERBASE }} - key: "python-0-${{ runner.os }}-${{ env.PYTHONUSERBASE }}-\ - ${{ steps.python.outputs.python-version }}-\ - ${{ hashFiles('./pyproject.toml', './poetry.lock') }}" - - # Install our dependencies if we did not restore a dependency cache - - name: Install dependencies using poetry - if: steps.python_cache.outputs.cache-hit != 'true' - run: | - pip install poetry - poetry install + # Set dev=true to install flake8 extensions, which are dev dependencies + dev: true + python_version: '3.10' # Check all of our non-dev dependencies are compatible with the MIT license. # If you added a new dependencies that is being rejected, @@ -94,17 +53,6 @@ jobs: pip-licenses --allow-only="$ALLOWED_LICENSE" \ --package $(poetry export -f requirements.txt --without-hashes | sed "s/==.*//g" | tr "\n" " ") - # This step caches our pre-commit environment. To make sure we - # do create a new environment when our pre-commit setup changes, - # we create a cache key based on relevant factors. - - name: Pre-commit Environment Caching - uses: actions/cache@v2 - with: - path: ${{ env.PRE_COMMIT_HOME }} - key: "precommit-0-${{ runner.os }}-${{ env.PRE_COMMIT_HOME }}-\ - ${{ steps.python.outputs.python-version }}-\ - ${{ hashFiles('./.pre-commit-config.yaml') }}" - # We will not run `flake8` here, as we will use a separate flake8 # action. As pre-commit does not support user installs, we set # PIP_USER=0 to not do a user install. -- cgit v1.2.3 From 0b495e757c909d6a5802ffa729cdc9d3e4069978 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Sat, 10 Sep 2022 19:57:16 +0100 Subject: Bump poetry in Docker and lint to 1.2.0 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 20b099a0b..d0687475e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM --platform=linux/amd64 python:3.10-slim # Set pip to have no saved cache ENV PIP_NO_CACHE_DIR=1 \ PIP_DISABLE_PIP_VERSION_CHECK=on \ - POETRY_VERSION=1.1.15 \ + POETRY_VERSION=1.2.0 \ POETRY_HOME="/opt/poetry" \ POETRY_VIRTUALENVS_IN_PROJECT=true \ POETRY_NO_INTERACTION=1 \ -- cgit v1.2.3 From 03a3a03d39099b09ed62337b075a9ada43353144 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Mon, 12 Sep 2022 21:37:04 +0100 Subject: Don't use fake in-project venvs for poetry Instead let poetry install the venv for the project in the right place, leading to a more 'traditional' poetry setup. --- Dockerfile | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index d0687475e..9cf9c7b27 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,15 @@ FROM --platform=linux/amd64 python:3.10-slim -# Set pip to have no saved cache -ENV PIP_NO_CACHE_DIR=1 \ - PIP_DISABLE_PIP_VERSION_CHECK=on \ - POETRY_VERSION=1.2.0 \ - POETRY_HOME="/opt/poetry" \ - POETRY_VIRTUALENVS_IN_PROJECT=true \ - POETRY_NO_INTERACTION=1 \ - INSTALL_DIR="/opt/dependencies" \ - APP_DIR="/bot" - -ENV PATH="$POETRY_HOME/bin:/$INSTALL_DIR/.venv/bin:$PATH" +# Define Git SHA build argument for sentry +ARG git_sha="development" + +ENV POETRY_VERSION=1.2.0 \ + POETRY_HOME="/opt/poetry" \ + POETRY_NO_INTERACTION=1 \ + APP_DIR="/bot" \ + GIT_SHA=$git_sha + +ENV PATH="$POETRY_HOME/bin:$PATH" RUN apt-get update \ && apt-get -y upgrade \ @@ -20,19 +19,12 @@ RUN apt-get update \ RUN curl -sSL https://install.python-poetry.org | python # Install project dependencies -WORKDIR $INSTALL_DIR +WORKDIR $APP_DIR COPY pyproject.toml poetry.lock ./ RUN poetry install --no-dev -# Define Git SHA build argument -ARG git_sha="development" - -# Set Git SHA environment variable for Sentry -ENV GIT_SHA=$git_sha - # Copy the source code in last to optimize rebuilding the image -WORKDIR $APP_DIR COPY . . -ENTRYPOINT ["python3"] -CMD ["-m", "bot"] +ENTRYPOINT ["poetry"] +CMD ["run", "python", "-m", "bot"] -- cgit v1.2.3