Skip to content

Commit 947e04a

Browse files
author
Ahmad Iqbal Ali
authored
use alpine base image (#4)
1 parent aa3267e commit 947e04a

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

Dockerfile

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
1-
FROM debian:stretch
1+
FROM alpine:3.6
22

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

5-
ARG USER=1001
6+
RUN addgroup -g 1000 -S git && \
7+
adduser -u 1000 -S git -G git
68

7-
ADD [--chown=$USER:root] init.sh /
8-
RUN chmod +x /init.sh
9-
10-
USER root
11-
12-
RUN mkdir /root/.ssh/ && \
9+
RUN mkdir /home/git/.ssh/ && \
10+
chown git /home/git/.ssh && \
1311
mkdir /repository && \
14-
touch /root/.ssh/known_hosts && \
15-
echo "\nStrictHostKeyChecking no" >> /etc/ssh/ssh_config
16-
17-
RUN chgrp -R 0 /root && \
18-
chmod -R g=u /root
19-
20-
# Clean up
21-
RUN apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
12+
chown git /repository && \
13+
touch /home/git/.ssh/known_hosts && \
14+
echo "" >> /etc/ssh/ssh_config && \
15+
echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config &&\
16+
chown git /etc/ssh/ssh_config
2217

23-
USER $USER
18+
USER git
2419

2520
CMD ["/init.sh"]

init.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
if [ -z "$REPO_LINK" ]; then
44
echo -e "\033[1;91mERROR:\033[0m REPO_LINK env variable is required"
@@ -17,26 +17,26 @@ echo "repository : $REPO_LINK"
1717
echo "branch : $REPO_BRANCH"
1818
echo "tag : $REPO_TAG"
1919
echo "revision : $REPO_REVISION"
20+
2021
# check if credentials files exist
2122
if [[ -f "/key/$REPO_KEY" ]] ; then
2223
echo "key file : $REPO_KEY"
23-
cp /key/$REPO_KEY /root/.ssh/id_rsa
24-
chmod 600 /root/.ssh/id_rsa
25-
ssh-keyscan -H gitlab.com >> /root/.ssh/known_hosts
24+
cp /key/$REPO_KEY /home/git/.ssh/id_rsa
25+
chmod 600 /home/git/.ssh/id_rsa
26+
ssh-keyscan -H gitlab.com >> /home/git/.ssh/known_hosts
2627
fi
2728

2829
if [ ! -z "$REPO_USER" ] && [ ! -z "$REPO_PASS" ]; then
2930
# clone with repository username & password
3031
echo "credentials: username and password"
3132
git clone -b $REPO_BRANCH https://$REPO_USER:$REPO_PASS@$REPO_LINK /repository
3233
else
33-
if [[ ! -f "/root/.ssh/id_rsa" ]] ; then
34+
if [[ ! -f "/home/git/.ssh/id_rsa" ]] ; then
3435
echo -e "\033[1;93mWARNING:\033[0m REPO_USER, REPO_PASS env variables or SSH deployment key missing"
3536
else
3637
# clone public repository or using ssh deployment key
3738
echo "credentials: RSA key"
3839
fi
39-
ls -lah /repository
4040
git clone -b $REPO_BRANCH $REPO_LINK /repository
4141
fi
4242

0 commit comments

Comments
 (0)