From 947e04a40e7ccf18e593d139033d1b49a3386857 Mon Sep 17 00:00:00 2001 From: Ahmad Iqbal Ali Date: Tue, 13 Nov 2018 09:29:46 +0500 Subject: [PATCH] use alpine base image (#4) --- Dockerfile | 31 +++++++++++++------------------ init.sh | 12 ++++++------ 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1a79f8a..1ae3e7f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/init.sh b/init.sh index 0523060..bc80001 100644 --- a/init.sh +++ b/init.sh @@ -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" @@ -17,12 +17,13 @@ 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 @@ -30,13 +31,12 @@ if [ ! -z "$REPO_USER" ] && [ ! -z "$REPO_PASS" ]; then 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