I'm having issues importing multiple private repositories, I seem to be able to do it with 1. So I am wondering if anyone can tell me what it is I'm doing wrong. My Project structure is like this: Inside the root of the project where Package.swift resides:
--.ssh
--config
--model
--model.pub
--service
--service.key
Contents of 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"])
]
)
Contents of config:
Host github.com
HostName github.com
User git
IdentityFile ./.ssh/model
Host service.github.com
HostName github.com
User git
IdentityFile ./.ssh/service
I added the keys to their respective repositories as deploy keys. I am not able to use the same key on different repositories. I thought I was able to do it by changing the host to service.github.com to make it use the other key but it seems to not be working like this. I also tried changing the user and the hostname but it's not doing the trick.
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
Another workaround is to create a deploy user with the deploy key as a user wide ssh key. Then add this deploy user as collaborator to your private repositories.
Thanks for the Response! I will try this as soon as possible, it is correct to just have the .ssh folder with the config and keys right? Then I should refer to IdentityFiles as ./.ssh/model and ./.ssh/service ? Or is it only possible to put the config file and the keys in my root directory?
I'm not 100% sure, but I think the path should be absolute, so
./.ssh/model
won't work. You need to specify the full path, e.g./Users/yourname/myproject/.ssh/model
This is giving me the following error:
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
I am still doing something wrong :/ Maybe the only solution is to check out locally. But I think it should be possible..It looks like you didn't add the correct ssh config. Did you edit the
~/.ssh/config
file or where did you save it? I just tried it exactly as described by me and it worked like a charm.The config file is in the .ssh file in my project, should I keep it in the .ssh of my root?