|
| 1 | +FROM debian:bookworm-slim |
| 2 | + |
| 3 | +RUN apt-get update \ |
| 4 | + && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ |
| 5 | + fcgiwrap \ |
| 6 | + git \ |
| 7 | + nginx-light \ |
| 8 | + && rm -rf /var/lib/apt/lists/* |
| 9 | + |
| 10 | +RUN mkdir -p /var/lib/git /run/fcgiwrap |
| 11 | + |
| 12 | +COPY --chmod=755 <<'EOF' /entrypoint.sh |
| 13 | +#!/usr/bin/env bash |
| 14 | +set -euo pipefail |
| 15 | + |
| 16 | +: "${USERNAME:?set USERNAME for HTTP basic auth}" |
| 17 | +: "${BCRYPT_PASSWORD:?set BCRYPT_PASSWORD containing a bcrypt hash}" |
| 18 | +: "${REPO_NAME:?set REPO_NAME for the bare repository (without .git)}" |
| 19 | + |
| 20 | +htpasswd_file=/etc/nginx/conf.d/htpasswd |
| 21 | + |
| 22 | +echo "${USERNAME}:${BCRYPT_PASSWORD}" > "${htpasswd_file}" |
| 23 | +chown www-data:www-data "${htpasswd_file}" |
| 24 | +chmod 640 "${htpasswd_file}" |
| 25 | + |
| 26 | +repo_path="/var/lib/git/${REPO_NAME}.git" |
| 27 | +if [ ! -d "${repo_path}" ]; then |
| 28 | + git init --bare "${repo_path}" |
| 29 | + chown -R www-data:www-data "${repo_path}" |
| 30 | +fi |
| 31 | + |
| 32 | +cat > /etc/nginx/sites-available/default <<'NGINXCONF' |
| 33 | +server { |
| 34 | + listen 8080 default_server; |
| 35 | + listen [::]:8080 default_server; |
| 36 | + server_name _; |
| 37 | + |
| 38 | + location / { |
| 39 | + auth_basic "qault git server"; |
| 40 | + auth_basic_user_file /etc/nginx/conf.d/htpasswd; |
| 41 | + |
| 42 | + include fastcgi_params; |
| 43 | + fastcgi_param GIT_HTTP_EXPORT_ALL ""; |
| 44 | + fastcgi_param GIT_PROJECT_ROOT /var/lib/git; |
| 45 | + fastcgi_param PATH_INFO $uri; |
| 46 | + fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend; |
| 47 | + fastcgi_param REMOTE_USER $remote_user; |
| 48 | + fastcgi_pass unix:{{SOCKET_PATH}}; |
| 49 | + } |
| 50 | +} |
| 51 | +NGINXCONF |
| 52 | + |
| 53 | +mkdir -p /run/fcgiwrap |
| 54 | +chown www-data:www-data /run/fcgiwrap |
| 55 | + |
| 56 | +socket_path="/run/fcgiwrap/fcgiwrap.sock" |
| 57 | +sed -i "s|{{SOCKET_PATH}}|${socket_path}|g" /etc/nginx/sites-available/default |
| 58 | + |
| 59 | +su -s /bin/sh -c "fcgiwrap -s unix:${socket_path}" www-data & |
| 60 | + |
| 61 | +trap "kill 0" EXIT |
| 62 | + |
| 63 | +exec nginx -g 'daemon off;' |
| 64 | +EOF |
| 65 | + |
| 66 | +EXPOSE 8080 |
| 67 | + |
| 68 | +ENTRYPOINT ["/entrypoint.sh"] |
0 commit comments