Multiple deploy keys for GitHub

@JanBrinker, I’m excited to try that approach, which sounds like it would work for our use-case: using the main repository for “staging”, while having a job that deploys to a separate “production” repository in a different Github organisation.

So far we have been using a pretty hacky approach to accomplish this, by manually changing the .ssh/config file. In a nutshell, the main steps are:

  1. In the “SSH Permissions” tab on CircleCI.com, add 2 separate SSH keys, one with a hostname of “gh-stg” and the other with a hostname of “gh-prod”.
  2. In the workflow when the staging repository needs to be cloned, use this code:
    • sed -i -e 's/Host gh-stg/Host gh-stg\n HostName github.com/g' ~/.ssh/config
    • git clone git@gh-stg:my-staging-github-org/my-staging-repo.git
  3. Likewise, when the production repository needs to be cloned, use this code:
    • sed -i -e 's/Host gh-prod/Host gh-prod\n HostName github.com/g' ~/.ssh/config
    • git clone git@gh-prod:my-prod-github-org/my-prod-repo.git