Skip to content

Commit d1a33e6

Browse files
author
Rogerio Varalda Jr
committed
feat(builder): add ssh key variable to support private repositories
remove 'del ssh_key' add builder SSH_KEY, deis client config set SSH_KEY, and its docs
1 parent d1cdd57 commit d1a33e6

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
@@ -1039,6 +1040,18 @@ def config_set(self, args):
10391040
if not app:
10401041
app = self._session.app
10411042
values = dictify(args['<var>=<value>'])
1043+
if values.get('SSH_KEY'):
1044+
if os.path.isfile(values.get('SSH_KEY')):
1045+
with open(values.get('SSH_KEY')) as f:
1046+
ssh_key = f.read()
1047+
else:
1048+
ssh_key = values['SSH_KEY']
1049+
match = re.match(r'^-.+ .SA PRIVATE KEY-*', ssh_key)
1050+
if match:
1051+
values['SSH_KEY'] = b64encode(ssh_key)
1052+
else:
1053+
self._logger.error("Could not parse SSH private key {}".format(ssh_key))
1054+
sys.exit(1)
10421055
self._config_set(app, values)
10431056

10441057
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)