From 2e2ecbc0a996af0042688d3d60b3ee7145718942 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Fri, 24 Feb 2017 10:01:33 +0200 Subject: [PATCH] Copy GitHub SSH key in Heroku to access private repositories --- heroku-copy-ssh-key-from-env.sh | 27 +++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 28 insertions(+) create mode 100755 heroku-copy-ssh-key-from-env.sh diff --git a/heroku-copy-ssh-key-from-env.sh b/heroku-copy-ssh-key-from-env.sh new file mode 100755 index 00000000..fc446637 --- /dev/null +++ b/heroku-copy-ssh-key-from-env.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +# Since we have a dependency to a private GitHub +# `sharetribe/sharetribe-sdk-js` repository, we must give Heroku SSH +# access to there. This script copies the GITHUB_SSH_KEY to the +# current user to enable SSH access to the repository. + +# NOTE: This script should be removed when the dependency is not a +# private repository anymore. + +set -e + +if [ -z "$GITHUB_SSH_KEY" ] +then + echo "No GitHub SSH key to copy" + exit 0 +fi + +echo "Copying GitHub SSH key" +mkdir -p ~/.ssh +chmod 700 ~/.ssh +echo "$GITHUB_SSH_KEY" > ~/.ssh/id_rsa +chmod 600 ~/.ssh/id_rsa + +echo "Adding GitHub SSH Host key to known hosts" +ssh-keyscan -H github.com >> ~/.ssh/known_hosts +chmod 600 ~/.ssh/known_hosts diff --git a/package.json b/package.json index cdee21f4..0d8974c9 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "eject": "sharetribe-scripts eject", "start": "node server/index.js", "dev-server": "yarn run build&&nodemon --watch server server/index.js", + "heroku-prebuild": "./heroku-copy-ssh-key-from-env.sh", "heroku-postbuild": "yarn run build" }, "engines": {