温馨提示:本文翻译自stackoverflow.com,查看原文请点击:swift - Error importing multiple private repositories with vapor
swift ssh vapor swift-package-manager

swift - 导入多个带有蒸气的私有存储库时出错

发布于 2020-03-27 10:45:56

我在导入多个私有存储库时遇到问题,我似乎可以用1做到这一点。所以我想知道是否有人可以告诉我我做错了什么。我的项目结构如下:Package.swift所在项目的根目录:

--.ssh
    --config
    --model
    --model.pub
    --service
    --service.key

package.swift的内容:

import PackageDescription

let package = Package(
    name: "Server",
    products: [
        .library(name: "Seerver", targets: ["App"]),
    ],
    dependencies: [
        // ???? A server-side Swift web framework.
        .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"),

        // ???? Swift ORM (queries, models, relations, etc) built on SQLite 3.
        .package(url: "https://github.com/vapor/fluent-sqlite.git", from: "3.0.0"),

        .package(url: "git@github.com:SwiftEverywhere/Model.git", .branch("master")),

        .package(url: "git@service.github.com:SwiftEverywhere/Service.git", .branch("master"))
    ],
    targets: [
        .target(name: "App", dependencies: ["FluentSQLite", "Vapor", "Model", "Service"]),
        .target(name: "Run", dependencies: ["App"]),
        .testTarget(name: "AppTests", dependencies: ["App"])
    ]
)

配置内容:

Host github.com
    HostName github.com
    User git
    IdentityFile ./.ssh/model
Host service.github.com
    HostName github.com
    User git
    IdentityFile ./.ssh/service

我将密钥添加到它们各自的存储库中作为部署密钥。我无法在不同的存储库上使用相同的密钥。我以为我可以通过将主机更改为service.github.com来使其使用其他密钥来做到这一点,但似乎无法正常工作。我还尝试了更改用户名和主机名,但没有成功。

The error I'm receiving when running 'vapor update' is "Could not read from remote repository. Please make sure you have the correct access rights and the repository exists"

If I remove the service dependency it does work, so that must be where I made a mistake. Thanks in advance!

tldr; Basically I need to know how to configure the config file and/or the package.swift to use the right deploy key.

查看更多

查看更多

提问者
SwiftEverywhere
被浏览
187
code28 2019-07-08 15:31

The problem is, that you can't use one key on multiple repositories as deploy keys, which you already noticed.

According to this gist and those comments you can work around like this:

In your Package.swift:

.package(url: "git@github.com-model:SwiftEverywhere/Model.git", .branch("master")),
.package(url: "git@github.com-service:SwiftEverywhere/Service.git", .branch("master"))

In your SSH-config (probably ~/.ssh/config):

Host github.com-model
    HostName github.com
    User git
    IdentityFile ~/.ssh/model

Host github.com-service
    HostName github.com
    User git
    IdentityFile ~/.ssh/service

另一个解决方法是使用部署密钥作为用户范围的ssh密钥来创建部署用户。然后将此部署用户作为协作者添加到您的私有存储库。