[Python] GitHub Actions Docker build not able to reach to GCP artifacts

Discussão em 'Python' iniciado por Stack, Agosto 21, 2025.

  1. Stack

    Stack Membro Participativo

    I have Python package in GCP Artifactory and want to access that in Docker image.

    GitHub Actions workflow:

    jobs:
    publish:
    runs-on: ubuntu-latest
    permissions:
    contents: 'read'
    id-token: 'write' # Required for OIDC
    steps:
    - name: Checkout code
    uses: actions/checkout@v4
    - name: Auth to GCP via OIDC
    uses: google-github-actions/auth@v2
    with:
    workload_identity_provider: projects/<ID>/locations/global/workloadIdentityPools/<PROJCTWIP>/providers/<OIDCPROVIDER>
    service_account: <SERVICEACCOUNT>@<PROJECTID>.iam.gserviceaccount.com
    - name: Set up gcloud
    uses: google-github-actions/setup-gcloud@v2
    with:
    project_id: <PROJECTID>
    - name: Install build dependencies
    run: |
    pip install keyrings.google-artifactregistry-auth
    - name: Configure Docker for Artifact Registry
    run: gcloud auth configure-docker us-central1-docker.pkg.dev
    - name: Build and push Docker image
    uses: docker/build-push-action@v5
    with:
    context: .
    push: true
    tags: us-central1-docker.pkg.dev/<PROJECTID>/<DOCKERREGISTRY>/myimage:latest


    Dockerfile:

    FROM python:3.12-slim

    RUN apt-get update && \
    apt-get install -y --no-install-recommends git openssh-client && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

    RUN pip install --extra-index-url https://us-central1-python.pkg.dev/<PROJECTID>/<PYPIREGISTRY>/simple/ my-backend==0.1.3 && \
    pip install gunicorn

    CMD ["gunicorn", "my_backend.app:app"]


    It gives error

    7 [3/3] RUN pip install --extra-index-url https://us-central1-python.pkg.dev/<PROJECTID>/<PYPIREGISTRY>/simple/ my-backend==0.1.3 && pip install gunicorn
    #7 1.481 Looking in indexes: https://pypi.org/simple, https://us-central1-python.pkg.dev/<PROJECTID>/<PYPIREGISTRY>/simple/, https://us-central1-python.pkg.dev/<PROJECTID>/<PYPIREGISTRY>/simple/
    #7 1.890 User for us-central1-python.pkg.dev: User for us-central1-python.pkg.dev: WARNING: There was an error checking the latest version of pip.
    #7 2.197 ERROR: Exception:
    #7 2.197 Traceback (most recent call last):
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_internal/cli/base_command.py", line 106, in _run_wrapper
    #7 2.197 status = _inner_run()
    #7 2.197 ^^^^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_internal/cli/base_command.py", line 97, in _inner_run
    #7 2.197 return self.run(options, args)
    #7 2.197 ^^^^^^^^^^^^^^^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_internal/cli/req_command.py", line 67, in wrapper
    #7 2.197 return func(self, options, args)
    #7 2.197 ^^^^^^^^^^^^^^^^^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_internal/commands/install.py", line 386, in run
    #7 2.197 requirement_set = resolver.resolve(
    #7 2.197 ^^^^^^^^^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 95, in resolve
    #7 2.197 result = self._result = resolver.resolve(
    #7 2.197 ^^^^^^^^^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_vendor/resolvelib/resolvers.py", line 546, in resolve
    #7 2.197 state = resolution.resolve(requirements, max_rounds=max_rounds)
    #7 2.197 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_vendor/resolvelib/resolvers.py", line 397, in resolve
    #7 2.197 self._add_to_criteria(self.state.criteria, r, parent=None)
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_vendor/resolvelib/resolvers.py", line 173, in _add_to_criteria
    #7 2.197 if not criterion.candidates:
    #7 2.197 ^^^^^^^^^^^^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_vendor/resolvelib/structs.py", line 156, in __bool__
    #7 2.197 return bool(self._sequence)
    #7 2.197 ^^^^^^^^^^^^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 174, in __bool__
    #7 2.197 return any(self)
    #7 2.197 ^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 162, in <genexpr>
    #7 2.197 return (c for c in iterator if id(c) not in self._incompatible_ids)
    #7 2.197 ^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 49, in _iter_built
    #7 2.197 for version, func in infos:
    #7 2.197 ^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 307, in iter_index_candidate_infos
    #7 2.197 result = self._finder.find_best_candidate(
    #7 2.197 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_internal/index/package_finder.py", line 892, in find_best_candidate
    #7 2.197 candidates = self.find_all_candidates(project_name)
    #7 2.197 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_internal/index/package_finder.py", line 833, in find_all_candidates
    #7 2.197 page_candidates = list(page_candidates_it)
    #7 2.197 ^^^^^^^^^^^^^^^^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_internal/index/sources.py", line 193, in page_candidates
    #7 2.197 yield from self._candidates_from_page(self._link)
    #7 2.197 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_internal/index/package_finder.py", line 793, in process_project_url
    #7 2.197 index_response = self._link_collector.fetch_response(project_url)
    #7 2.197 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_internal/index/collector.py", line 448, in fetch_response
    #7 2.197 return _get_index_content(location, session=self.session)
    #7 2.197 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_internal/index/collector.py", line 352, in _get_index_content
    #7 2.197 resp = _get_simple_response(url, session=session)
    #7 2.197 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_internal/index/collector.py", line 131, in _get_simple_response
    #7 2.197 resp = session.get(
    #7 2.197 ^^^^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_vendor/requests/sessions.py", line 602, in get
    #7 2.197 return self.request("GET", url, **kwargs)
    #7 2.197 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_internal/network/session.py", line 523, in request
    #7 2.197 return super().request(method, url, *args, **kwargs)
    #7 2.197 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_vendor/requests/sessions.py", line 589, in request
    #7 2.197 resp = self.send(prep, **send_kwargs)
    #7 2.197 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_vendor/requests/sessions.py", line 710, in send
    #7 2.197 r = dispatch_hook("response", hooks, r, **kwargs)
    #7 2.197 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_vendor/requests/hooks.py", line 30, in dispatch_hook
    #7 2.197 _hook_data = hook(hook_data, **kwargs)
    #7 2.197 ^^^^^^^^^^^^^^^^^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_internal/network/auth.py", line 505, in handle_401
    #7 2.197 username, password, save = self._prompt_for_password(parsed.netloc)
    #7 2.197 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_internal/network/auth.py", line 460, in _prompt_for_password
    #7 2.197 username = ask_input(f"User for {netloc}: ") if self.prompting else None
    #7 2.197 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    #7 2.197 File "/usr/local/lib/python3.12/site-packages/pip/_internal/utils/misc.py", line 243, in ask_input
    #7 2.197 return input(message)
    #7 2.197 ^^^^^^^^^^^^^^
    #7 2.197 EOFError: EOF when reading a line
    #7 ERROR: process "/bin/sh -c pip install --extra-index-url https://us-central1-python.pkg.dev/<PROJECTID>/<PYPIREGISTRY>/simple/ my-backend==0.1.3 && pip install gunicorn" did not complete successfully: exit code: 2


    If I run pip install --extra-index-url https://us-central1-python.pkg.dev/<PROJECTID>/<PYPIREGISTRY>/simple/ my-backend==0.1.3 in my laptop, it works fine.

    What I have to do to make sure Docker in GitHub Actions is able to reach to GCP Artifactory using OIDC?

    Continue reading...

Compartilhe esta Página