aboutsummaryrefslogtreecommitdiff
path: root/gitolite/Dockerfile
blob: 44af1f0b323eb24ccc68ebfc43be17602b1d9f45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# Compile cgit
FROM alpine:3.23.3 AS build

RUN set -x \
 && apk add --no-cache gcc g++ cmake make curl linux-headers musl-dev zlib-dev libressl-dev libintl musl-libintl

# Compile cgit
RUN set -x \
 && wget 'https://git.zx2c4.com/cgit/snapshot/cgit-1.3.tar.xz' \
 && tar -xvf cgit-1.3.tar.xz \
 && make -C /cgit-1.3 get-git \
 && DESTDIR=/pkg NO_REGEX=NeedsStartEnd make -C /cgit-1.3 install


 #&& tar -czvf deps.tar.gz -C /cgit-1.3/pkg .


# Compile cmark-gfm
RUN set -x \
  && wget https://github.com/github/cmark-gfm/archive/refs/tags/0.29.0.gfm.13.tar.gz \
  && tar -xvf 0.29.0.gfm.13.tar.gz \
  && cmake -S /cmark-gfm-0.29.0.gfm.13 -B /cmark-gfm-0.29.0.gfm.13/build \
    -DCMAKE_POLICY_VERSION_MINIMUM=4.0 -DCMAKE_INSTALL_PREFIX=pkg \
  && cmake --build /cmark-gfm-0.29.0.gfm.13/build \
  && cmake --install /cmark-gfm-0.29.0.gfm.13/build

RUN set -x \
  && tar -czvf deps.tar.gz -C pkg .

# Configure nginx & cgit + fcgiwrap
FROM alpine:3.23.3
COPY --from=build /deps.tar.gz /deps.tar.gz

ARG DOMAIN=localhost

RUN set -x \
 && apk add --no-cache \
   curl cmark fail2ban fcgiwrap gcc gitolite libintl libressl-dev linux-headers \
   make musl-dev musl-libintl nginx openrc openssh py3-pygments zlib-dev \
 && tar -xvf /deps.tar.gz

RUN apk update \
 && apk upgrade --no-cache \
 && sed -i '/getty/d' /etc/inittab

COPY cgit/40-fcgiwrap.sh /docker-entrypoint.d/
RUN chmod +x /docker-entrypoint.d/40-fcgiwrap.sh

COPY cgit/cgitrc /etc/

COPY cgit/nginx.conf /
RUN sed "s/\$DOMAIN/$DOMAIN/g" /nginx.conf > /etc/nginx/http.d/default.conf \
  && rm /nginx.conf

RUN addgroup nginx www-data

COPY cgit/about.html /var/www/htdocs/cgit/
COPY cgit/cgit.png /var/www/htdocs/cgit/logo.png
COPY cgit/favicon.ico /var/www/htdocs/cgit/

COPY cgit/css_variable_colors.sh /
COPY cgit/everforest.css /var/www/htdocs/cgit/
RUN sh css_variable_colors.sh

COPY cgit/about-formatting.sh /usr/local/lib/cgit/filters/about-formatting.sh
RUN chmod 755 /usr/local/lib/cgit/filters/about-formatting.sh

# Volume used to store SSH host keys, generated on first run
VOLUME /etc/ssh/keys

RUN rc-update add fail2ban \
 && rc-update add fcgiwrap \
 && rc-update add nginx \
 && rc-update add sshd

# www-data may not be necessary
RUN addgroup fcgiwrap git
#RUN usermod -G nginx,www-data,git nginx
# Configure gitolite
# Install OpenSSH server and Gitolite
# Unlock the automatically-created git user

#RUN addgroup -g 102 -S git \
# && adduser -S -D -H -u 102 -h /var/lib/git -s /sbin/nologin -G git -g git git

RUN git config --system advice.defaultBranchName false

# Volume used to store all Gitolite data (keys, config and repositories), initialized on first run
VOLUME /var/lib/git
RUN chmod 750 /var/lib/git

# Disable unwanted authentications and Disable sftp subsystem
RUN perl -i -pe 's/^#?((?!Kerberos|GSSAPI|Password)\w*Authentication)\s.*/\1 no/;s/^(PubkeyAuthentication) no/\1 yes/' /etc/ssh/sshd_config \
 && perl -i -pe 's/^#?(PermitRootLogin)\s.*/\1 no/' /etc/ssh/sshd_config \
 && perl -i -pe 's/^(Subsystem\ssftp\s)/#\1/' /etc/ssh/sshd_config


# Permissions are fixed in docker-entrypoint.sh
RUN mkdir -p /var/lib/git/local/hooks/common
COPY post-receive /var/lib/git/local/hooks/common/
RUN chmod +x /var/lib/git/local/hooks/common/post-receive

# Configure nginx & cgit + fcgiwrap
#RUN addgroup -g 101 -S nginx \
# && adduser -S -D -H -u 101 -h /var/cache/nginx -s /sbin/nologin -G nginx -g nginx nginx

# Entrypoint responsible for SSH host keys generation, and Gitolite data initialization
COPY docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]

# Expose port 22 to access SSH
EXPOSE 22

# Default command is to run the SSH server
#CMD ["sshd"]
#CMD ["/sbin/init"]
CMD ["/sbin/init"]