Передать Gitlab CI_JOB_TOKEN из Cloud Build в Dockerfile

Мне очень нужна помощь по этому вопросу. Кажется, я перепробовал все советы в интернете, но все безрезультатно. Должно быть, я что-то упускаю!!

Предыстория

Я попробовал жестко заcodeировать учетные данные в Dockerfile, и все работает так, как и ожидалось. Все рушится только при попытке использовать переменную $CI_JOB_TOKEN!

.gitlab-ci.yml

cloudbuild.yaml

Dockerfile

Ошибка конвейера

...

.build:
  image:
    name: google/cloud-sdk:latest
  script:
    - gcloud builds submit --config=cloudbuild.yaml --substitutions=_CI_JOB_TOKEN="$CI_JOB_TOKEN"

...
steps:
  - name: 'gcr.io/cloud-builders/docker'
    entrypoint: bash
    args:
      - -c
      - |
         DOCKER_BUILDKIT=1 docker build -t target --build arg=CI_JOB_TOKEN=${_CI_JOB_TOKEN} .

substitutions:
  _CI_JOB_TOKEN: replace at runtime
FROM python:3.11.5-slim as python-base

#Install Poetry

RUN --mount-type=cache,target=/root/.cache \
  curl -sSL https://install.python-poetry.org | python -

WORKDIR /app
COPY poetry.lock pyproject.toml ./
COPY python_scripts/ python_scripts/

#Authenticate with Gitlab Package Registry with CI_JOB_TOKEN
ARG CI_JOB_TOKEN

RUN poetry config http-basic.gitlab gitlab-ci-token $CI_JOB_TOKEN

#Install dependencies
RUN --mount=type=cache,target=/root/.cache \
  poetry install --no-root --only-main

#19 7.513   RuntimeError
#19 7.513 
#19 7.513   Unable to find installation candidates for package_name (0.1.4)
#19 7.513 
#19 7.513   at /opt/poetry/venv/lib/python3.11/site-packages/poetry/installation/chooser.py:74 in choose_for
#19 7.532        70│ 
#19 7.532        71│             links.append(link)
#19 7.532        72│ 
#19 7.532        73│         if not links:
#19 7.532     →  74│             raise RuntimeError(f"Unable to find installation candidates for {package}")
#19 7.533        75│ 
#19 7.533        76│         # Get the best link
#19 7.533        77│         chosen = max(links, key=lambda link: self._sort_key(package, link))
#19 7.533        78│ 
#19 7.533 
#19 7.533 Cannot install package_name.
#19 7.533
#19 ERROR: executor failed running [/bin/sh -c poetry install --no-root --only main]: exit code: 1
------
 > [builder-base 8/8] RUN --mount=type=cache,target=/root/.cache     poetry install --no-root --only main:
------
executor failed running [/bin/sh -c poetry install --no-root --only main]: exit code: 1
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 1
Афанасий
Вопрос задан10 января 2024 г.

1 Ответ

Ваш ответ

Загрузить файл.