【问题标题】:PHP and Composer with Docker build: failed to clone git带有 Docker 构建的 PHP 和 Composer:无法克隆 git
【发布时间】:2016-05-11 14:55:46
【问题描述】:

我正在尝试创建一个 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 预先配置了 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"]

这一定是一个很常见的问题,但是我在网上根本找不到任何解决方案。

【问题讨论】:

    标签: git docker composer-php dockerfile git-clone


    【解决方案1】:

    问题最终被追溯到 composer-asset-plugin 不遵守通过 https 而不是 git:// 加载的指令。解决方案是将这样的文件:https://github.com/djcf/humhub-docker/blob/master/config.json 复制到 /root/.composer。

    【讨论】:

      【解决方案2】:

      接受的解决方案可以工作,但也可能不安全,因为 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 的情况),如果您无法生成令牌,例如,存储库不受您的控制,另一种选择是减少数量api 请求 composer 通过在 composer.json 中将参数 no-api 设置为 true 来实现的,例如:

      "repositories": [
        {
          "type": "vcs",
          "url": "https://github.com/user/repo",
          "no-api": true
        }
      ]
      

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-10-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-17
        • 2014-02-26
        • 1970-01-01
        相关资源
        最近更新 更多