python-poetry / poetry

Python packaging and dependency management made easy
https://python-poetry.org
MIT License
31.21k stars 2.26k forks source link

Auth in Gitlab to the Gitlab hosted package repository does not work correctly #9694

Open geudrik opened 1 week ago

geudrik commented 1 week ago

Description

When the following is run in a CI job on GL, a 400 is returned, indicating that Auth succeeded (the 400 is expected on successful auth)

- "curl -v --header \"JOB-TOKEN: ${CI_JOB_TOKEN}\" \"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi\""

Using the following to attempt to push a package results in a 401, when from what I can tell, it shouldn't

    - poetry config repositories.gitlab "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi"
    - poetry config http-basic.gitlab "gitlab-ci-token" "${CI_JOB_TOKEN}"
    - poetry publish -r gitlab

Am I just doing something wrong?

Workarounds

The aim is to push a built python package into the GL registry. The work-around is to use Twine

Publish with Twine:
  image: python:3.12
  stage: Publish
  needs:
    - job: Discern New Version Tag
      artifacts: true
    - job: Build Package
      artifacts: true
  script:
    - pip install twine
    - export TWINE_PASSWORD=${CI_JOB_TOKEN}
    - export TWINE_USERNAME=gitlab-ci-token
    - python -m twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/*
  rules:
    - if: $CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE != "merge_request_event"

Poetry Installation Method

pip

Operating System

Debian [python 3.12 image]

Poetry Version

Poetry (version 1.8.3)

Poetry Configuration

n/a

Python Sysconfig

No response

Example pyproject.toml

No response

Poetry Runtime Logs

n/a
dimbleby commented 1 week ago

Am I just doing something wrong?

I guess you are not reading the docs, and you are not searching for duplicates.

Probably https://python-poetry.org/docs/cli#usage

geudrik commented 1 week ago

Will give this a shot, thanks!