I am trying to serve git repos over http
using Alpine's Apache image in Docker.
I am able to get Apache to serve up documents and folders over http
(there are some non git repos in this folder, this is just a proof of concept at the moment, so they can be ignored):
However when I attempt to clone the git repo's, I can only successfully clone the DynamicDockerTesting.git
repo. When attempting to clone the other repo's I get
fatal: repository 'http://192.168.1.32/<repo-name>.git' not found
I have inspected every difference I can think of between DynamicDockerTesting.git
and the other repo's present, but have not been able to find any meaningful difference that would explain why I can clone that particular repo, but none of the other ones. If you have suggestions as to how to figure out why this is the case I would love to hear them, but more importantly if you know what I am doing wrong in general, and how to deploy these repo's successfully using the docker-alpine-apache-git combination, I would be extremely grateful.
Here are the contents of my Dockerfile
FROM httpd:alpine
RUN mkdir -p /usr/local/apache2/git
RUN apk update && apk upgrade && apk add git git-gitweb apache2-utils apache2
COPY apacheGitServer.xml /usr/local/apache2/
RUN cat /usr/local/apache2/apacheGitServer.xml >> /usr/local/apache2/conf/httpd.conf
RUN sed -i '/LoadModule alias_module modules\/mod_alias.so/aLoadModule cgi_module modules/mod_cgi.so' /usr/local/apache2/conf/httpd.conf
Alpine Apache seems to run everything out of /usr/local/apache2
(instead of /etc/apache2
), so here I am just adding to the default httpd.conf
the logic to deploy the repos, and also enabling the cgi
module since it is disabled by default (env
and alias
are enabled by default).
Here are the contents of apacheGitServer.xml
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /usr/local/apache2/git/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<VirtualHost *:80>
DocumentRoot /usr/local/apache2/git
ServerName 192.168.1.32
<Directory "/usr/local/apache2/git">
Allow from All
Options +Indexes +ExecCGI
AllowOverride All
AddHandler cgi-script cgi
</Directory>
SetEnv GIT_HTTP_EXPORT_ALL
SetEnv GIT_PROJECT_ROOT /usr/local/apache2/git
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend
#ScriptAlias / /usr/share/gitweb/gitweb.cgi
</VirtualHost>
apacheGitServer.xml
has gone through a number of revisions as I have tried every configuration that I could think of to get this working, but to no avail. This configuration makes the repos accessible, but not clone-able (except, of course DynamicDockerTesting.git
)
With the Dockerfile
and apacheGitServer.xml
in the same folder, I have been building the image with
docker build -t apachegit .
and then I have cd
'ed to the directory with my git repo's, and issued the command
docker run -d --name apachegitserver -p 80:80 -v $(pwd):/usr/local/apache2/git apachegit
I have spent two days trying to get this to work, so any guidance at this point is welcome.
EDIT
running top
I see that the process is owned by daemon
, I have cd
'ed to /usr/local/apache2/git
from inside the container and run chown -R daemon:daemon .
, but now when I clone:
git clone http://192.168.1.32/git/ScalaOpenCV.git
I get a 403
:
fatal: unable to access 'http://192.168.1.32/git/<repo name>.git/': The requested URL returned error: 403
(actually I get a 403
no matter if I change the permissions or not)
So I am finally able to clone over http. This is what finally worked:
1) put all the git repos in the default deploy folder (/usr/local/apache2/htdocs
) using the docker -v
flag from my original question post.
2) Modify the default httpd.conf
for the alpine image and add the following:
2a) <Directory "usr/local/apache2/htdocs">
node now has:
Options +Indexes +FollowSymLinks +ExecCGI
(not sure if the FollowSymLinks
option in necessary)
2b) No need to add a <VirtualHost>
node
2c) add the following settings to the config:
SetEnv GIT_PROJECT_ROOT /usr/local/apache2/htdocs
,
SetEnv GIT_HTTP_EXPORT_ALL
,
ScriptAlias / /usr/libexec/git-core/git-http-backend/
(Obviously, this is all pretty standard stuff from other postings about how to set up an Apache Git server)
2d) Comment in LoadModule cgi_module modules/mod_cgi.so
2e) Add the following Directory
node:
<Directory "/usr/libexec/git-core">
Options +ExecCGI
AllowOverride All
Require all granted
</Directory>
I DO NOT KNOW HOW SECURE THESE CONFIGURATIONS ARE
Now when I navigate locally to the container's IP address, the browser gives me a 404
, that there is nothing to serve. However, if I attempt to clone, git finds the repos and clones just fine.
I am cloning from the root context, ie http://<ip address>/<git repo>.git
.
I am still working to figure out why the browser is not indexing the repo's for display, but at least the core need (cloning over http) is working.