quartz-research-note/content/Mastodonのアップデートでいちいちdocker-compose.ymlを一時的に書き換えない.md
Tomoya Matsuura(MacBookPro) 4b5abf861a
All checks were successful
Build / build (push) Successful in 3m46s
[obsidian] vault backup: 2024-02-16 21:27:20
2024-02-16 21:27:20 +09:00

55 lines
2.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
date: 2023-02-15
---
#tips #self-hosted #mastodon
普通、dockerで運用するときは[[Mastodon]]のリポジトリをクローンしてきて、`docker-compose.yml`の`build`をコメントアウトすることで、リポジトリからコンテナイメージをpullするように変える。
ただこの場合、バージョンアップデートの際に`git stash && git fetch && git checkout <version> && git stash pop`するとこんな感じにconflictが発生する。(ここでは例示のため4.2.6から4.2.5にダウングレードしてるが)
```yml
web:
<<<<<<< Updated upstream
build: .
image: ghcr.io/mastodon/mastodon:v4.2.5
=======
# build: .
image: ghcr.io/mastodon/mastodon:v4.2.6
>>>>>>> Stashed changes
restart: always
```
そこで、`docker-compose.yml`とは別に`docker-compose.override.yml`というのを置いておくと、特定のキーを上書きしてくれる機能を使う。
[Merge Compose files | Docker Docs](https://docs.docker.com/compose/multiple-compose-files/merge/)
最近まで、この上書き機能では特定のエントリをコメントアウトするような操作はできなかったが、docker-compose v2.18.0以降で`!reset`というのを置いておくとできるようになった。
[docker-compose.override.yml で 打ち消し定義 ができるようになった。](https://zenn.dev/iitenkida7/articles/91b88ca76e98c7)
ので、`sudo apt-get upgrade docker-compose-plugin`をやった上でこんな`docker-compose.override.yml`を作る。
```yml
web:
image: ghcr.io/mastodon/mastodon:latest
build: !reset
streaming:
image: ghcr.io/mastodon/mastodon:latest
build: !reset
sidekiq:
image: ghcr.io/mastodon/mastodon:latest
build: !reset
```
実際のファイルではpostgresの設定とかでもうちょっといろんなエントリが入っている。
こうすれば、大概のマイナーな更新時は`docker compose pull&& docker compose down && docker compose up -d`1つでよくなる。(compose自体に更新が入ったり、.env.productionとかに変更があったり、`rake:db migrate`する必要がある場合もあるので、基本はリリースートを読んでから、必要に応じてgit pullすること)
そもそもきちんとリポジトリをmergeで更新していく運用の方がいいのかもしれないが
注意点として、ハイフン付きの`docker-compose`コマンドはv1コンパチで動くので`!reset`が効かずパースエラーになる。もう実質deprecatedになってるのでサブコマンドの`docker compose`で使うことこれに気づかず30分ぐらいハマった