[英]PHP and Composer with Docker build: failed to clone git
我正在嘗試創建一個 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(請參閱如何強制 Composer 使用 https:// 而不是 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"]
這一定是一個非常普遍的問題,但是我在網上根本找不到任何解決方案。
問題最終被追溯到 composer-asset-plugin 不遵守通過 https 而不是 git:// 加載的指令。 解決方案是將這樣的文件復制到 /root/.composer 中: https ://github.com/djcf/humhub-docker/blob/master/config.json。
已接受的解決方案可能有效,但也可能不安全,因為 config.json 文件中硬編碼了一個 github 令牌。 有關詳細說明和更安全的解決方案,請參見此處: https : //www.previousnext.com.au/blog/managing-composer-github-access-personal-access-tokens
根本原因是github限制了像composer這樣的客戶端調用api的次數。 Composer 使用 github api 將文件下載到您的供應商目錄,當它達到 de limit ( 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 中的所有包設置選項:這樣作曲家將只下載一次壓縮的 repo,並嘗試在每次更新時運行 git pull: https : //getcomposer.org/doc/06-config.md#使用-github-api
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.