feat(): add Docker entrypoint

This allows to pre-fetch scripts form a GIT repository.
This commit is contained in:
Nicolas Carlier 2018-07-06 14:07:09 +00:00
parent b9e5bbaeae
commit 4b586772ae
2 changed files with 24 additions and 0 deletions

View File

@ -40,6 +40,9 @@ RUN apk add --no-cache git openssh-client jq
# Install binary and default scripts
COPY --from=builder /go/src/$REPOSITORY/$ARTIFACT/release/$ARTIFACT-linux-amd64 /usr/local/bin/$ARTIFACT
COPY --from=builder /go/src/$REPOSITORY/$ARTIFACT/scripts /opt/scripts
COPY docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
# Define command
CMD webhookd

21
docker-entrypoint.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/sh
# Error function
die() { echo "error: $@" 1>&2 ; exit 1; }
if [ ! -z "$APP_SCRIPTS_GIT_URL" ]
then
[ ! -f "$APP_SCRIPTS_GIT_KEY" ] && die "Git clone key not found."
export APP_SCRIPTS_DIR=${APP_SCRIPTS_DIR:-/opt/scripts-git}
export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
mkdir -p $APP_SCRIPTS_DIR
echo "Cloning $APP_SCRIPTS_GIT_URL into $APP_SCRIPTS_DIR ..."
ssh-agent sh -c 'ssh-add ${APP_SCRIPTS_GIT_KEY}; git clone --depth 1 --single-branch ${APP_SCRIPTS_GIT_URL} ${APP_SCRIPTS_DIR}'
[ $? != 0 ] && die "Unable to clone repository"
fi
exec "$@"