diff --git a/Dockerfile b/Dockerfile index c13d23b..635809c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..c9704dd --- /dev/null +++ b/docker-entrypoint.sh @@ -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 "$@" +