Open6

GitでSDKを配布する検討

okuokuokuoku

100MiB以上のファイルが無いか確認

GitHubの最大バイナリサイズは100MiBで50MiBを超えると警告がでる。GHEだと拡張できるけど少くとも無料の範囲では100MiBがハードリミットのようだ。これは find コマンドで簡単に探せる。

root@ae5e1788ff72:/build# find /opt/yunibase -size +100M
root@ae5e1788ff72:/build#

でかくても50MiBくらいには収まっているようだ。

okuokuokuoku

tarballにする

Docker内に構築しているので適当に取りだしてやる必要がある。... dockerってvolumeを誰かのUIDにする機能あったよね確か。。

$ docker run --rm -it -v/home/oku/outtemp:/outtemp okuoku/yunibase:latest bash
# cd /opt/yunibase
# tar cf /outtemp/yunibase.tar current
okuokuokuoku

indexの生成とコミット

原理的にはShallow cloneしてもこの方法ならちゃんとコミットできるはず。。Bare repositoryに直接コミットするのを試してみる。

$ git clone --mirror ~/repos/prebuilt-yunibase/
$ GIT_DIR=prebuilt-yunibase.git GIT_INDEX_FILE=index git read-tree --empty
$ find README.md current -not -type d | \
    GIT_DIR=prebuilt-yunibase.git GIT_INDEX_FILE=index \
    GIT_WORK_TREE=. git update-index --add --replace --stdin
$ GIT_DIR=prebuilt-yunibase.git GIT_INDEX_FILE=index \
    git write-tree
4acf249505354b609c675d2c8a4ef70091f414ac

update-index には本来work tree、つまり何らかのチェックアウトが必要だが、特に何も用意しなくても単に . を指定すれば正常に動作する。

$ GIT_AUTHOR_NAME=nobody GIT_AUTHOR_EMAIL=nobody \
    GIT_COMMITTER_NAME=nobody GIT_COMMITTER_EMAIL=nobody \
    GIT_DIR=prebuilt-yunibase.git \
git commit-tree 4acf249505354b609c675d2c8a4ef70091f414ac -m update
da45c715e207a8b994086869c8f159c55f8c782a

コミットしたらupdate-refでブランチを更新する。

GIT_DIR=prebuilt-yunibase.git git update-ref refs/heads/linux-amd64 da45c715e207a8b994086869c8f159c55f8c782a
okuokuokuoku

Pushしてみた

https://github.com/okuoku/prebuilt-yunibase-proto

$ git push --all -f
Enumerating objects: 11833, done.
Counting objects: 100% (11833/11833), done.
Delta compression using up to 4 threads
Compressing objects: 100% (11266/11266), done.
Writing objects: 100% (11833/11833), 230.42 MiB | 3.15 MiB/s, done.
Total 11833 (delta 2763), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (2763/2763), done.
To github.com:okuoku/prebuilt-yunibase-proto.git
 * [new branch]      linux-amd64 -> linux-amd64
 * [new branch]      master -> master

230MiB。。絶妙なサイズ感だな。。

okuokuokuoku

展開と利用

$ curl -L --output yunibase.tar.gz https://api.github.com/repos/okuoku/prebuilt-yunibase-proto/tarball/linux-amd64
$ tar zxf yunibase.tar.gz
$ mv okuoku-prebuilt-yunibase-proto-* yunibase

APIにはTokenを与えないと速攻でrate limitされてしまう。...というかこれREST APIだったのか。。 https://docs.github.com/ja/rest/repos/contents?apiVersion=2022-11-28#download-a-repository-archive-tar

ただ、このAPI何か遅いらしく(40秒くらい掛かる)、普通にcloneした方が早かった(19秒)。

https://github.com/okuoku/ribbon-integ/blob/de64b115caf08fd0e8d87fe56ec6dc92561aa468/.github/workflows/build.yml#L21-L28