summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.env.example7
-rw-r--r--.gitignore1
-rw-r--r--Readme.md8
-rw-r--r--docker-compose.yml31
-rw-r--r--docker/cgit/Dockerfile23
-rwxr-xr-xdocker/cgit/docker-entrypoint.sh14
-rwxr-xr-xdocker/cgit/docker-init.py22
7 files changed, 106 insertions, 0 deletions
diff --git a/.env.example b/.env.example
new file mode 100644
index 0000000..4294059
--- /dev/null
+++ b/.env.example
@@ -0,0 +1,7 @@
+DOMAIN=git.example.org
+TRAEFIK_NETWORK=traefik
+
+REPOSITORIES_PATH=/repositories
+
+CGIT_CLONE_PREFIX="https://${DOMAIN}${REPOSITORIES_PATH} ssh://${DOMAIN}${REPOSITORIES_PATH}"
+CGIT_SCAN_PATH=${REPOSITORIES_PATH}
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..4c49bd7
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+.env
diff --git a/Readme.md b/Readme.md
new file mode 100644
index 0000000..16f68a0
--- /dev/null
+++ b/Readme.md
@@ -0,0 +1,8 @@
+Can be set up with any directory containing git repositories.
+
+For example with a mounted cifs directory:
+
+**/etc/fstab**
+```
+//REMOTE_DOMAIN/REMOTE_PATH /LOCAL_PATH cifs credentials=CREDENTIALS_FILE,file_mode=0777,dir_mode=0777,uid=USER,gid=GROUP,nofail 0 0
+```
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..28b327b
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,31 @@
+version: "3.7"
+
+services:
+ cgit:
+ build:
+ context: "docker/cgit"
+ dockerfile: "Dockerfile"
+ env_file: .env
+ volumes:
+ - "${REPOSITORIES_PATH}:${CGIT_SCAN_PATH}"
+ networks:
+ - traefik
+ labels:
+ - "traefik.enable=true"
+ - "traefik.http.routers.cgit.rule=Host(`${DOMAIN}`) && PathPrefix(`/cgit`)"
+ - "traefik.http.routers.cgit.entrypoints=websecure"
+ - "traefik.http.routers.cgit.tls=true"
+ - "traefik.http.routers.cgit.tls.certresolver=letsencrypt"
+
+ - "traefik.http.routers.cgit-root.rule=Host(`${DOMAIN}`)"
+ - "traefik.http.routers.cgit-root.entrypoints=websecure"
+ - "traefik.http.routers.cgit-root.tls=true"
+ - "traefik.http.routers.cgit-root.tls.certresolver=letsencrypt"
+ - "traefik.http.middlewares.cgit-root.redirectregex.regex=${DOMAIN}/(.*)"
+ - "traefik.http.middlewares.cgit-root.redirectregex.replacement=${DOMAIN}/cgit/$${1}"
+ - "traefik.http.routers.cgit-root.middlewares=cgit-root"
+
+networks:
+ traefik:
+ external: true
+ name: "${TRAEFIK_NETWORK}"
diff --git a/docker/cgit/Dockerfile b/docker/cgit/Dockerfile
new file mode 100644
index 0000000..187cf10
--- /dev/null
+++ b/docker/cgit/Dockerfile
@@ -0,0 +1,23 @@
+FROM httpd
+
+
+EXPOSE 80
+EXPOSE 443
+
+
+ARG DEBIAN_FRONTEND=noninteractive
+RUN apt-get update
+
+RUN apt-get install -y \
+ cgit \
+ python3
+
+RUN : \
+ && a2enmod cgi
+
+
+COPY docker-init.py /
+COPY docker-entrypoint.sh /
+
+ENTRYPOINT ["/docker-entrypoint.sh"]
+CMD ["init"]
diff --git a/docker/cgit/docker-entrypoint.sh b/docker/cgit/docker-entrypoint.sh
new file mode 100755
index 0000000..102d46c
--- /dev/null
+++ b/docker/cgit/docker-entrypoint.sh
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+
+if [ "${1}" = "init" ]; then
+ service apache2 start
+
+ /docker-init.py
+
+ # TODO: https://git-scm.com/docs/gitweb#_generating_projects_list_using_gitweb
+
+ tail -f /dev/null
+else
+ exec "$@"
+fi
diff --git a/docker/cgit/docker-init.py b/docker/cgit/docker-init.py
new file mode 100755
index 0000000..c5b47b8
--- /dev/null
+++ b/docker/cgit/docker-init.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python3
+
+
+import sys, os
+import re
+
+
+with open("/etc/cgitrc", "r") as file: cgitrc = file.read()
+
+
+for env_name, env_value in os.environ.items():
+ if env_name.startswith('CGIT_'):
+ rc_name = env_name[5:].lower().replace('_', '-')
+ p = re.compile(r"({0}=)([\w\d]+)".format(rc_name))
+
+ if p.search(cgitrc):
+ cgitrc = p.sub(r"\1{0}".format(env_value), cgitrc)
+ else:
+ cgitrc += ("\n" + "{0}={1}".format(rc_name, env_value) + "\n")
+
+
+with open("/etc/cgitrc", "w") as file: file.write(cgitrc)