summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Dockerfile8
-rw-r--r--README29
-rw-r--r--config.env3
-rw-r--r--entrypoint.sh8
-rw-r--r--sshd_config6
-rwxr-xr-xstart_container.sh12
6 files changed, 46 insertions, 20 deletions
diff --git a/Dockerfile b/Dockerfile
index 35208e9..86352b4 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -7,14 +7,16 @@ RUN apk add --no-cache \
7 fcgiwrap \ 7 fcgiwrap \
8 spawn-fcgi \ 8 spawn-fcgi \
9 gettext \ 9 gettext \
10 openssl 10 openssl \
11 openssh-server
11 12
12COPY cgitrc.template /etc/cgitrc.template 13COPY cgitrc.template /etc/cgitrc.template
13COPY Caddyfile /etc/caddy/Caddyfile 14COPY Caddyfile /etc/caddy/Caddyfile
15COPY sshd_config /etc/ssh/sshd_config
14COPY entrypoint.sh /entrypoint.sh 16COPY entrypoint.sh /entrypoint.sh
15RUN chmod +x /entrypoint.sh 17RUN chmod +x /entrypoint.sh
16 18
17# 80 required for Let's Encrypt HTTP-01 challenge, 443 for HTTPS 19# 80 required for Let's Encrypt HTTP-01 challenge, 443 for HTTPS, 22 for git SSH
18EXPOSE 80 443 20EXPOSE 80 443 22
19 21
20ENTRYPOINT ["/entrypoint.sh"] 22ENTRYPOINT ["/entrypoint.sh"]
diff --git a/README b/README
index 99ecf57..c71655b 100644
--- a/README
+++ b/README
@@ -1,12 +1,11 @@
1CGIT-CADDY CONTAINER 1CGIT CONTAINER
2 2
3Cgit with automatic HTTPS (cgit + caddy + Let's Encrypt). 3Cgit with automatic HTTPS (cgit + caddy + Let's Encrypt).
4 4
5Requirements: 5Requirements:
6 - Public IPv4 address pointed to this machine 6 - Public IPv4 address
7 - /git directory on host for bare git repos 7 - Domain pointing to the IP
8 - Domain name pointing to the public IP 8 - /git directory for bare repos
9TLS certificates are auto-generated by Caddy and stored in a container volume.
10 9
11Host setup (one-time): 10Host setup (one-time):
12 cat > /etc/sysctl.d/99-container-routing.conf << 'EOF' 11 cat > /etc/sysctl.d/99-container-routing.conf << 'EOF'
@@ -14,12 +13,9 @@ Host setup (one-time):
14 net.ipv4.conf.enp1s0.proxy_arp=1 13 net.ipv4.conf.enp1s0.proxy_arp=1
15 EOF 14 EOF
16 sysctl -p /etc/sysctl.d/99-container-routing.conf 15 sysctl -p /etc/sysctl.d/99-container-routing.conf
17 mkdir -p /git 16 mkdir -p /git/.ssh
18 17
19Build: 18Run:
20 podman build -t cgit-caddy .
21
22Run (first time or after changes):
23 ./start_container.sh 19 ./start_container.sh
24 20
25Run (manual): 21Run (manual):
@@ -31,19 +27,25 @@ Run (manual):
31 --env-file config.env \ 27 --env-file config.env \
32 -v cgit_data:/data \ 28 -v cgit_data:/data \
33 -v /git:/git \ 29 -v /git:/git \
34 localhost/cgit-caddy 30 localhost/cgit
35 31
36 sleep 2 32 sleep 2
37 podman exec cgit ip addr add 37.27.166.242/32 dev eth0 33 podman exec cgit ip addr add 37.27.166.242/32 dev eth0
38 ip route add 37.27.166.242/32 via 10.89.0.2 34 ip route add 37.27.166.242/32 via 10.89.0.2
39 35
36SSH keys:
37 Drop .pub files in /git/.ssh/, they're combined into authorized_keys on run.
38
39Create repo:
40 git init --bare /git/myrepo
41
40Restart: 42Restart:
41 podman restart cgit 43 podman restart cgit
42 44
43Stop: 45Stop:
44 podman stop cgit && podman rm cgit && ip route del 37.27.166.242/32 46 podman stop cgit && podman rm cgit && ip route del 37.27.166.242/32
45 47
46Cleanup (remove everything): 48Cleanup:
47 podman stop cgit 49 podman stop cgit
48 podman rm cgit 50 podman rm cgit
49 podman volume rm cgit_data 51 podman volume rm cgit_data
@@ -55,6 +57,3 @@ Logs:
55 57
56Shell: 58Shell:
57 podman exec -it cgit sh 59 podman exec -it cgit sh
58
59Create repo:
60 git init --bare /git/myrepo
diff --git a/config.env b/config.env
index 417ce14..0f623f9 100644
--- a/config.env
+++ b/config.env
@@ -10,7 +10,8 @@ NETWORK=public-routed
10 10
11# Paths (inside container) 11# Paths (inside container)
12GIT_PATH=/git 12GIT_PATH=/git
13XDG_DATA_HOME=/data # mounted as caddy_data volume, stores SSL certs 13# Caddy stores SSL certs here, mounted as ${CONTAINER_NAME}_data volume
14XDG_DATA_HOME=/data
14CGIT_CSS=/cgit.css 15CGIT_CSS=/cgit.css
15CGIT_LOGO=/cgit.png 16CGIT_LOGO=/cgit.png
16FCGI_SOCK=/run/fcgiwrap.sock 17FCGI_SOCK=/run/fcgiwrap.sock
diff --git a/entrypoint.sh b/entrypoint.sh
index bf3753f..3e2dcc0 100644
--- a/entrypoint.sh
+++ b/entrypoint.sh
@@ -13,6 +13,14 @@ fi
13# Generate cgitrc from template 13# Generate cgitrc from template
14envsubst < /etc/cgitrc.template > /etc/cgitrc 14envsubst < /etc/cgitrc.template > /etc/cgitrc
15 15
16# Setup SSH
17ssh-keygen -A # Generate host keys if missing
18mkdir -p /git/.ssh
19touch /git/.ssh/authorized_keys
20chmod 700 /git/.ssh
21chmod 600 /git/.ssh/authorized_keys
22/usr/sbin/sshd
23
16spawn-fcgi -s ${FCGI_SOCK} /usr/bin/fcgiwrap 24spawn-fcgi -s ${FCGI_SOCK} /usr/bin/fcgiwrap
17chmod 666 ${FCGI_SOCK} 25chmod 666 ${FCGI_SOCK}
18 26
diff --git a/sshd_config b/sshd_config
new file mode 100644
index 0000000..ab4c469
--- /dev/null
+++ b/sshd_config
@@ -0,0 +1,6 @@
1Port 22
2PermitRootLogin prohibit-password
3PasswordAuthentication no
4PubkeyAuthentication yes
5AuthorizedKeysFile /git/.ssh/authorized_keys
6Subsystem sftp /usr/lib/ssh/sftp-server
diff --git a/start_container.sh b/start_container.sh
index bf1c167..25fcb10 100755
--- a/start_container.sh
+++ b/start_container.sh
@@ -17,6 +17,16 @@ podman stop ${CONTAINER_NAME} 2>/dev/null || true
17podman rm ${CONTAINER_NAME} 2>/dev/null || true 17podman rm ${CONTAINER_NAME} 2>/dev/null || true
18ip route del ${PUBLIC_IP}/32 2>/dev/null || true 18ip route del ${PUBLIC_IP}/32 2>/dev/null || true
19 19
20# Rebuild authorized_keys from .pub files
21mkdir -p /git/.ssh
22rm -f /git/.ssh/authorized_keys
23cat /git/.ssh/*.pub > /git/.ssh/authorized_keys 2>/dev/null || true
24chmod 600 /git/.ssh/authorized_keys
25
26# Build image
27echo "Building image..."
28podman build -t cgit "$(dirname "$0")"
29
20# Run container 30# Run container
21podman run -d \ 31podman run -d \
22 --name ${CONTAINER_NAME} \ 32 --name ${CONTAINER_NAME} \
@@ -26,7 +36,7 @@ podman run -d \
26 --env-file "$(dirname "$0")/config.env" \ 36 --env-file "$(dirname "$0")/config.env" \
27 -v ${CONTAINER_NAME}_data:/data \ 37 -v ${CONTAINER_NAME}_data:/data \
28 -v /git:/git \ 38 -v /git:/git \
29 localhost/cgit-caddy 39 localhost/cgit
30 40
31# Setup public IP 41# Setup public IP
32sleep 2 42sleep 2