Skip to content

Instantly share code, notes, and snippets.

@whywaita
Last active July 7, 2021 03:06
Show Gist options
  • Save whywaita/c6558fc967e29dbc259055078a61fbf4 to your computer and use it in GitHub Desktop.
Save whywaita/c6558fc967e29dbc259055078a61fbf4 to your computer and use it in GitHub Desktop.

ストレージ代をケチるためにGitHub Repositoryを無料ストレージとみなして遊ぶのをたまにやっているがそのシリーズ、今回はオブジェクトストレージ

やることは単純でGitリポジトリをFUSEでマウントできる presslabs/gitfs を使ってGitリポジトリをLinuxのファイルシステムとしてマウントしてあげて、そのディレクトリを minio/minio のfs-v1で被せてやるだけで終了。

さっくり動くかと思ってたけどさすがにちゃんと動かなかったのでパッチを当てるなどした。これ今回の環境じゃなくても起きそうだなということでPull Reqにもしたけど、メンテ自体止まってそうなので多分そのまま放置されそう

presslabs/gitfs#368

というわけで私のForkを使うと正しく動きます

環境

  • Ubuntu bionic 18.04
    • mv(1) の挙動が最近微妙に変わったようでlibfuseを利用していたアプリケーションが軒並み壊れたらしい
    • https://bugzilla.redhat.com/show_bug.cgi?id=1656826
    • 最初 Ubuntu focal 20.04 で動かそうとしていたがこれがだるそうだったので回避
  • gitfs patched by whywaita
  • minio RELEASE.2021-06-09T18-51-39Z

実行

$ sudo apt install -y build-essential
$ git clone https://github.com/whywaita/gitfs
$ git switch fix/catch-oserror
$ make

/mnt/gitfs にマウント

$ sudo $(pwd)/gitfs/build/gitfs http://github.com/username/foobar /mnt/gitfs -o debug=true,remote_url=https://username:${GITHUB PERSONAL TOKEN}@github.com/username/foobar,allow_other=true

Dockerでminioを起動

実際のデータは ${mount point}/current にマウントされるのでminioはそのディレクトリにマウントしてあげる

$ docker run -d -p 9000:9000 -e MINIO_ROOT_USER=foo -e MINIO_ROOT_PASSWORD=bar -v /mnt/gitfs/current:/data --rm --name minio minio/minio server /data

とりあえずこれでminioが動いてファイルをCRUDするとGitリポジトリに反映される

所感

とりあえずで雑に80GBほどのファイルを mc cp コマンドでマイグレーションしようとしたところgitfsのマウントが外れた。

dmesgを見るとgeneral protectionで弾かれているようだ

traps: python3.6[10531] general protection ip:7f942ae1fab4 sp:7f940cff64d0 error:0 in libgit2-96e6b8cb.so.0.28.2[7f942acd9000+492000]

直すだけならumount / re-mountとdockerコンテナの再起動でOKだけど、そこそこの負荷で殴ると壊れるっぽいのはかなしみ。ただs3fsなどでもよく起きるみたいなので仕方なさそう。

そういう細かいところに目をつぶると安価にオブジェクトストレージがそこそこのレイテンシとそこそこの信頼性で激安運用できるので便利そう。しばらくこれで様子見してみる。

2021/06/15 追記

gitfsバンバンマウント外れるのでsystemd.timerでRemount自動化した

cat /usr/local/bin/remount-gitfs
#!/bin/bash

set -eu

/bin/ls /root/mnt >> /dev/null && exit 0 || echo "need remount"

/bin/umount /root/mnt
/root/gitfs/build/gitfs http://github.com/username/foobar /root/mnt -o remote_url=https://username:${github personal token}@github.com/username/foobar,allow_other=true
/usr/bin/docker restart minio


# cat /etc/systemd/system/remount-gitfs.service
[Unit]
Description=Remount gitfs
After=network.target auditd.service

[Service]
ExecStart=/usr/local/bin/remount-gitfs

[Install]
WantedBy=multi-user.target


# cat /etc/systemd/system/remount-gitfs.timer
[Unit]
Description=Remount gitfs if broken

[Timer]
OnUnitActiveSec=10m
Unit=remount-gitfs.service

[Install]
WantedBy=multi-user.target

追記 (2021/07/07)

自動リマウント入れてたら完全に壊れてしまった、どうして……

mc cp などで数百GBのファイルを転送するとこれも壊れたので残念〜という感じ、使うのやめました

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment