Skip to content

Commit 2a59e60

Browse files
committed
Merge pull request #3305 from rvaralda/master
feat(builder): add ssh key variable to support private repositories
2 parents 6b9b76d + d1a33e6 commit 2a59e60

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

builder/image/slugbuilder/builder/build.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ if [[ -n "$BUILDPACK_URL" ]]; then
8787
committish="master"
8888
fi
8989

90+
if [[ -n "$SSH_KEY" ]]; then
91+
mkdir -p ~/.ssh/
92+
chmod 700 ~/.ssh/
93+
94+
echo $SSH_KEY | base64 -d > ~/.ssh/id_rsa
95+
chmod 400 ~/.ssh/id_rsa
96+
97+
echo 'StrictHostKeyChecking=no' > ~/.ssh/config
98+
chmod 600 ~/.ssh/config
99+
100+
fi
101+
90102
set +e
91103
git clone --branch "$committish" --depth=1 "$url" "$buildpack" &> /dev/null
92104
SHALLOW_CLONED=$?

client/deis.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from itertools import cycle
4949
from threading import Event
5050
from threading import Thread
51+
from base64 import b64encode
5152
import glob
5253
import json
5354
import locale
@@ -1057,6 +1058,18 @@ def config_set(self, args):
10571058
if not app:
10581059
app = self._session.app
10591060
values = dictify(args['<var>=<value>'])
1061+
if values.get('SSH_KEY'):
1062+
if os.path.isfile(values.get('SSH_KEY')):
1063+
with open(values.get('SSH_KEY')) as f:
1064+
ssh_key = f.read()
1065+
else:
1066+
ssh_key = values['SSH_KEY']
1067+
match = re.match(r'^-.+ .SA PRIVATE KEY-*', ssh_key)
1068+
if match:
1069+
values['SSH_KEY'] = b64encode(ssh_key)
1070+
else:
1071+
self._logger.error("Could not parse SSH private key {}".format(ssh_key))
1072+
sys.exit(1)
10601073
self._config_set(app, values)
10611074

10621075
def _config_set(self, app, values):

docs/using_deis/using-buildpacks.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,29 @@ Use ``deis create`` to create an application on the :ref:`controller`.
2727
Creating application... done, created unisex-huntress
2828
Git remote deis added
2929
30+
Optional: Add SSH KEY to use private repositories
31+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
32+
33+
To pull code from private repositories, you'll need to provide Deis with a private SSH key which has access.
34+
35+
You can do so with deis client:
36+
37+
38+
Using private key file:
39+
40+
.. code-block:: console
41+
42+
$ deis config:set SSH_KEY=/home/user/.ssh/id_rsa
43+
44+
45+
You can also use a raw key instead of a private key file:
46+
47+
.. code-block:: console
48+
49+
$ deis config:set SSH_KEY="""-----BEGIN RSA PRIVATE KEY-----
50+
(...)
51+
-----END RSA PRIVATE KEY-----"""
52+
3053
Push to Deploy
3154
--------------
3255
Use ``git push deis master`` to deploy your application.

0 commit comments

Comments
 (0)