diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-12 20:45:58 +0100 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-12 21:00:39 +0100 |
| commit | 58181e629a5d51eaee7f6ad08fcbda4411b22d19 (patch) | |
| tree | afac1586dfb7cdf0717eea7d8d36a05725d0f835 | |
| download | cgit-55ab08855462a51370443fe96fc6f5c10f08cac4.tar.gz cgit-55ab08855462a51370443fe96fc6f5c10f08cac4.zip | |
| -rw-r--r-- | Dockerfile | 40 | ||||
| -rw-r--r-- | cgit.conf | 1 | ||||
| -rw-r--r-- | examples/about.md | 3 | ||||
| -rw-r--r-- | examples/cgitrc | 47 | ||||
| -rwxr-xr-x | examples/commit-filter.sh | 11 | ||||
| -rw-r--r-- | httpd.conf | 63 | ||||
| -rw-r--r-- | readme.md | 75 |
7 files changed, 240 insertions, 0 deletions
diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4c23eb2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +FROM debian:13.3-slim AS build + +ARG CGIT_COMMIT=09d24d7cd0b7e85633f2f43808b12871bb209d69 + +# Install build dependencies +RUN apt-get update \ + && apt-get install --assume-yes --no-install-recommends \ + make gcc pkg-config curl xz-utils ca-certificates libzip-dev libssl-dev liblua5.2-dev \ + && rm -rf /var/lib/apt/lists/* + +# Build cgit +ADD --unpack=true https://git.zx2c4.com/cgit/snapshot/cgit-${CGIT_COMMIT}.tar.xz /usr/src +WORKDIR /usr/src/cgit-${CGIT_COMMIT} +COPY cgit.conf . +RUN make get-git && make LUA_PKGCONFIG=lua5.2 && make install && rm -rf $(pwd) + +FROM httpd:2.4.66 AS final + +ARG UID=1000 GID=1000 + +# Create cgit user (used by Apache) +RUN groupadd --gid ${GID} cgit && useradd --uid ${UID} --groups cgit --no-user-group cgit + +# Copy cgit built in previous stage +COPY --from=build /var/www/htdocs/cgit /var/www/htdocs +COPY --from=build /usr/local/lib/cgit/filters /usr/local/lib/cgit/filters +RUN mkdir /var/cache/cgit && chown cgit:cgit /var/cache/cgit + +# Install runtime dependencies +RUN apt-get update \ + && apt-get install --assume-yes --no-install-recommends \ + python3 python3-pygments python3-markdown \ + && rm -rf /var/lib/apt/lists/* + +# HTTP server configuration +COPY httpd.conf /usr/local/apache2/conf/ + +WORKDIR /var/www/htdocs +EXPOSE 80 +VOLUME /srv/git /etc/cgit /usr/local/lib/cgit/filters/commit /srv/cgit diff --git a/cgit.conf b/cgit.conf new file mode 100644 index 0000000..446a846 --- /dev/null +++ b/cgit.conf @@ -0,0 +1 @@ +CGIT_CONFIG = /etc/cgit/cgitrc diff --git a/examples/about.md b/examples/about.md new file mode 100644 index 0000000..34e5902 --- /dev/null +++ b/examples/about.md @@ -0,0 +1,3 @@ +# tvcloud.fr + +Edit this in `about.md`. diff --git a/examples/cgitrc b/examples/cgitrc new file mode 100644 index 0000000..631feaa --- /dev/null +++ b/examples/cgitrc @@ -0,0 +1,47 @@ +# +# Global +# +css=/cgit.css +logo=/cgit.png +# Formatters +source-filter=/usr/local/lib/cgit/filters/syntax-highlighting.py +about-filter=/usr/local/lib/cgit/filters/about-formatting.sh +commit-filter=/usr/local/lib/cgit/filters/commit/commit-filter.sh +# Mimetypes (for plain blobs) +mimetype.gif=image/gif +mimetype.html=text/html +mimetype.jpg=image/jpeg +mimetype.jpeg=image/jpeg +mimetype.pdf=application/pdf +mimetype.png=image/png +mimetype.svg=image/svg+xml + +# +# Cache +# +cache-size=1000 + +# +# Index +# +root-title=Edit this in cgitrc +root-desc=Edit this in cgitrc +root-readme=/srv/cgit/about.md +favicon=/favicon.ico + +# +# Repositories +# +enable-index-owner=1 +enable-index-links=1 +enable-commit-graph=1 +enable-log-filecount=1 +enable-log-linecount=1 +repository-sort=age +remove-suffix=1 +max-stats=year +snapshots=tar.gz zip +clone-url=http://localhost:8080/$CGIT_REPO_URL +readme=:readme.md +# This setting must be set last because settings set after repos are scanned are not applied +scan-path=/srv/git diff --git a/examples/commit-filter.sh b/examples/commit-filter.sh new file mode 100755 index 0000000..3b6dbd2 --- /dev/null +++ b/examples/commit-filter.sh @@ -0,0 +1,11 @@ +regex='' + +# This expression generates links to commits referenced by their SHA1. +regex=$regex' +s|\b([0-9a-fA-F]{7,64})\b|<a href="./?id=\1">\1</a>|g' + +# This expression generates links to a fictional bugtracker. +regex=$regex' +s|#([0-9]+)\b|<a href="http://bugs.example.com/?bug=\1">#\1</a>|g' + +sed -re "$regex" diff --git a/httpd.conf b/httpd.conf new file mode 100644 index 0000000..451603c --- /dev/null +++ b/httpd.conf @@ -0,0 +1,63 @@ +# +# Apache HTTP server configuration +# + +LoadModule rewrite_module modules/mod_rewrite.so +LoadModule mpm_event_module modules/mod_mpm_event.so +LoadModule authn_file_module modules/mod_authn_file.so +LoadModule authn_core_module modules/mod_authn_core.so +LoadModule authz_host_module modules/mod_authz_host.so +LoadModule authz_groupfile_module modules/mod_authz_groupfile.so +LoadModule authz_user_module modules/mod_authz_user.so +LoadModule authz_core_module modules/mod_authz_core.so +LoadModule access_compat_module modules/mod_access_compat.so +LoadModule auth_basic_module modules/mod_auth_basic.so +LoadModule reqtimeout_module modules/mod_reqtimeout.so +LoadModule filter_module modules/mod_filter.so +LoadModule mime_module modules/mod_mime.so +LoadModule log_config_module modules/mod_log_config.so +LoadModule env_module modules/mod_env.so +LoadModule headers_module modules/mod_headers.so +LoadModule setenvif_module modules/mod_setenvif.so +LoadModule version_module modules/mod_version.so +LoadModule unixd_module modules/mod_unixd.so +LoadModule status_module modules/mod_status.so +LoadModule autoindex_module modules/mod_autoindex.so +<IfModule !mpm_prefork_module> + LoadModule cgid_module modules/mod_cgid.so +</IfModule> +<IfModule mpm_prefork_module> + LoadModule cgi_module modules/mod_cgi.so +</IfModule> +LoadModule dir_module modules/mod_dir.so +LoadModule alias_module modules/mod_alias.so + +ServerName localhost +ServerRoot "/usr/local/apache2" +Listen 80 +User cgit +Group cgit + +DocumentRoot "/var/www/htdocs" +<Directory "/var/www/htdocs"> + Options +ExecCGI + AddHandler cgi-script .cgi + RewriteEngine on + # Serve regular files + RewriteCond %{REQUEST_FILENAME} -f + RewriteRule ^ - [L] + # URLs not starting with "cgit.cgi" are internally prefixed with it + RewriteRule "^(?!cgit\.cgi)(.*)" "/cgit.cgi/$1" [L] +</Directory> + +<Files ".ht*"> + Require all denied +</Files> + +ErrorLog /proc/self/fd/2 +LogLevel warn +# Uncomment to see rewrite module trace +# LogLevel info rewrite_module:trace1 +LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined +LogFormat "%h %l %u %t \"%r\" %>s %b" common +CustomLog /proc/self/fd/1 common diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..abf9829 --- /dev/null +++ b/readme.md @@ -0,0 +1,75 @@ +# cgit + +[Docker image](https://hub.docker.com/r/tvanbesi/cgit) + +This project is a [cgit](https://git.zx2c4.com/cgit/about/) docker image. + +It aims to be as simple as possible. No authentication, no SSH, just browsing repositories on a web page. The container doesn't write to the repositories so they can be read-only. + +# Build + +``` +docker build --tag cgit . +``` + +# Run + +## cgit configuration and runtime + +Examples are provided in the `examples` directory. + +* `CGITRC`: Host directory containing a `cgitrc` configuration, see [cgitrc manual](https://manpages.debian.org/trixie/cgit/cgitrc.5.en.html). +* `COMMIT_FILTER`: Host directory containing an executable `commit-filter.sh` script to format Git commit messages. See the `commit-filter` section of the [cgitrc manual](https://manpages.debian.org/trixie/cgit/cgitrc.5.en.html). +* `ABOUT`: Host directory containing `about.md` for the front page "about" section. +* `REPOSITORIES`: Host directory containing your Git repositories. + +## Run with `docker` + +``` +docker run \ + --rm \ + --name cgit \ + --publish 8080:80 \ + --mount type=bind,src=CGITRC,dst=/etc/cgit,ro \ + --mount type=bind,src=COMMIT_FILTER,dst=/usr/local/lib/cgit/filters/commit \ + --mount type=bind,src=ABOUT,dst=/srv/cgit,ro \ + --mount type=bind,src=REPOSITORIES,dst=/srv/git,ro \ + cgit +``` + +Browse the website [here](http://localhost:8080). + +## Run with `docker compose` + +*Example `compose.yaml`:* + +``` +services: + cgit: + build: . + image: cgit + container_name: cgit + ports: + - 8080:80 + volumes: + - CGITRC:/etc/cgit:ro + - COMMIT_FILTER:/usr/local/lib/cgit/filters/commit + - ABOUT:/srv/cgit:ro + - REPOSITORIES:/srv/git:ro +``` + +Browse the website [here](http://localhost:8080). + +# Configuration + +## Repository specific `cgitrc` + +Add a `cgitrc` file at the root of a repository to configure it for cgit. Note that this only works with the `scan-path` setting. + +*Example `cgitrc`:* + +``` +desc=Repository description +owner=Repository owner +section=Repository section +``` |
