pythonlinuxdockerjenkinspython-poetry

Running poetry in using jenkins dockerfile


I've got my dockerfile

FROM git.corp.com:4567/some/python:3.11-slim

RUN apt update; \
  apt install pipx -y; \
  pipx install  poetry; \
  pipx ensurepath; \
  chmod a +rx /root/.local/bin/poetry; \
  ln -s /root/.local/bin/poetry /usr/bin/poetry; \

and my jenkins stage

stage('Test') {
      agent {
        dockerfile{
            filename 'Dockerfile.build'
            args "-v $WORKSPACE:/app"
            reuseNode true
        }
      }
      steps {
          sh """
          ls -l poetry
          poetry install --no-root -E tests -E mypy -E lint
          PYTHONPATH="$PWD/src" pytest
          """
      }
    }

Why do I get this message?

script.sh.copy: 3: poetry: Permission denied 

I've changed permessions using chmod a +rx

ls -l poetry output looks like this

lrwxrwxrwx 1 root root 23 Apr 11 10:02 /usr/bin/poetry -> /root/.local/bin/poetry

I know Jenkins pass -u 1000:1000 arguments to docker run command but shouldn't chmod fix this?


Solution

  • Try to install Poetry to the path which will be available to all users instead of installing it to /root/.local

    ENV PIPX_HOME=/opt/pipx \
        PIPX_BIN_DIR=/usr/local/bin
    
    RUN apt update && \
        apt install pipx -y && \
        pipx install poetry