12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
+ # HOW TO USE THIS CONTAINER:
16
+ #
17
+ # For most users, the simplest way to use this container is to mount a volume
18
+ # on /git. The only commandline argument (or env var) that is really required
19
+ # is `--repo` ($GIT_SYNC_REPO). Everything else is optional (run this with
20
+ # `--man` for details).
21
+ #
22
+ # This container will run as UID:GID 65533:65533 by default, and unless you
23
+ # change that, you do not need to think about permissions much. If you run
24
+ # into permissions problems, this might help:
25
+ #
26
+ # - User does not mount a volume
27
+ # => should work, but limited utility
28
+ #
29
+ # - User mounts a new docker volume on /git
30
+ # => should work
31
+ #
32
+ # - User mounts an existing docker volume on /git
33
+ # => if the volume already exists with compatible permissions it should work
34
+ # => if the volume already exists with different permissions you can either
35
+ # set the container UID or GID(s) or you can chown the volume
36
+ #
37
+ # - User mounts an existing dir on /git
38
+ # => set container UID or GID(s) to be able to access that dir
39
+ #
40
+ # - User sets a different UID and git-sync GID
41
+ # => should work
42
+ #
43
+ # - User sets a different GID
44
+ # => either add the git-sync GID or else set --root, mount a volume,
45
+ # and manage volume permissions to access that volume
46
+
15
47
FROM {ARG_FROM}
16
48
17
49
RUN apt-get update \
@@ -24,14 +56,33 @@ RUN apt-get update \
24
56
openssh-client \
25
57
&& rm -rf /var/lib/apt/lists/*
26
58
27
- # By default we will run as this user.. .
59
+ # Add the default UID to /etc/passwd so SSH is satisfied .
28
60
RUN echo "git-sync:x:65533:65533::/tmp:/sbin/nologin" >> /etc/passwd
29
- # ...but the user might choose a different UID and pass --add-user
30
- # which needs to be able to write to /etc/passwd.
61
+ # A user might choose a different UID and set the --add-user flag, which needs
62
+ # to be able to write to /etc/passwd.
31
63
RUN chmod 0666 /etc/passwd
32
64
33
- ADD bin/{ARG_OS}_{ARG_ARCH}/{ARG_BIN} /{ARG_BIN}
65
+ # Add the default GID to /etc/group for completeness.
66
+ RUN echo "git-sync:x:65533:git-sync" >> /etc/group
34
67
35
- WORKDIR /tmp
68
+ # Make a directory that can be used to mount volumes. Git-sync itself does not
69
+ # default the --root ($GIT_SYNC_ROOT) flag, but we can set a default here,
70
+ # which makes the container image easier to use. Setting the mode to include
71
+ # group-write allows users to run this image as a different user, as long as
72
+ # they use our git-sync group. If the user needs a different group or sets
73
+ # $GIT_SYNC_ROOT or --root, their values will override this, and we assume they
74
+ # are handling permissions themselves.
75
+ ENV GIT_SYNC_ROOT=/git
76
+ RUN mkdir -m 02775 /git && chown 65533:65533 /git
77
+
78
+ # Run as non-root by default. There's simply no reason to run as root.
36
79
USER 65533:65533
80
+
81
+ # Setting HOME ensures that whatever UID this ultimately runs as can write to
82
+ # files like ~/.gitconfig.
83
+ ENV HOME=/tmp
84
+ WORKDIR /tmp
85
+
86
+ # Just dump the binary in the root.
87
+ ADD bin/{ARG_OS}_{ARG_ARCH}/{ARG_BIN} /{ARG_BIN}
37
88
ENTRYPOINT ["/{ARG_BIN}"]
0 commit comments