Skip to content

Commit

Permalink
Merge pull request #2 from stakater-docker/debug
Browse files Browse the repository at this point in the history
fix user access issue
  • Loading branch information
waseem-h committed Nov 10, 2018
2 parents 9c16f2d + c21eaec commit 9ec2d06
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
11 changes: 9 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ FROM debian:stretch

RUN apt-get update && apt-get install -y git

ARG USER=1001

ADD [--chown=$USER:root] init.sh /
RUN chmod +x /init.sh

USER root

RUN mkdir /root/.ssh/ && \
mkdir /repository && \
touch /root/.ssh/known_hosts && \
echo "\nStrictHostKeyChecking no" >> /etc/ssh/ssh_config

ADD init.sh /
RUN chmod +x /init.sh
RUN chgrp -R 0 /root && \
chmod -R g=u /root

# Clean up
RUN apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ It is also required to mount a volume where the repository will be cloned from l
In case of private repositories you also have to mount deployment SSH key authorized to clone code repository

### optional
`TAG` - clone specified tag
`REPO_TAG` - checkout specified tag

`BRANCH` - clone specified branch (defaults to master)
`REPO_REVISION` - checkout specified revision

`REPO_BRANCH` - clone specified branch (defaults to master)

`REPO_KEY` - RSA key filename (defaults to id_rsa)

Expand Down
19 changes: 14 additions & 5 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ fi

echo "repository : $REPO_LINK"
echo "branch : $REPO_BRANCH"
echo "tag : $REPO_TAG"
echo "revision : $REPO_REVISION"
# check if credentials files exist
if [[ -f "/key/$REPO_KEY" ]] ; then
echo "key file : $REPO_KEY"
Expand All @@ -27,12 +29,14 @@ if [ ! -z "$REPO_USER" ] && [ ! -z "$REPO_PASS" ]; then
# clone with repository username & password
echo "credentials: username and password"
git clone -b $REPO_BRANCH https://$REPO_USER:$REPO_PASS@$REPO_LINK /repository
elif [[ ! -f "/root/.ssh/id_rsa" ]] ; then
echo -e "\033[1;91mERROR:\033[0m REPO_USER, REPO_PASS env variables or SSH deployment key missing"
exit 1
else
# clone public repository or using ssh deployment key
echo "credentials: RSA key"
if [[ ! -f "/root/.ssh/id_rsa" ]] ; then
echo -e "\033[1;93mWARNING:\033[0m REPO_USER, REPO_PASS env variables or SSH deployment key missing"
else
# clone public repository or using ssh deployment key
echo "credentials: RSA key"
fi
ls -lah /repository
git clone -b $REPO_BRANCH $REPO_LINK /repository
fi

Expand All @@ -42,3 +46,8 @@ if [ ! -z "$REPO_TAG" ]; then
git checkout tags/$REPO_TAG
fi

if [ ! -z "$REPO_REVISION" ]; then
cd /repository && \
echo "checking out repository revision: $REPO_REVISION"
git checkout $REPO_REVISION
fi

0 comments on commit 9ec2d06

Please sign in to comment.