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.