From 67259ded7b01fbbcd4df9f4a856c50cbdd524233 Mon Sep 17 00:00:00 2001 From: Ahmad Iqbal Date: Fri, 9 Nov 2018 22:29:05 +0500 Subject: [PATCH 1/4] debug commands --- init.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/init.sh b/init.sh index 16a4f16..b17d677 100644 --- a/init.sh +++ b/init.sh @@ -18,8 +18,13 @@ echo "branch : $REPO_BRANCH" # check if credentials files exist if [[ -f "/key/$REPO_KEY" ]] ; then echo "key file : $REPO_KEY" + echo "current user: " + id -un + ls -lah /key + ls -lah /root/.ssh/ cp /key/$REPO_KEY /root/.ssh/id_rsa chmod 600 /root/.ssh/id_rsa + ls -lah /root/.ssh/ ssh-keyscan -H gitlab.com >> /root/.ssh/known_hosts fi From a7f125f29690efada7faba7a5a12b6c89863c2e8 Mon Sep 17 00:00:00 2001 From: Ahmad Iqbal Date: Fri, 9 Nov 2018 22:53:33 +0500 Subject: [PATCH 2/4] modify image user --- Dockerfile | 13 +++++++++++-- init.sh | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index e12dc64..1a79f8a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,15 +2,24 @@ 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/* +USER $USER + CMD ["/init.sh"] diff --git a/init.sh b/init.sh index b17d677..54d8204 100644 --- a/init.sh +++ b/init.sh @@ -21,6 +21,7 @@ if [[ -f "/key/$REPO_KEY" ]] ; then echo "current user: " id -un ls -lah /key + ls -lah /root ls -lah /root/.ssh/ cp /key/$REPO_KEY /root/.ssh/id_rsa chmod 600 /root/.ssh/id_rsa From 76b858aaa3467db1de240d033b3eb5332857a414 Mon Sep 17 00:00:00 2001 From: Ahmad Iqbal Date: Sat, 10 Nov 2018 02:30:32 +0500 Subject: [PATCH 3/4] remove debug commands --- init.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/init.sh b/init.sh index 54d8204..16a4f16 100644 --- a/init.sh +++ b/init.sh @@ -18,14 +18,8 @@ echo "branch : $REPO_BRANCH" # check if credentials files exist if [[ -f "/key/$REPO_KEY" ]] ; then echo "key file : $REPO_KEY" - echo "current user: " - id -un - ls -lah /key - ls -lah /root - ls -lah /root/.ssh/ cp /key/$REPO_KEY /root/.ssh/id_rsa chmod 600 /root/.ssh/id_rsa - ls -lah /root/.ssh/ ssh-keyscan -H gitlab.com >> /root/.ssh/known_hosts fi From c21eaec0530d3bd30ebafa574f0e5028b58e592a Mon Sep 17 00:00:00 2001 From: Ahmad Iqbal Date: Sat, 10 Nov 2018 12:12:39 +0500 Subject: [PATCH 4/4] add option to checkout revision --- Dockerfile | 2 -- README.md | 6 ++++-- init.sh | 19 ++++++++++++++----- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1a79f8a..f13a9b5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,6 +20,4 @@ RUN chgrp -R 0 /root && \ # Clean up RUN apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* -USER $USER - CMD ["/init.sh"] diff --git a/README.md b/README.md index f4f17e0..635fa15 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/init.sh b/init.sh index 16a4f16..0523060 100644 --- a/init.sh +++ b/init.sh @@ -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" @@ -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 @@ -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