【问题标题】:GitLab: Composer Install private repository with ssh key (still get error failed to download)GitLab:Composer 使用 ssh 密钥安装私有存储库(仍然出现错误无法下载)
【发布时间】:2020-05-06 02:39:40
【问题描述】:

我从我的私有存储库的本地计算机克隆没有问题,但是,当我想通过 composer 下载文件时,它要求我创建一个 auth.json 文件(我不想要这个,我不想'不想使用令牌)。

你知道为什么会这样吗?

composer.json

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

我尝试添加"no-api": true,我尝试设置dev-master,但失败了。为了测试它,我为 BitBucket 创建了一个存储库,并且安装它没有问题。

我的错误是:

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

【问题讨论】:

    标签: composer-php gitlab


    【解决方案1】:

    几天前我们遇到了同样的问题。问题是 GitLab 公共 Api 没有公开作曲家所需的存储库的默认分支名称。 到目前为止,我们找到的唯一解决方案是:

    1. 转到您的 GitLab 帐户并创建一个具有读取权限的 api 令牌
    2. 打开 composer.json 并添加:

      "config": {
          "gitlab-token": {
              "gitlab.com": "YOUR_TOKEN"
          }
      },
      
    3. 运行作曲家安装

    附:请谨慎使用此解决方案,因为该令牌将存储在项目存储库中并与您的团队共享。

    【讨论】:

    • 有点遗憾,我真的很想不使用令牌。不过还是谢谢。
    • 这就像通过 gitlab 提供的多种类型的令牌,希望一个是正确的,为什么?
    • 您需要创建一个范围为“api”(或者可能是“read_repository”)的“个人访问令牌”。需要令牌才能让作曲家读取您的私人仓库元数据
    • 我发现除了个人访问令牌之外,它还可以与只有read_api 权限的项目访问令牌一起使用。这比使用个人访问令牌安全得多,在某些情况下甚至可以直接提交到 composer.json。
    • 我想知道你是怎么发现的。 composer update -vvvv 只是说“无法下载 无效凭据”
    【解决方案2】:

    ssh 和 git 现在可以在 composer 中使用

    你的 gitlab 克隆看起来像这样:

    git@gitlab.com:/.git

    在您的 composer.json 中执行此操作:

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

    然后添加资源:

    composer require <VENDOR>/<PROJECT>
    composer update
    

    【讨论】:

    • 为什么你使用 git ype 而不是 vcs
    • @famas23,因为问题在 gitlab 上。
    • 这应该被选为正确答案。只需在项目的 composer.json 中用“git”替换存储库类型“vcs”,问题就完全消失了。
    猜你喜欢
    • 1970-01-01
    • 2017-02-19
    • 1970-01-01
    • 1970-01-01
    • 2014-08-20
    • 2021-12-08
    • 2014-11-15
    • 1970-01-01
    • 2021-06-25
    相关资源
    最近更新 更多