週刊Elixirライブラリ2015-8
Elixirのライブラリの解説を週ごとにお届けする記事です。
解説が間違っていた場合には、コメントか@hayabusa333にご連絡くださると嬉しいです。
今回はBottlerについて
# Bottler is 何?
Bottlerはリリースする内容をまとめ、リリースを行いたいサーバーへとデプロイするためのツールです。
# 実行環境
OS:OS X Yosemite
Erlang:Eshell V6.5, OTP-Version 18
Elixir:v1.0.4
# Bottlerの実行を行うための新規プロジェクトの作成
$ mix new my_bottler $ cd my_bottler
# HexにてBottlerをインストールするために設定ファイルの記載を行う
$ vim mix.exs
mix.exsの内容は下記となります。
defmodule MyBottler.Mixfile do use Mix.Project def project do [app: :my_bottler, version: "0.0.1", elixir: "~> 1.0", build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod, deps: deps] end # Configuration for the OTP application # # Type `mix help compile.app` for more information def application do [applications: [:logger]] end # Dependencies can be Hex packages: # # {:mydep, "~> 0.3.0"} # # Or git/path repositories: # # {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"} # # Type `mix help deps` for more examples and options defp deps do [{:bottler, " >= 0.5.0"}] end end
# 依存関係の解決を行います。
$ mix deps.get $ mix deps.compile
# Bottler用の設定を記載する
$ vim config/config.exs
設定を記載する config/config.exs の一番下に下記を追加
config :bottler, :params, [servers: [server1: [ip: "0.0.0.0"],], remote_user: "produser" ]
# Bottlerを使ってリリース内容をまとめる
$ mix bottler.release
リリース内容としてまとめられたファイルを確認
$ ls rel/ my_bottler.boot my_bottler.script sys.config my_bottler.rel my_bottler.tar.gz $ cd rel/ $ tar zxvf my_bottler.tar.gz $ ls lib my_bottler.script sys.config my_bottler.boot my_bottler.tar.gz my_bottler.rel releases $ ls lib/ asn1-4.0 kernel-4.0 ssh-4.0 bottler-0.5.0 logger-1.0.4 sshex-1.1.0 compiler-6.0 my_bottler-0.0.1 stdlib-2.5 crypto-3.6 public_key-1.0 syntax_tools-1.7 elixir-1.0.4 sasl-2.5 $ ls releases/ 0.0.1 my_bottler.rel
# Bottlerを使って、特定のサーバーにリリース内容を送る
$ mix bottler.ship
上記のコマンドを実行すると、リリース先のサーバの /tmp 配下に作成した tar.gzファイルが転送されます。
※ SCPで転送のため送り先のサーバーに公開鍵認証の設定が必要です。
# Bottlerで使用できる他のコマンド
mix bottler.install
configで指定したサーバへとリリース内容をインストールします
mix bottler.restart
HarakiriというElixirのライブラリを使用することが前提となりますが、アプリケーションの再起動を行うことができます。
Harakiriに関しては、いつになるかはわかりませんが次回以降に紹介していきたいと思います。
mix deploy
releaseとshipとinstallが集約したコマンドとなります。
mix bottler.rollback
デプロイしたリリース内容をロールバックしたいときに使うコマンドですが、リリース内容が安全であるかはユーザーに任されているようです。
# まとめ
今回はElixirのデプロイツールであるBottlerを紹介させていただきました。
デプロイツールも数多の数のものが出てきておりますが、Elixir環境下のみで開発を行うならば、BottlerなどのElixirで動くデプロイツールを使うのも良いかもしれませんね
それでは皆さま、良いElixirライフを