swift - 使用 Vapor 导入多个私有(private)存储库时出错

标签 swift ssh vapor swift-package-manager

我在导入多个私有(private)存储库时遇到问题,我似乎可以使用 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: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dabdb3ae9abdb3aeb2afb8f4b9b5b7" rel="noreferrer noopener nofollow">[email protected]</a>:SwiftEverywhere/Model.git", .branch("master")),

        .package(url: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5037392410233522263933357e3739243825327e333f3d" rel="noreferrer noopener nofollow">[email protected]</a>: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

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

运行“vapor update”时收到的错误是“无法从远程存储库读取。请确保您具有正确的访问权限并且存储库存在”

如果我删除服务依赖项,它确实可以工作,所以这一定是我犯错误的地方。提前致谢!

tldr;基本上我需要知道如何配置配置文件和/或 package.swift 以使用正确的部署 key 。

最佳答案

问题是,您不能在多个存储库上使用一个 key 作为部署 key ,您已经注意到了这一点。

根据this gist and those comments你可以像这样解决:

在您的Package.swift中:

.package(url: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="46212f3206212f322e33246825292b6b2b2922232a" rel="noreferrer noopener nofollow">[email protected]</a>:SwiftEverywhere/Model.git", .branch("master")),
.package(url: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ff98968bbf98968b978a9dd19c9092d28c9a8d89969c9a" rel="noreferrer noopener nofollow">[email protected]</a>:SwiftEverywhere/Service.git", .branch("master"))

在你的 SSH 配置中(可能是 ~/.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

另一个解决方法是创建一个部署用户,并将部署 key 作为用户范围的 ssh key 。然后将此部署用户作为协作者添加到您的私有(private)存储库。

关于swift - 使用 Vapor 导入多个私有(private)存储库时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56871705/

相关文章:

swift - 线程1 : Exception: “attempt to insert row 1 into section 1, but there are only 1 sections after the update”

swift - 从 actor 的 init 方法中调用方法

macos - Laravel Homestead 在 SSH 身份验证方法 : private key on mac 中挂起

swift - 我可以使用直接 SQL 来使用 Fluent (Vapor) 获取表中的行数吗?

swift - Vapor 3 Swift 4 如何制作计时器

ios - NSRangeException - 无法删除观察者

ios - 谷歌地图IOS sdk只显示 '??????'

尽管存在 SSH 凭据,但 Git 克隆无法在 Docker 构建中工作

windows - 如何在 Windows 上使用 SSH 详细模式运行 git 命令?

swift - 如何验证服务器端 Swift HTTPS 端点中的 SNS 消息?