Skip to content

Commit 41f012f

Browse files
committed
allow to specify RSA key filename
1 parent 96c2dce commit 41f012f

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ In case of private repositories you also have to mount deployment SSH key author
2020
### optional
2121
`TAG` - clone specified tag
2222

23-
`BRANCH` - clone specified branch
23+
`BRANCH` - clone specified branch (defaults to master)
24+
25+
`REPO_KEY` - RSA key filename (defaults to id_rsa)
2426

2527
if cloning using repository username/password instead SSH deployment key, please provide `REPO_LINK` without leading `https://`
2628

@@ -32,9 +34,9 @@ if cloning using repository username/password instead SSH deployment key, please
3234
## Example run
3335

3436
```
35-
docker --rm run -ti \
37+
docker run --rm -ti \
3638
-v /path/to/clone/repository:/repository \
37-
-v /path/to/authorized/id_rsa:/root/.ssh/id_rsa \
39+
-v /path/to/authorized/id_rsa:/key:ro \
3840
-e REPO_LINK=crunchgeek/git-clone
3941
-e REPO_BRANCH=master
4042
-e REPO_TAG=1.0.0

init.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,35 @@ if [ -z "$REPO_BRANCH" ]; then
99
export REPO_BRANCH=master
1010
fi
1111

12+
if [ -z "$REPO_KEY" ]; then
13+
export REPO_KEY=id_rsa
14+
fi
15+
16+
echo "repository : $REPO_LINK"
17+
echo "branch : $REPO_BRANCH"
1218
# check if credentials files exist
13-
if [[ -f "/root/.ssh/id_rsa" ]] ; then
19+
if [[ -f "/key/$REPO_KEY" ]] ; then
20+
echo "key file : $REPO_KEY"
21+
cp /key/$REPO_KEY /root/.ssh/id_rsa
1422
chmod 600 /root/.ssh/id_rsa
1523
fi
1624

1725
if [ ! -z "$REPO_USER" ] && [ ! -z "$REPO_PASS" ]; then
1826
# clone with repository username & password
27+
echo "credentials: username and password"
1928
git clone -b $REPO_BRANCH https://$REPO_USER:$REPO_PASS@$REPO_LINK /repository
2029
elif [[ ! -f "/root/.ssh/id_rsa" ]] ; then
2130
echo -e "\033[1;91mERROR:\033[0m REPO_USER, REPO_PASS env variables or SSH deployment key missing"
2231
exit 1
2332
else
2433
# clone public repository or using ssh deployment key
34+
echo "credentials: RSA key"
2535
git clone -b $REPO_BRANCH $REPO_LINK /repository
2636
fi
2737

2838
if [ ! -z "$REPO_TAG" ]; then
2939
cd /repository && \
40+
echo "checking out repository tag: $REPO_TAG"
3041
git checkout tags/$REPO_TAG
3142
fi
3243

0 commit comments

Comments
 (0)