diff options
| -rw-r--r-- | Dockerfile | 24 | ||||
| -rw-r--r-- | README.md | 29 | ||||
| -rw-r--r-- | docker-compose.yml | 10 | ||||
| -rw-r--r-- | docker/cgitrc | 25 | ||||
| -rw-r--r-- | docker/entrypoint.sh | 26 | ||||
| -rw-r--r-- | docker/nginx.conf | 47 |
6 files changed, 161 insertions, 0 deletions
diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2801b33 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM debian:bookworm-slim + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + cgit \ + fcgiwrap \ + nginx-light \ + spawn-fcgi \ + git \ + ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +COPY docker/nginx.conf /etc/nginx/nginx.conf +COPY docker/cgitrc /etc/cgitrc +COPY docker/entrypoint.sh /entrypoint.sh + +RUN chmod +x /entrypoint.sh \ + && mkdir -p /run/fcgiwrap /var/cache/nginx /var/lib/git/repos + +EXPOSE 80 + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..94478fa --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# cgit Docker +ホスト側: + +```text +/home/git/repos/ +└── f2b-out-gen +## 起動 + +```bash +docker compose up -d --build +``` + +- ホストポート: `8080` +- コンテナ内 repo パス: `/var/lib/git/repos` + +```text +http://localhost:8080/ +``` + +## environment variables + +```bash +CGIT_PORT=8080 +GIT_REPOS_PATH=/home/git/repos +CGIT_TITLE="Git" +CGIT_DESC="Hosted by cgit" +CGIT_CLONE_BASE_URL="https://git.soulminingrig.com" +docker compose up -d --build +``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..89982bd --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +services: + cgit: + build: + context: . + container_name: cgit-server + ports: + - "${CGIT_PORT:-8080}:80" + volumes: + - "${GIT_REPOS_PATH:-/home/git/repos}:/var/lib/git/repos:ro" + restart: unless-stopped diff --git a/docker/cgitrc b/docker/cgitrc new file mode 100644 index 0000000..25c5f1e --- /dev/null +++ b/docker/cgitrc @@ -0,0 +1,25 @@ +css=/cgit.css +logo=/cgit.png +favicon=/cgit.png + +root-title=Git Repositories +root-desc=public repositories +root-readme= + +virtual-root=/ +scan-path=/var/lib/git/repos + +remove-suffix=1 +enable-http-clone=1 +enable-index-owner=0 +enable-commit-graph=1 +snapshots=tar.gz zip + +clone-url=https://git.example.com/$CGIT_REPO_URL + +cache-root=/var/cache/cgit +cache-size=5000 +cache-static-ttl=60 +cache-dynamic-ttl=30 +cache-repo-ttl=30 +cache-root-ttl=30 diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 0000000..c3ccc41 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,26 @@ +#!/bin/sh +set -eu + +if [ ! -d /var/lib/git/repos ]; then + echo "repository path /var/lib/git/repos does not exist" >&2 + exit 1 +fi + +mkdir -p /run/fcgiwrap +chown www-data:www-data /run/fcgiwrap + +if [ -n "${CGIT_TITLE:-}" ]; then + sed -i "s/^root-title=.*/root-title=${CGIT_TITLE}/" /etc/cgitrc +fi + +if [ -n "${CGIT_DESC:-}" ]; then + sed -i "s/^root-desc=.*/root-desc=${CGIT_DESC}/" /etc/cgitrc +fi + +if [ -n "${CGIT_CLONE_BASE_URL:-}" ]; then + sed -i "s#^clone-url=.*#clone-url=${CGIT_CLONE_BASE_URL}/\\\$CGIT_REPO_URL#" /etc/cgitrc +fi + +spawn-fcgi -s /run/fcgiwrap/fcgiwrap.sock -U www-data -G www-data -- /usr/sbin/fcgiwrap + +exec nginx -g "daemon off;" diff --git a/docker/nginx.conf b/docker/nginx.conf new file mode 100644 index 0000000..0a5cf5d --- /dev/null +++ b/docker/nginx.conf @@ -0,0 +1,47 @@ +user www-data; +worker_processes auto; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + access_log /dev/stdout; + error_log /dev/stderr warn; + + sendfile on; + tcp_nopush on; + keepalive_timeout 65; + + server { + listen 80 default_server; + server_name _; + + root /usr/share/cgit; + index cgit.css; + + location /cgit.css { + try_files $uri =404; + } + + location /cgit.png { + try_files $uri =404; + } + + location /favicon.ico { + try_files /cgit.png =404; + } + + location / { + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME /usr/lib/cgit/cgit.cgi; + fastcgi_param PATH_INFO $uri; + fastcgi_param QUERY_STRING $query_string; + fastcgi_pass unix:/run/fcgiwrap/fcgiwrap.sock; + fastcgi_read_timeout 60s; + } + } +} |
