Skip to content

Commit 648e4e1

Browse files
committed
git server via docker
1 parent c35e7e8 commit 648e4e1

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,24 @@ Run `go run ./cmd/qault -- list` (or any other subcommand) to exercise the CLI d
174174
```sh
175175
go test ./...
176176
```
177+
178+
### HTTP git server for testing pushes
179+
180+
Build and run a minimal HTTP git server with basic auth:
181+
182+
```sh
183+
docker build -t qault/git-http ./server
184+
185+
BCRYPT_PASSWORD=$(htpasswd -nbBC 12 alice 'plain-password' | cut -d: -f2)
186+
docker run -p 8080:8080 \
187+
-e USERNAME=alice \
188+
-e BCRYPT_PASSWORD="$BCRYPT_PASSWORD" \
189+
-e REPO_NAME=qault-vault \
190+
qault/git-http
191+
```
192+
193+
Clone or push with your plain password; the server checks it against the bcrypt hash you supplied:
194+
195+
```sh
196+
git clone http://alice:plain-password@localhost:8080/qault-vault.git
197+
```

server/Dockerfile

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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

Comments
 (0)