quartz-research-note/content/Mastodonのアップデートでいちいちdocker-compose.ymlを一時的に書き換えない.md
Tomoya Matsuura(MacBookPro) c76abb9917
All checks were successful
Build / build (push) Successful in 1m45s
[obsidian] vault backup: 2024-02-15 13:48:33
2024-02-15 13:48:33 +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.

#tips #self-hosted #mastodon
普通、dockerで運用するときは[[Mastodon]]のリポジトリをクローンしてきて、`docker-compose.yml`の`build`をコメントアウトすることで、リポジトリからコンテナイメージをpullするように変える。
ただこの場合、バージョンアップデートの際に`git stash && git fetch && git checkout <version>` するとこんな感じにconflictが発生する。(ここでは4.2から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
#depends_on: #必要に応じて
# - es
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分ぐらいハマった