記事対象者
(一般ユーザとしてcomposer installしており、)後述のエラー事象が発生してる方。
前提
organization/repos-name というプライベートリポジトリをcomposer installしようとする。
エラー事象
composer install 時に以下のエラーが発生。
Failed to download laravel/framework from dist: The "https://api.github.com/repos/organization/repos-name/zipball/xxxxxxx" file could not be downloaded (HTTP/2 404 ): {"message":"Not Found","documentation_url":"https://docs.github.com/rest/repos/contents#download-a-repository-archive-zip"} Now trying to download from source
メッセージ内の、
https://api.github.com/repos/organization/repos-name/zipball/xxxxxxx
はプライベートリポジトリなのでそのままアクセスしても not foundになる。
エラーメッセージに記載されている以下のURL、
に記載の通り、
curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer xxxxxxxx" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/organization/repos-name/zipball/xxxxxxx --output laravel-framework.zip
のようにすればダウンロード可能ではある。
しかし、今回はこのような形でDLしたい訳ではない。
対処方法
rootユーザの場合は
composer config -g github-oauth.github.com ${GITHUB_ACCESS_TOKEN}
のようにアクセストークンを設定すればOK。
これが一般ユーザ(仮に「appuser」というユーザとする)で composer install する場合は、
appuser でアクセストークンを設定する必要があるので
su - appuser -c "composer config -g github-oauth.github.com ${GITHUB_ACCESS_TOKEN}"
のように設定する必要がある。
Dockerfile 上であれば
RUN su - appuser -c "composer config -g github-oauth.github.com ${GITHUB_ACCESS_TOKEN}"
のように記述する。