ことの発端
Docker On Mac遅い。
DockerSyncは不安定らしく(未チェック)使う気があまり起きない。
悩んだ末以下の記事に到達。
DXを大幅に低下させるDocker for Macを捨ててMac最速のDocker環境を手に入れる
この記事ではHostとVirtualBox間のファイル同期にmutagenというツールを使っている。
めちゃくちゃマイナーなツールで情報が少ないので触ってみた。
公式を読む
Mutagen is a development utility that lets you use your existing local tools (such as your text editor/IDE, browser, and terminal) to work in remote environments like cloud servers and containers. It does this by providing high-performance file synchronization and flexible network forwarding, allowing you to develop applications in a way that looks local but runs on remote hardware. Mutagen is completely free and open-source and works directly between your local system and the remote infrastructure that you need to access.
Unlike most other remote development solutions, Mutagen isn’t a plug-in or a wrapper, so it works with essentially any tool. It also doesn’t require users to manually install it on remote endpoints or expose ports. Instead, Mutagen uses copy mechanisms like scp and docker cp to inject small “agent” binaries into remote environments and then communicates with those binaries over a transport like ssh or docker exec. For maximum flexibility, it also offers a peer-to-peer transport that will work with almost any remote infrastructure, including Kubernetes® clusters.
要するに2点間のファイル同期をしてローカルでリモート環境を編集しようという試みっぽい。
中身はscpやdocker cpらしい。
使ってみる
今回はvagrantで仮想環境を立てて、仮想環境とファイル同期をしてみる。
まずは仮想環境を建てる。Vagrantfileなどは割愛。
$ vagrant up
mutagenのsessionを作成する
$ mutagen sync create ./ <remote-host>:/home/vagrant/app
sessionができてるか確認。
このように表示されます。
$ mutagen list
--------------------------------------------------------------------------------
Identifier: sync_<省略>
Labels: None
Alpha:
URL: <local-hostのディレクトリ>
Connection state: Connected
Beta:
URL: <remote-host>:/home/vagrant/app/
Connection state: Connected
Status: Scanning files
--------------------------------------------------------------------------------
ローカル環境でファイルを作成してみる
(local)$ touch hoge
virtualbox内でファイルを確認してみる
(remote)$ ls
hoge
できた!
その後
vagrant-mutagenプラグインを入れるとセッションの管理をvagrant up、vagrant halt時に合わせて自動的に生成削除してくれる。
https://github.com/dasginganinja/vagrant-mutagen