aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose Quintana <[email protected]>2022-05-11 11:14:06 +0200
committerGitHub <[email protected]>2022-05-11 11:14:06 +0200
commit64c21817c205c871cbb1eaeefa666f4221ad6520 (patch)
treee77c746c47f6355c49dac8c44f53dc8131ce2366
parentaed4f5bf7a4d06a1a7e365df55d951c3a20cd42b (diff)
parentb4850173260c9f5f648955726ce62c9dc157e982 (diff)
downloadalpine-cgit-64c21817c205c871cbb1eaeefa666f4221ad6520.tar.xz
alpine-cgit-64c21817c205c871cbb1eaeefa666f4221ad6520.zip
Merge pull request #9 from joseluisq/feature/custom_config_file_support
feat: custom configuration file support via new `USE_CUSTOM_CONFIG` env
-rw-r--r--Dockerfile32
-rw-r--r--README.md27
-rwxr-xr-xdocker-entrypoint.sh26
3 files changed, 70 insertions, 15 deletions
diff --git a/Dockerfile b/Dockerfile
index b6729ed..860ef05 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -6,7 +6,9 @@ ENV VERSION=${VERSION}
# CGit
ARG CGIT_VERSION=1.2.3-r2
ENV CGIT_VERSION=${CGIT_VERSION}
-ENV CGIT_TITLE="cgit"
+
+# CGit default options
+ENV CGIT_TITLE="CGit"
ENV CGIT_DESC="The hyperfast web frontend for Git repositories"
ENV CGIT_VROOT="/"
ENV CGIT_SECTION_FROM_STARTPATH=0
@@ -35,19 +37,29 @@ RUN set -eux \
&& true
COPY cgit/cgit.conf /tmp/cgitrc.tmpl
+COPY docker-entrypoint.sh /
COPY nginx/nginx.conf /etc/nginx/nginx.conf
COPY nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
-VOLUME [ "/srv/git", "/var/cache/cgit" ]
+RUN set -eux \
+ && echo "Creating application directories..." \
+ && mkdir -p /var/cache/cgit \
+ && mkdir -p /srv/git \
+ && true
+
+RUN set -eux \
+ && echo "Testing Nginx server configuration files..." \
+ && nginx -c /etc/nginx/nginx.conf -t \
+ && true
+
+ENTRYPOINT [ "/docker-entrypoint.sh" ]
+
+EXPOSE 80
+
+STOPSIGNAL SIGQUIT
+
+CMD [ "nginx", "-g", "daemon off;" ]
-CMD chown nginx:nginx /var/cache/cgit \
- && chmod u+g /var/cache/cgit \
- && envsubst < /tmp/cgitrc.tmpl > /etc/cgitrc \
- && spawn-fcgi \
- -u nginx -g nginx \
- -s /var/run/fcgiwrap.sock \
- -n -- /usr/bin/fcgiwrap \
- & nginx -g "daemon off;"
# Metadata
LABEL org.opencontainers.image.vendor="Jose Quintana" \
diff --git a/README.md b/README.md
index f3992cd..6960ba4 100644
--- a/README.md
+++ b/README.md
@@ -39,12 +39,17 @@ docker run --rm -it \
FROM joseluisq/alpine-cgit
```
-## Volumes
+## Key container paths
-- `/srv/git`: Place for Git repositories.
-- `/var/cache/cgit`: CGit caching of generated HTML.
+- `/etc/cgitrc`: Default CGit configuration file.
+- `/srv/git`: Default directory for Git repositories scanned by CGit.
+- `/var/cache/cgit`: Default CGit caching directory of generated HTML.
-## Settings via env variables
+Note that all these paths can be overwritten via [Bind Mounts](https://docs.docker.com/storage/bind-mounts/) or [Docker Volumes](https://docs.docker.com/storage/volumes/).
+
+## Settings via environment variables
+
+CGit Docker image can be configured via environment variables. This is the default behaviour.
- `CGIT_TITLE`: Website title.
- `CGIT_DESC`: Website description.
@@ -52,7 +57,19 @@ FROM joseluisq/alpine-cgit
- `CGIT_SECTION_FROM_STARTPATH`: How many path elements from each repo path to use as a default section name.
- `CGIT_MAX_REPO_COUNT`: Number of entries to list per page on the repository index page.
-See default file configuration at [cgit/cgit.conf](./cgit/cgit.conf)
+## Settings via custom configration file
+
+By default this Docker image will use a template file located at [cgit/cgit.conf](./cgit/cgit.conf) which is replaced with the env settings (mentioned above) at start up time.
+
+However if you want to use a custom `/etc/cgitrc` file then follow these steps:
+
+1. Provide the env variable `USE_CUSTOM_CONFIG=true` to prevent using the default config file.
+2. Provide the custom config file as a [Bind Mount](https://docs.docker.com/storage/bind-mounts/) or [Docker Volume](https://docs.docker.com/storage/volumes/). For example `--volume my-config-file:/etc/cgitrc`
+3. Provide the `cache-root` option in your config file. For example `cache-root=/var/cache/cgit`
+4. Provide the `scan-path` option in your config file. For example `scan-path=/srv/git`
+5. Provide the repositories folder as a [Bind Mount](https://docs.docker.com/storage/bind-mounts/) or [Docker Volume](https://docs.docker.com/storage/volumes/). For example `--volume my-repos:/srv/git`
+
+See [`cgitrc` man page](https://linux.die.net/man/5/cgitrc) for more detailed information.
## Contributions
diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh
new file mode 100755
index 0000000..2e875a4
--- /dev/null
+++ b/docker-entrypoint.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+set -e
+
+# Check for incomming Nginx server commands or subcommands only
+if [ "$1" = "nginx" ] || [ "${1#-}" != "$1" ]; then
+ if [ "${1#-}" != "$1" ]; then
+ set -- nginx "$@"
+ fi
+
+ chown nginx:nginx /var/cache/cgit
+ chmod u+g /var/cache/cgit
+
+ # Replace environment variables only if `USE_CUSTOM_CONFIG` is not defined or equal to `false`
+ if [[ -z "$USE_CUSTOM_CONFIG" ]] || [[ "$USE_CUSTOM_CONFIG" = "false" ]]; then
+ envsubst < /tmp/cgitrc.tmpl > /etc/cgitrc
+ fi
+
+ spawn-fcgi \
+ -u nginx -g nginx \
+ -s /var/run/fcgiwrap.sock \
+ -n -- /usr/bin/fcgiwrap \
+ & exec "$@"
+else
+ exec "$@"
+fi