it needs fewer settings than other frameworks̶but it still needs some • Choosing something other than the default requires explicit con guration • Every framework needs application-speci c con guration fi fi fi fi fi Railsと言えば設定より規約、とはいえ全く設定しなくていいわけではない
• Infrastructure con guration • Middleware con guration • Rails and gem con guration • Application-speci c con guration fi fi fi fi fi fi Webアプリケーションを構成する設定はいろんなところにある
• Infrastructure con guration • Middleware con guration • Rails and gem con guration • Application-speci c con guration fi fi fi fi fi fi 今日は主にアプリケーション固有の設定の話をします
guration does not always live in just one place • Con guration values ows from its source, through intermediate layers, to the interface used by application code. fi fl fi fi fi 設定には“流れ”があり、起点・中継点・終点と値を受け渡して利用します
available as environment variables • Assign an environment variable to con g.x • The environment variable is the intermediate layer fi 起点に書かれた設定を、アプリケーションから利用可能な形に変換したものが 中継点
use, such as naming magic numbers • For application-wide settings, a dedicated place o ers: • Discoverability - Easy to nd and review • Consistency - Easier to keep settings organized and consistent • Environment Management - Easier to manage environment-speci c values fi ff fi fi 局所的な値であれば定数などに直接値を入れてもいいけど、基本的には分けて 管理した方が便利なことが多い
payment serviceʼs API secret key) • Must be stored securely, for example with encryption • Non-secrets(Examples: public external API URLs, database timeouts in seconds) • Can be managed in plain text • Whether a value needs to be secret depends on the environment (Example: database passwords) • Must be kept secret in production, but can often be stored in plain text in development fi 秘密の値は安全な形式で保存する必要があり、秘密の値かどうかは環境によっ て変わりうる
change it as part of a deployment • Developers or non-developers change it at any time • Example: feature ags • Requires external storage, such as a database • (This talk will not cover con guration management using external storage in depth) fi fl fi 任意のタイミングで変更したい設定値は、外部ストレージで扱う
• Sources and intermediaries often need to be considered together (for example, dotenv uses .env as the source and environment variables as the intermediate layer) • Consider con guration interfaces separately fi fi 起点・中継点・終点それぞれについてまとめていく(ただし起点と中継点はセ ットになっていることが多いので一緒に考える)
erent requirements, so putting everything in one place is not realistic • Consider the following categories • Secrets(Production, Development) • Non-secrets ff まとめるなら全部一つにしたらいいじゃん、とはいかないのが面倒なところ。 要件によって最適な方法が違うのであった
management services provided by your PaaS or IaaS are often useful (for example, Secrets Manager) • Fine-grained access control with IAM • Easy to pass values through environment variables when using ECS • Credentials is an option for small teams that do not need advanced features, or environments without a con guration management service (for example, a VPS) fi fi 本番環境用の秘密の値はお使いのクラウドサービスが提供しているやつが多機 能なのでオススメ
in development altogether (For example, use a local storage instead of accessing S3 directly) • In that case, use a tool such as 1Password to share secrets with the team through environment variables • For example, you can access .env through 1Password (note: this does not work through Docker)) • Another option is to use the 1Password CLI with direnv • export API̲KEY=$(op read op://YourVault/Payment/API̲KEY) 開発環境で秘密の値を扱わなければいけないときは1Passwordなどのパスワ ードマネージャを使いましょう
di erent sources in production and development in the same way • Tools such as fnox and SecretSpec can help • They abstract sources such as 1Password and Secrets Manager, providing a consistent interface across environments ff 起点を抽象化するためのツールとしてfnoxやSecretSpecなどがあります
• It provides transparent access to environment variables, .env les (in development), and Credentials • Lookup order: environment variables → .env les → Credentials fi fi Rails 8.2から使えるRails.app.credsで中継点をまとめることができる
con g̲for • Easy to de ne environment-speci c values and shared values • Supports more data types than environment variables fi fi fi fi fi 秘密ではない値やYAMLとcon g̲forがオススメ
how application code accesses con guration values • Direct access to environment variables, such as ENV.fetch('FOO') , is common, but I do not recommend it • I do not want to think about where con guration is stored! • A uni ed interface makes con guration easier to use • It also makes it easier to see which settings are available fi fi fi fi fi fi 終点では、起点と中継点について意識しないで統一的に扱いたい!
is hard to tell whether con gured values are correct • Especially in production • Con guration mistakes can cause outages, so we want to catch as many as possible • Catch as many con guration errors as possible, and make them harder to introduce fi fi fi 設定値が意図した値になっているのかを確認するのはとても難しい。意図して いない値が入らないようにしたり、意図していない値になったときにすぐ気づ けるようにしたい
you can check whether Stripe credentials are valid like this • But a temporary network error would cause the deployment to fail • This is an option if you can accept the trade-o , but that seems unlikely in most cases ff 設定が有効かどうかをチェックするのは難しい
For example • Converting types: use̲ssl = ENV.fetch('USE̲SSL') == 'true' • Combining values: url = "#{scheme}://#{host}:#{port}" • Tests for this kind of con guration processing are often skipped fi fi 設定値は型変換をしたり、他の設定と組み合わせたりなど変換をして使うこと があるけどそこのテストは省略されがち
• Automatically brings sources and intermediaries together in a con guration class • Lookup order: environment variables → Credentials → YAML • Checks for required values and supports validation • Type conversion • If the ideas make sense but you are unsure where to start, give it a try fi fi 「まとめる」と「確認しやすい形にする」をやりやすくする機能が揃っている ので結局どうしたらいいかわからない人は試してみて
up a web application • We used those categories to explore how to design con guration that avoids accumulating technical debt • The core principles: consolidate and make it easy to verify • We covered several recommendations, but no single best practice ts every environment̶these principles matter more fi fi fi fi 設定に関する銀の弾丸はないので「まとめる」「確認しやすい形にする」で設 計してみて下さい