From cea11bf982fa235f9a186a4a8d55450a44397e77 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Thu, 29 Dec 2016 11:57:30 +0100 Subject: [PATCH] Add Docker support. --- .dockerignore | 1 + Dockerfile | 13 +++++++++++++ README.rst | 10 ++++++++++ entrypoint.sh | 22 ++++++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100755 entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c1c9f4d --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.git* diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..825e437 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM python:3-alpine +MAINTAINER Tecnativa +ENTRYPOINT ["/usr/src/app/entrypoint.sh"] +ENV GIT_AUTHOR_NAME=git-aggregator \ + EMAIL=https://hub.docker.com/r/tecnativa/git-aggregator +# HACK Install git >= 2.11, to have --shallow-since +# TODO Remove HACK when python:alpine is alpine >= v3.5 +RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.5/main git +COPY . /usr/src/app +RUN pip install --no-cache-dir --editable /usr/src/app +RUN python -m compileall /usr/src/app/ +VOLUME /repos +WORKDIR /repos diff --git a/README.rst b/README.rst index e82ed56..7333b11 100644 --- a/README.rst +++ b/README.rst @@ -117,6 +117,16 @@ Only aggregate a specific repository using `fnmatch`_: .. _fnmatch: https://docs.python.org/2/library/fnmatch.html +Dockerized version +------------------ + +You can use ``git-aggregator`` from CLI without installing anything but Docker: + +.. code-block:: bash + + $ docker run -it --rm -v $(pwd):/repos tecnativa/git-aggregator -c repos.yaml + + Credits ======= diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..b14e237 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +# Default to the gitaggregate command if we get an option as first argument +if [ "${1:0:1}" == - ]; then + cmd="gitaggregate $@" +else + cmd="$@" +fi + +# Add SETUID & SETGUID to binaries to make them run with the same user as +# `/repos`'s owner. In case you mount `/repos` from your host computer. This is +# useful because otherwise all files and folders would be owned by `root`. +uid=$(stat -c %u /repos) +if [ $uid -ne $(id -u root) ]; then + gid=$(stat -c %g /repos) + addgroup -g $gid threpwood + adduser -G threpwood -u $uid guybrush -DH -s /bin/sh + + exec su guybrush -c "$cmd" +else + exec "$cmd" +fi