何をしたいか
githubではサイズの大きいファイル(>100MB)のpushは禁止されている。大きいファイルを扱う場合には、gitlfsという仕組みを使う必要がある。詳細は別記事に譲る。
我々の環境では社用サーバ(AWS)上に構築したgitlabをリモートサーバとして使用しているものの、将来的なgithubへの移行も考慮して、gitlfsを扱えるようにしておく。
#一度大容量ファイルを登録した履歴が残っていると、その履歴を削除しない限りgithubにpushできなくなる!
主に以下の公式docを参照した。
https://gitlab-docs.creationline.com/ee/topics/git/lfs/
サーバ側の要件は以下:
- Git LFS is supported in GitLab starting with version 8.2
- Git LFS must be enabled under project settings
- Git LFS client version 1.0.1 and up
3番目のGit LFS clientが入っていないので、これをインストールする。
gitlabサーバにgit-lfsをインストールする
普通にsudo yum install git-lfs
すると、パッケージが見つからないといわれてしまう。RHELやCentOSとは異なり、AmazonLinux2では専用のリポジトリしか登録されていないため、個別に登録する必要がある。
git-lfsのinstallガイドに記載されている手順に社内のプロキシサーバの設定を加えて実行。
$ sudo curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.rpm.sh -x http://<proxy_server>:<port> | sudo bash
Detected operating system as amzn/2.
Checking for curl...
Detected curl...
Downloading repository file: https://packagecloud.io/install/repositories/github/git-lfs/config_file.repo?os=amzn&dist=2&source=script
curl: (7) Failed to connect to packagecloud.io port 443: Connection timed out
Unable to run:
curl https://packagecloud.io/install/repositories/github/git-lfs/config_file.repo?os=amzn&dist=2&source=script
Double check your curl installation and try again.
の状態で止まってしまう。失敗したcurlコマンドを直接実行してみる。プロキシサーバの指定と、&でコマンドがエスケープされてしまうのでURLをダブルクオートで囲って実行。
$ curl "https://packagecloud.io/install/repositories/github/git-lfs/config_file.repo?os=amzn&dist=2&source=script" --proxy http://<proxy_server>:<port>
[github_git-lfs]
name=github_git-lfs
baseurl=https://packagecloud.io/github/git-lfs/el/7/$basearch
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/github/git-lfs/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
[github_git-lfs-source]
name=github_git-lfs-source
baseurl=https://packagecloud.io/github/git-lfs/el/7/SRPMS
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/github/git-lfs/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
ここに表示された内容を/etc/yum.repos.d/github_git-lfs.repo
として保存する。この状態でリポジトリリストを見るとgit-lfsが登録されていることがわかる。
$ yum repolist all
読み込んだプラグイン:extras_suggestions, langpacks, priorities, update-motd
リポジトリー ID リポジトリー名 状態
!amzn2-core/2/x86_64 Amazon Linux 2 core repository 有効: 25,208
amzn2-core-debuginfo/2/x86_64 Amazon Linux 2 core repository - debuginfo packages 無効
amzn2-core-source/2 Amazon Linux 2 core repository - source packages 無効
!amzn2extra-docker/2/x86_64 Amazon Extras repo for docker 有効: 42
amzn2extra-docker-debuginfo/2/x86_64 Amazon Extras debuginfo repo for docker 無効
amzn2extra-docker-source/2 Amazon Extras source repo for docker 無効
!amzn2extra-nginx1/2/x86_64 Amazon Extras repo for nginx1 有効: 54
amzn2extra-nginx1-debuginfo/2/x86_64 Amazon Extras debuginfo repo for nginx1 無効
amzn2extra-nginx1-source/2 Amazon Extras source repo for nginx1 無効
!github_git-lfs/x86_64 github_git-lfs 有効: 65
!github_git-lfs-source github_git-lfs-source 有効: 0
!gitlab_gitlab-ee/x86_64 gitlab_gitlab-ee 有効: 649
!gitlab_gitlab-ee-source gitlab_gitlab-ee-source 有効: 0
!runner_gitlab-runner/x86_64 runner_gitlab-runner 有効: 94
!runner_gitlab-runner-source runner_gitlab-runner-source 有効: 0
repolist: 26,112
後は通常のパッケージインストール手順と同様。バージョンは2.13.3でgitlabの要件を満たしている。
$ sudo yum install -y git-lfs
$ git-lfs --version
git-lfs/2.13.3 (GitHub; linux amd64; go 1.16.2; git a5e65851)
gitlabの設定変更
/etc/gitlab/gitlab.rbで以下の2行コメントアウトを解除して、$ gitlab-ctl reconfigure
### Git LFS
gitlab_rails['lfs_enabled'] = true
gitlab_rails['lfs_storage_path'] = "/var/opt/gitlab/gitlab-rails/shared/lfs-objects"
# gitlab_rails['lfs_object_store_enabled'] = false
# gitlab_rails['lfs_object_store_direct_upload'] = false
# gitlab_rails['lfs_object_store_background_upload'] = true
# gitlab_rails['lfs_object_store_proxy_download'] = false
クライアント(ローカルリポジトリ)側の設定
git-lfsの手順にしたがってファイルをpush。
# git-lfsの設定
$ git lfs install
$ git lfs track <lfsで扱うファイル>
# 対象ファイルの登録。.gitattributesも登録する
$ git add .
$ git commit -m "add large file"
$ git push
Remote "origin" does not support the LFS locking API. Consider disabling it with:
$ git config lfs.https://<remote URL>/<repository name>/info/lfs.locksverify false
batch response: Fatal error: Server error: http://<remote URL>/<repository name>/info/lfs/objects/batch from HTTP 503
Uploading LFS objects: 0% (0/1), 0 B | 0 B/s, done.
Errors logged to <local URL>/<repository name>/.git/lfs/logs/20210701T103557.261027288.log
Use `git lfs logs last` to view the log.
error: failed to push some refs to '<local URL>/<repository name>'
consider desabling it with:…はワーニングで、複数ユーザによるアクセス競合を避けるための仕組みをリモートサーバがサポートしていないよ、というもの。メッセージに従って設定を追加しても後者のエラーが残る。
後者のエラーについては、以下に記述があった。
Known limitations
Git LFS v1 original API is not supported since it was deprecated early in LFS development
When SSH is set as a remote, Git LFS objects still go through HTTPS
Any Git LFS request will ask for HTTPS credentials to be provided so a good Git credentials store is recommended
Git LFS always assumes HTTPS so if you have GitLab server on HTTP you will have to add the URL to Git configuration manually (see troubleshooting)
Note: With 8.12 GitLab added LFS support to SSH. The Git LFS communication still goes over HTTP, but now the SSH client passes the correct credentials to the Git LFS client, so no action is required by the user.
我々の環境では通常のgitはsshで実行している。しかしlfsはHTTPを経由する。そのため、社内サーバにもかかわらずプロキシサーバを経由してアクセスしに行こうとするものだから、エラーが発生していたということだ。
ということで.cshrcのno_proxyにリモートサーバを登録して、再度pushすることで、無事解決。