GitLab: Composer Install private repository with ssh key (still get error failed to download)

故事扮演 提交于 2021-02-10 05:13:19

问题


I have no issue to clone from my local machine of the private repository, however, when I want to download the file via composer it asks me to create an auth.json file (I don't want this and I don't want to use a token).

Do you have an idea why this happens?

composer.json

"require": {
..
"myname/my-app": "*",
..
},
"repositories": [
        {
            "type": "vcs",
            "url": "git@gitlab.com:myname/my-app.git",
        },
]

I tried to add "no-api": true, I tried to set dev-master but failed. To test it out, I created a repository to BitBucket and with that I have no problems installing it.

My error is:

Loading composer repositories with package information
Failed to download myname/my-app:The "https://gitlab.com/api/v4/projects/myname%2Fmy-app" file could not be downloaded (HTTP/1.1 404 Not Found)
Your credentials are required to fetch private repository metadata (git@gitlab.myname/my-app.git)
A token will be created and stored in "/Users/myname/.composer/auth.json", your password will never be stored
To revoke access to this token you can visit gitlab.com/profile/applications

回答1:


We had the same problem some days ago. The problem is that GitLab public Api does not expose the default branch name of the repository that is needed for composer. The only solution we found so far is:

  1. Go to your GitLab account and create an api token with read access
  2. Open you composer.json and add this:

    "config": {
        "gitlab-token": {
            "gitlab.com": "YOUR_TOKEN"
        }
    },
    
  3. Run composer install

P.S. Use this solution with care since that token will be stored in the project repository and shared with your team.




回答2:


ssh and git now work in composer

Your gitlab clone looks like this:

git@gitlab.com:/.git

Do this in your composer.json:

{
    ...
    "repositories": [
        ...
        {
            "type": "git",
            "url":  "git@gitlab.com:<VENDOR>/<PROJECT>.git"
        }
    ]
}

Then add the resource:

composer require <VENDOR>/<PROJECT>
composer update


来源:https://stackoverflow.com/questions/58204791/gitlab-composer-install-private-repository-with-ssh-key-still-get-error-failed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!