Skip to content

Commit

Permalink
use alpine base image (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad Iqbal Ali authored Nov 13, 2018
1 parent aa3267e commit 947e04a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
31 changes: 13 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
FROM debian:stretch
FROM alpine:3.6

RUN apt-get update && apt-get install -y git
COPY init.sh /
RUN apk add --update git openssh

ARG USER=1001
RUN addgroup -g 1000 -S git && \
adduser -u 1000 -S git -G git

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

USER root

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

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/*
chown git /repository && \
touch /home/git/.ssh/known_hosts && \
echo "" >> /etc/ssh/ssh_config && \
echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config &&\
chown git /etc/ssh/ssh_config

USER $USER
USER git

CMD ["/init.sh"]
12 changes: 6 additions & 6 deletions init.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh

if [ -z "$REPO_LINK" ]; then
echo -e "\033[1;91mERROR:\033[0m REPO_LINK env variable is required"
Expand All @@ -17,26 +17,26 @@ 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"
cp /key/$REPO_KEY /root/.ssh/id_rsa
chmod 600 /root/.ssh/id_rsa
ssh-keyscan -H gitlab.com >> /root/.ssh/known_hosts
cp /key/$REPO_KEY /home/git/.ssh/id_rsa
chmod 600 /home/git/.ssh/id_rsa
ssh-keyscan -H gitlab.com >> /home/git/.ssh/known_hosts
fi

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
else
if [[ ! -f "/root/.ssh/id_rsa" ]] ; then
if [[ ! -f "/home/git/.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 Down

0 comments on commit 947e04a

Please sign in to comment.