LoginSignup
10
7

More than 5 years have passed since last update.

Elastic BeanstalkでWAR内の設定ファイルをdev,prodで出し分けたい

Posted at

Elastic Beanstalk (java) で

  • ある設定ファイルをどうしても WARの中に 置かないと動かない
  • 開発環境と本番環境では違うものを使わなきゃいけない

という状況下で使った手法です。WAR外で良ければ別の簡単な手段があります。

以下、ある設定ファイルを settings.conf という名前だとして進めます。

ファイル配置

settings.conf.development と settings.conf.production を用意し、/path/to/* に配置します。それぞれ開発用と本番用です。

elastic beanstalk設定

environmentに ENV というパラメータを追加します。ENVにはdevelopmentやproductionといった、上記のsettings.confの末尾に追加した値を利用します。

.ebextentions

src/main/webapp/.ebextensions/myapp.config というファイルを設置します。中身は下記

container_commands:
  myapp_config:
    command: cp path/to/settings.conf.$ENV path/to/settings.conf

これで準備は完了です。

あとは、このwarファイルをデプロイすると、WAR解凍後にcontainer_commandsのコマンドが実行され、必要な設定ファイルが配置され、その後tomcatが起動します。

補足

container_commandsの実行タイミングは「アプリケーション解凍後」とドキュメントにはっきり書かれていたので、この手法を取りました。

別にWARの外でもよいなら、filesなど別の機能を利用するのが正しいです。

参考

10
7
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
10
7