我在导入多个私有存储库时遇到问题,我似乎可以用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.
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密钥来创建部署用户。然后将此部署用户作为协作者添加到您的私有存储库。
感谢您的回应!我将尽快尝试此操作,仅使.ssh文件夹具有配置和键正确对吗?然后我应该将IdentityFiles称为./.ssh/model和./.ssh/service?还是只能将配置文件和密钥放在我的根目录中?
我不确定100%,但是我认为路径应该是绝对的,因此
./.ssh/model
不会起作用。您需要指定完整路径,例如/Users/yourname/myproject/.ssh/model
这给了我以下错误:
Cloning into bare repository \'~/Test/TestPackage-e4ffafc9\'... ssh: Could not resolve hostname github.com-service: nodename nor servname provided, or not known fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.", output: "Fetching git@github.com-service:SwiftEverywhere/TestPackage.git
我仍然在做错事:/也许唯一的解决方法是在本地签出。但我认为应该有可能。看来您未添加正确的ssh配置。您是在编辑
~/.ssh/config
文件还是在哪里保存文件?我只是按照我的描述完全尝试了一下,它就像一种魅力。配置文件位于项目的.ssh文件中,是否应该将其保存在根目录的.ssh中?