PHP和Composer与Docker构建:克隆Git失败

3
我正在尝试创建一个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/'  

据推测,这是由于composer使用git安装jquery,并期望预配置git访问凭据所致。然而,在Docker构建脚本中提供git访问凭据毫无意义。
我已尝试强制git和composer都使用https(参见如何强制Composer使用https而不是git://?),但似乎没有产生预期效果。这可能是由于composer插件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"]

这一定是一个非常普遍的问题,但我在网上找不到任何解决方案。

2个回答

5
接受的解决方案可能有效,但由于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以减少Composer执行的API请求次数,例如:
"repositories": [
  {
    "type": "vcs",
    "url": "https://github.com/user/repo",
    "no-api": true
  }
]

Composer将每个仓库的调用次数从约20次减少到只有一次:下载来自GitHub的压缩仓库的调用。有一种方法可以为所有来自GitHub的包设置选项:这样,Composer将仅下载一次压缩仓库,并在每次更新时尝试运行git pull: https://getcomposer.org/doc/06-config.md#use-github-api


3

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接