diff options
| author | 2022-09-10 21:20:10 +0100 | |
|---|---|---|
| committer | 2022-09-10 21:22:32 +0100 | |
| commit | f209534196a92bbffd251ecd460645e7c54c9286 (patch) | |
| tree | f0285ca61e1351dbf9af0847cd62422115b26a36 | |
| parent | Merge pull request #18 from python-discord/bump-dep (diff) | |
Use venvs with poetry in Dockerfile
his is required due to a regression in poetry, see https://github.com/HassanAbouelela/actions/pull/7
| -rw-r--r-- | .github/workflows/lint-build-deploy.yaml | 47 | ||||
| -rw-r--r-- | Dockerfile | 24 |
2 files changed, 33 insertions, 38 deletions
diff --git a/.github/workflows/lint-build-deploy.yaml b/.github/workflows/lint-build-deploy.yaml index f28530f..eb2bbd7 100644 --- a/.github/workflows/lint-build-deploy.yaml +++ b/.github/workflows/lint-build-deploy.yaml @@ -15,12 +15,11 @@ jobs: name: Lint runs-on: ubuntu-latest env: - # 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 + # Configure pip and poetry to cache dependencies and do an unattended venv install + PIP_NO_CACHE_DIR: 1 + PIP_DISABLE_PIP_VERSION_CHECK: true + POETRY_VIRTUALENVS_IN_PROJECT: true + POETRY_NO_INTERACTION: true # Specify explicit paths for python dependencies and the pre-commit # environment so we know which directories to cache @@ -28,6 +27,10 @@ jobs: 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 @@ -35,33 +38,13 @@ jobs: - 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.0 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' + poetry_version: 'poetry==1.2.0' # Run flake8 and have it format the linting errors in the format of # the GitHub Workflow command to register error annotations. This @@ -1,15 +1,26 @@ FROM --platform=linux/amd64 python:3.10-slim -ENV PIP_NO_CACHE_DIR=false \ - POETRY_VIRTUALENVS_CREATE=false +# 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="/app" -# Install poetry -RUN pip install -U poetry +ENV PATH="$POETRY_HOME/bin:/$INSTALL_DIR/.venv/bin:$PATH" -# Create the working directory -WORKDIR /arthur +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/* + +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 @@ -20,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"] |