poetry icon indicating copy to clipboard operation
poetry copied to clipboard

Permission issue when using Poetry 1.5.1, updated from 1.1.13

Open alejandrofm opened this issue 3 years ago • 9 comments

  • Poetry version: 1.5.1
  • Python version: 3.10
  • OS version and name: Ubuntu (Airflow image)

Have all my repos configured on 1.5.1, read the changelogs and no mention of my issue of similar.

Issue

This is my Dockerfile

FROM apache/airflow:2.7.0-python3.10

RUN pip install pip==23.1
RUN pip install poetry==1.5.1

USER root

RUN if [[ -s packages.txt ]]; then \
    apt-get update && cat packages.txt | xargs apt-get install -y --no-install-recommends \
    && apt-get autoremove -yqq --purge \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*; \
  fi

USER airflow
COPY ./pyproject.toml ./poetry.lock* ./
RUN poetry config virtualenvs.create false

ARG PIP_USERNAME
ARG PIP_PASSWORD
ENV POETRY_HTTP_BASIC_REPO $PIP_USERNAME

# Install Python packages from poetry.lock
RUN poetry install

if I create the lock file with 1.1.13 and generate the image with the above Dockerfile, everything goes smoothly, Just a warning:

13 [8/8] RUN poetry install
#13 1.636 Skipping virtualenv creation, as specified in config file.
#13 1.714 /home/airflow/.local/lib/python3.10/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
#13 1.714   warnings.warn(
#13 3.026 Installing dependencies from lock file
#13 4.814 
#13 4.814 Package operations: 3 installs, 133 updates, 2 removals`

when I create the lock file and run it with 1.5.1 I have this log:

#13 [8/8] RUN poetry install
#13 1.622 Skipping virtualenv creation, as specified in config file.
#13 2.281 Installing dependencies from lock file
#13 3.403 
#13 3.403 Package operations: 3 installs, 134 updates, 0 removals
#13 3.403 
#13 3.403   • Updating wrapt (1.15.0 /home/airflow/.local/lib/python3.10/site-packages -> 1.15.0)
#13 4.678 
#13 4.678   PermissionError
#13 4.678 
#13 4.678   [Errno 13] Permission denied: '/usr/local/lib/python3.10/site-packages/wrapt-1.15.0.dist-info'
#13 4.678 
#13 4.678   at /usr/local/lib/python3.10/pathlib.py:1175 in mkdir
#13 4.731       1171│         """
#13 4.731       1172│         Create a new directory at this given path.
#13 4.731       1173│         """
#13 4.731       1174│         try:
#13 4.732     → 1175│             self._accessor.mkdir(self, mode)
#13 4.732       1176│         except FileNotFoundError:
#13 4.732       1177│             if not parents or self.parent == self:
#13 4.732       1178│                 raise
#13 4.732       1179│             self.parent.mkdir(parents=True, exist_ok=True)
#13 4.732 
#13 ERROR: executor failed running [/bin/bash -o pipefail -o errexit -o nounset -o nolog -c poetry install]: exit code: 1

The poetry version is the only thing that changes between a successful and failed build. Any idea of what could be happening? Thanks!

alejandrofm avatar Sep 05 '23 14:09 alejandrofm

Skipping virtualenv creation, as specified in config file.

this is almost certainly a bad idea, don't do that - #6398

[Errno 13] Permission denied: '/usr/local/lib/python3.10/site-packages/wrapt-1.15.0.dist-info'

apparently you are running as a user who does not have permission in that place in the docker image. since you seem to be running as root, I suppose things are marked read-only.

This is not a poetry issue, please close.

dimbleby avatar Sep 05 '23 16:09 dimbleby

The only thing I changed between the two runs was the Poetry version, that's why I posted it here. I am not using venv because I need these libraries accessible to the docker image I'm pulling. Then other use cases I have run on a venv. Thanks!

alejandrofm avatar Sep 05 '23 17:09 alejandrofm

sure, the new poetry probably behaves differently than the old poetry

but still the problem you have is one of permissions in your container: which is not a poetry problem

dimbleby avatar Sep 05 '23 18:09 dimbleby

Maybe I need to move this into discussion? someone else should had a similar issue, don't know where to start, at the end it's running a pip install as the same user as in the 1.1.3, so, the same permissions should be needed, for now, I'll be downgrading. Thanks!

alejandrofm avatar Sep 05 '23 18:09 alejandrofm

the recommended approach is to use a virtual environment, then there'll be no question of trying to make undesirable updates to system packages

dimbleby avatar Sep 05 '23 18:09 dimbleby

I had the same issue, but I solved it with the method below. I don't know if this is the right way to do it, but it's more important to get things done quickly, so...

# FROM python:3.10.13-alpine3.19
FROM apache/airflow:2.5.3-python3.10

ENV IMAGE_TAG=$TAG
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
ENV TZ Asia/Seoul
ENV PYTHONBREAKPOINT=0
ENV PYTHONUNBUFFERED=0
ENV AIRFLOW_HOME=/home/airflow

USER root
RUN apt update && apt-get install build-essential libssl-dev libffi-dev cmake make pkg-config openssl -y
USER airflow
RUN pip install --upgrade pip && pip install poetry

RUN mkdir -p $AIRFLOW_HOME/app

# 빌드시 설치 시간을 아끼기 위해 디펜던시를 먼저 설치
COPY  projects/naver_ep_manager/pyproject.toml $AIRFLOW_HOME/app/projects/naver_ep_manager/pyproject.toml
COPY  projects/naver_ep_manager/poetry.lock $AIRFLOW_HOME/app/projects/naver_ep_manager/poetry.lock
COPY  lib $AIRFLOW_HOME/app/lib

# THIS IS WHAT I ADDED ---------------------
USER root
RUN chown -R airflow:root /usr/local
# ---------------------------------------------

USER airflow
WORKDIR $AIRFLOW_HOME/app/projects/naver_ep_manager
RUN poetry config virtualenvs.create false
RUN poetry install --no-interaction --no-dev --no-ansi

RavenBuzzni avatar Apr 11 '24 00:04 RavenBuzzni

# syntax=docker/dockerfile:1

# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/go/dockerfile-reference/

# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7

ARG PYTHON_VERSION=3.10.12
FROM python:${PYTHON_VERSION}-slim as base

# Prevents Python from writing pyc files.
ENV PYTHONDONTWRITEBYTECODE=1

# Keeps Python from buffering stdout and stderr to avoid situations where
# the application crashes without emitting any logs due to buffering.
ENV PYTHONUNBUFFERED=1


# Ensure /root/.local/bin is in the PATH
ENV PATH=/root/.local/bin:$PATH

# Working directory
WORKDIR /app
       
# Create a non-privileged user that the app will run under.
# See https://docs.docker.com/go/dockerfile-user-best-practices/
ARG UID=10001
RUN adduser \
    --disabled-password \
    --gecos "" \
    --home "/nonexistent" \
    --shell "/sbin/nologin" \
    --no-create-home \
    --uid "${UID}" \
    appuser


# Install system dependencies
RUN apt-get update \
    && apt-get install -y curl \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*



# Install virtualenv
RUN pip install virtualenv

# Create and activate a virtual environment
RUN virtualenv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"



# Install poetry
RUN curl -sSL https://install.python-poetry.org | python3 - && \
    mv /root/.local/bin/poetry /usr/local/bin/poetry 
    
RUN chmod +x /usr/local/bin/poetry 
RUN chown -R appuser:appuser /usr/local/bin/poetry


# Copy dependency files
COPY poetry.lock pyproject.toml ./


# Install dependencies with Poetry
RUN poetry config virtualenvs.create false \
    && poetry install --no-root


# Switch to the non-privileged user to run the application.
USER appuser


# Set up Database
#RUN /home/appuser/.local/bin/poetry run bash ./prestart.sh

# Copy the source code into the container.
COPY . .

# Expose the port that the application listens on.a
EXPOSE 8000

# Run the application.
CMD poetry run uvicorn app.main:app --reload

I am getting this error when I do compose-up -d 2024-07-06 16:51:09 server-1 | /bin/sh: 1: poetry: Permission denied

Zenitugo avatar Jul 06 '24 16:07 Zenitugo

For best practices about how to use Poetry in docker please see https://github.com/orgs/python-poetry/discussions/1879

finswimmer avatar Nov 01 '24 06:11 finswimmer

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Dec 03 '24 00:12 github-actions[bot]