Apache git 服务器与 Alpine Linux 在 Docker

Apache git server with Alpine Linux on Docker

我正在尝试使用 Docker 中的 Alpine 的 Apache 映像在 http 上提供 git 回购服务。

我可以让 Apache 在 http 上提供文档和文件夹(此文件夹中有一些非 git 存储库,目前这只是概念验证,所以它们可以被忽略):

然而,当我尝试克隆 git 存储库时,我只能成功克隆 DynamicDockerTesting.git 存储库。尝试克隆其他回购时,我得到

fatal: repository 'http://192.168.1.32/<repo-name>.git' not found

我已经检查了 DynamicDockerTesting.git 和其他回购协议之间我能想到的每一个差异,但未能找到任何有意义的差异来解释为什么我可以克隆那个特定的回购协议,但是 none 其他的。如果你有关于如何弄清楚为什么会这样的建议,我很乐意听取他们的意见,但更重要的是,如果你知道我一般做错了什么,以及如何使用 docker 成功部署这些回购协议-alpine-apache-git组合,将不胜感激。

这是我的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 似乎 运行 /usr/local/apache2 中的所有内容(而不是 /etc/apache2),所以在这里我只是将要部署的逻辑添加到默认的 httpd.conf回购协议,并启用 cgi 模块,因为默认情况下它是禁用的(envalias 默认启用)。

这里是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 已经进行了多次修改,因为我已经尝试了所有我能想到的配置,但都无济于事。此配置使存储库可访问,但不可克隆(当然 DynamicDockerTesting.git 除外)

由于 DockerfileapacheGitServer.xml 在同一个文件夹中,我一直在用

构建图像

docker build -t apachegit .

然后我 cd 使用我的 git 存储库进入目录,并发出命令

docker run -d --name apachegitserver -p 80:80 -v $(pwd):/usr/local/apache2/git apachegit

我花了两天时间试图让它工作,所以欢迎任何指导。

编辑

运行ning top 我看到进程归 daemon 所有,我从容器内部 cd'ed 到 /usr/local/apache2/git 并且运行 chown -R daemon:daemon .,但现在当我克隆时:

git clone http://192.168.1.32/git/ScalaOpenCV.git

我得到一个 403:

fatal: unable to access 'http://192.168.1.32/git/<repo name>.git/': The requested URL returned error: 403

(实际上,无论我是否更改权限,我都会得到一个 403

ScriptAlias /git/ /usr/libexec/git-core/git-http-backend

这意味着任何 git 操作都应该包含一个 URL 并在其中包含 /git/(如 this setup 所示)。

git clone http://192.168.1.32/git/<repo-name>.git

检查 apache 日志,看看 DynamicDockerTesting.git 和其他的是否有任何区别。检查所有权,如 shown here.

所以我终于可以通过 http 进行克隆了。这就是最终起作用的方法:

1) 使用我最初问题 post 中的 docker -v 标志将所有 git 存储库放入默认部署文件夹 (/usr/local/apache2/htdocs) .

2) 修改默认的httpd.conf为alpine image,添加如下内容:

2a) <Directory "usr/local/apache2/htdocs"> 节点现在有: Options +Indexes +FollowSymLinks +ExecCGI(不确定 FollowSymLinks 选项是否必要)

2b) 无需添加 <VirtualHost> 节点

2c) 将以下设置添加到配置中: SetEnv GIT_PROJECT_ROOT /usr/local/apache2/htdocs, SetEnv GIT_HTTP_EXPORT_ALL, ScriptAlias / /usr/libexec/git-core/git-http-backend/ (显然,这些都是来自其他 postings 的关于如何设置 Apache Git 服务器的非常标准的东西)

2d) 在 LoadModule cgi_module modules/mod_cgi.so

中发表评论

2e) 添加以下 Directory 节点:

<Directory "/usr/libexec/git-core">
   Options +ExecCGI
   AllowOverride All
   Require all granted
</Directory>

我不知道这些配置有多安全

现在,当我在本地导航到容器的 IP 地址时,浏览器给了我一个 404,没有任何服务。但是,如果我尝试克隆,git 会发现存储库和克隆都很好。

我正在从根上下文进行克隆,即 http://<ip address>/<git repo>.git

我仍在努力弄清楚为什么浏览器没有为 repo 编制索引以供显示,但至少核心需求(通过 http 克隆)在起作用。