LoginSignup
7
10

More than 5 years have passed since last update.

環境切り替え方法便覧

Last updated at Posted at 2016-02-17

環境の切り替えを、各フレームワークでどうするかをまとめてみます。
http://12factor.net/ja/config をどう実現するか考えるため。

Ruby on Rails

環境変数またはコマンドライン引数"RAILS_ENV"で指定する。

デフォルトで用意されている環境の種類は以下のとおり。

  • development
  • test
  • production

デフォルトはdevelopment

Sinatra

環境変数"RACK_ENV"で指定する。

デフォルトで用意されている環境の種類はRailsと同じ。デフォルトの環境がdevelopmentなのもRailsと同じ。

express

環境変数"NODE_ENV"で指定する。

デフォルトで用意されている環境の種類はRailsと同じ。デフォルトの環境がdevelopmentなのもRailsと同じ。

Spring Boot

下記どこかで指定した"SPRING_PROFILES_ACTIVE"が使われる。

  1. Command line arguments.
  2. Properties from SPRING_APPLICATION_JSON (inline JSON embedded in an environment variable or system property)
  3. JNDI attributes from java:comp/env.
  4. Java System properties (System.getProperties()).
  5. OS environment variables.
  6. A RandomValuePropertySource that only has properties in random.*.
  7. Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants)
  8. Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants)
  9. Application properties outside of your packaged jar (application.properties and YAML variants).
  10. Application properties packaged inside your jar (application.properties and YAML variants).
  11. @PropertySource annotations on your @Configuration classes.
  12. Default properties (specified using SpringApplication.setDefaultProperties).

デフォルトのプロファイルはdefault。慣例としてプロファイルは、application.properties(またはYAML)でそれごとにファイルを作る。

Seasar2

クラスパスに含まれる/env.txtで指定する。

デフォルトで用意されている環境の種類は以下のとおり。

  • ut: 単体テスト環境
  • ct: 結合テスト環境
  • it: 統合テスト環境
  • production: 本番環境

デフォルト(env.txtがない場合)の環境は、productionである。

Leiningen

leinコマンドの引数で使う(使わない)プロファイルを指定する。複数のプロファイルを重ね合わせることができる(Mavenからの思想継承)

lein with-profile 1.3 test :database

デフォルトでActiveになるプロファイルは以下のとおり。

  • :base
  • :system - providedスコープの依存ライブラリをクラスパスに含める
  • :user - ユーザごとの設定
  • :provided - providedスコープの依存ライブラリをクラスパスに含める
  • :dev

environ (clojure)

  • 12 Factor Appにしたがうように、環境変数から値をとるためのライブラリ。
  • Spring Bootと同じように、システムプロパティやファイルでも指定可能。
  • 同作者のductフレームワークみると、結局設定のグルーピングはやっている。
7
10
2

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