我正在尝试按照安装指南创建一个Dockerfile来自动安装HumHub:https://www.humhub.org/docs/guide-admin-installation.html
但是,每当构建脚本运行composer时,我都会收到以下错误:
Changed current directory to /root/.composer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing fxp/composer-asset-plugin (v1.1.1)
Downloading: Connecting... Failed to download fxp/composer-asset-plugin from dist: Could not authenticate against github.com
Now trying to download from source
- Installing fxp/composer-asset-plugin (v1.1.1)
Cloning daca454b94539a4e6d30937dfc6b817eceb03f28
Writing lock file
Generating autoload files
Loading composer repositories with package information
Updating dependencies (including require-dev)
Failed to clone the git@github.com:jquery/jquery-dist.git repository, try running in interactive mode so that you can enter your GitHub credentials
[RuntimeException]
Failed to execute git clone --mirror 'git@github.com:jquery/jquery-dist.git' '/root/.composer/cache/vcs/git-github.com-jquery-jquery-dist.git/'
据推测,这是由作曲家使用git安装jquery并期望git预先配置git访问凭据引起的。但是,为Docker构建脚本提供git访问凭证是没有意义的。
我试图强制git和composer都使用https(请参阅How to force Composer to use https:// instead of git://?),但它似乎没有达到预期的效果。这可能是由作曲家插件composer-asset-plugin中的一个错误导致的吗?
这是构建文件:
FROM orukami/alpine-php:5.6
ENV WWW_ROOT /var/www
ENV PUBLIC_ROOT /var/www/public
COPY nginx /etc/nginx
COPY fpm /etc/php/fpm
COPY supervisord.conf /etc/supervisord.conf
COPY entrypoint.sh /
RUN apk add -U nginx supervisor git curl && \
mkdir -p /var/www && mkdir -p ${WWW_ROOT} && \
rm -rf /var/cache/apk/* && \
chmod +x /entrypoint.sh
RUN git clone https://github.com/humhub/humhub.git /var/www/public
RUN cd /var/www/public && curl -sS https://getcomposer.org/installer | php
RUN git config --global url."https://".insteadOf "git://" && cd /var/www/public && \
./composer.phar config --global github-protocols https && \
./composer.phar global require "fxp/composer-asset-plugin:~1.1.0" && \
./composer.phar update
WORKDIR ${WWW_ROOT}
EXPOSE 80 443
VOLUME /var/www/public
ENTRYPOINT ["/entrypoint.sh"]
CMD ["/usr/bin/supervisord"]
这一定是一个非常常见的问题,但我无法在网上找到任何解决方案。
答案 0 :(得分:1)
问题最终被追溯到composer-asset-plugin,不遵守加载https而不是git://的指令。解决方案是将像这样的文件https://github.com/djcf/humhub-docker/blob/master/config.json复制到/root/.composer。
答案 1 :(得分:1)
被接受的解决方案可以工作,但是它也可能是不安全的,因为在config.json文件中有一个硬编码的github令牌。有关详细说明和更安全的解决方案,请参见此处:https://www.previousnext.com.au/blog/managing-composer-github-access-personal-access-tokens
根本原因是github限制了诸如composer之类的客户端进行的api调用次数。 Composer使用github api将文件下载到您的供应商目录,当文件达到限制(https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting)时,您将看到该错误消息。
在某些情况下(例如我的情况并非完全是@DMCoding的情况),如果由于例如存储库不在您的控制下而无法生成令牌,则另一种选择是减少数量通过在composer.json中将参数no-api设置为true来完成api请求,例如:
"repositories": [
{
"type": "vcs",
"url": "https://github.com/user/repo",
"no-api": true
}
]
Composer会将每个存储库的调用从大约20个减少到一个:从github下载压缩存储库的调用。有一种方法可以为来自github的所有软件包设置选项:这样,作曲家将只下载压缩后的仓库一次,并尝试在每次更新中运行git pull: https://getcomposer.org/doc/06-config.md#use-github-api