Мне нужно установить через composer приватный пакет из корпоративного неймспейса в Gitlab CI.
Зависимость в composer.json.
"repositories": [
{
"type": "git",
"url": "git@gitlab.com:namespace/package.git"
}
],
"require": {
"namespace/package": "dev-master",
}
в .gitlab.ci.yml
image: registry.gitlab.com/namespace/project:1.0.0
stages:
- deploy
.setup_ssh: &setup_ssh
- 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client zip unzip -y )'
- eval $(ssh-agent -s)
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_PUBLIC_KEY" > ~/.ssh/id_rsa.pub
- echo "$SSH_PRIVATE_KEY" | base64 -d > ~/.ssh/id_rsa
- ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
- ssh-keyscan $DEV_HOST >> ~/.ssh/known_hosts
- chmod 600 ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa.pub
- chmod 644 ~/.ssh/known_hosts
- ssh-add ~/.ssh/id_rsa
.setup_composer: &setup_composer
- composer i -n
deploy to dev:
stage: deploy
script:
- *setup_ssh
- *setup_composer
При установке composer i -n падает с ошибкой на приватном пакете.
Cloning into bare repository '/root/.composer/cache/vcs/git-gitlab.com-namespace-package.git'...
remote:
remote: ========================================================================
remote:
remote: The project you were looking for could not be found or you don't have permission to view it.
remote:
remote: ========================================================================
remote:
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Я попробовал запустить контейнер локально и установить зависимости composer внутри контейнера в интерактивном режиме.
- Syncing namespace/package (dev-master fa27046) into cache
Cloning failed, enter your GitLab credentials to access private repos
A token will be created and stored in "/root/.composer/auth.json", your password will never be stored
To revoke access to this token you can visit https://gitlab.com/-/profile/personal_access_tokens
У меня настроена 2FA. Для теста я создал токен и попробовал авторизоваться.
composer config --global gitlab-token.gitlab.com [token]
После этого все заработало. Но проблема в том, что это мой персональный токен.
Как авторизоваться внутри контейнера Gitlab CI?