IBM-Swift / swift-buildpack

IBM Cloud buildpack for Swift
BSD 3-Clause "New" or "Revised" License
32 stars 31 forks source link

Multiple private repositories #124

Closed mbarnach closed 4 years ago

mbarnach commented 4 years ago

Hi, I'm trying to build a Kitura project with the Swift-Buildpack on the IBM Cloud Foundry. My server is having multiple private repositories as dependencies (model, db, etc.), and even if I can access all of them individually, I cannot make it work with more than one at the time. I'm using the .ssh approach with all the repositories on Github. All the dependencies repository have their own deployment key, and I've double checked that I can access them with that key. The config file syntax is a bit obscure, and it could really be the issue. So far it looks like something like that:

Host private_repository_dependency
    HostName github.com
    User git
    IdentityFile ~/.ssh/dependency_1

Host private_repository_dependency_2
    HostName github.com
    User git
    IdentityFile ~/.ssh/dependency_2

where HostName is always Github as the repositories are hosted there. and Host is the name of the repository itself (the dependency name). I've tried with other names, with the same result.

For reference, the error is always like that:

 error: Failed to clone git@github.com:User/private_repository_dependency.git:
       Cloning into bare repository '/tmp/app/.build/repositories/private_repository_dependency-e222c161'...
       git@github.com: Permission denied (publickey).
   fatal: Could not read from remote repository.
       Please make sure you have the correct access rights
       and the repository exists.
   Failed to compile droplet: Failed to compile droplet: exit status 1

What am I doing wrong here? Thanks for your help.

mbarnach commented 4 years ago

The solution is to adapt your Package.swift with the alias you've created before:

Before:

  .package(url: "git@github.com:User/private_repository_dependency.git", from: "1.0.0"),

After:

  .package(url: "git@private_repository_dependency:User/private_repository_dependency.git", from: "1.0.0"),

It will use the HostName and the IdentityFile specified by the Host alias key.

Then you can have as many private dependency as you want!