2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[firebase] Local Emulator Suiteをdocker化してみたが、データの永続化ができない場合

Last updated at Posted at 2022-04-13

問題

とりあえずローカルマシンに環境依存をなくしたいので、あらゆるものをdocker化したい。Local Emulator Suiteを今回やってみたが、公式のイメージはない模様。

自作してみて動くのは動くが、

$ docker-compose up
...
...

のように動かしておいて、ctrl+cをして止めると再起動時にデータが保持されない。

これはfirebase emulators:start --import data --export-on-exitとして起動しても変わらず...

原因

どうもdocker-compose側でctrl+cをサービス内まで届けてない?様子で色々検索して試したがうまいことINTシグナルを渡すことができなかった。

$ docker-compose -v
docker-compose version 1.29.1, build c34c88b2

試したこと

これは一見動きそうだが、ctrl+c時にtrapされている様子はなかった。

これを使ってdocker-compose downの代わりにdocker exec container_name firebase emulators:export -f export/dataとかしてみてもtrap事前にサービスが止められてる感じだった。

解決方法

この人のパターンのように定期的にデータをexportするようにした。
shellはよく分からないのでrubyで...

export.rb
loop do
  sleep 10
  puts "###############"
  puts "exporting ..."
  puts "###############"
  system("firebase emulators:export -f export/data")
end
startup.sh
ruby ./export.rb &
firebase emulators:start --import export/data

こうすることで10秒置きにとりあえずデータは保持されるので、なんとかなる。

exportはdocker-composeで指定しているvolume


  firebase:
    ...
    ...
    volumes:
      - export:/firebase/export
    ...
    ...

volumes:
  export: {}
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?