Osaka RubyKaigi 03のLT会で発表したスライドです。
Copyright © 2023 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止RAILS_ENVを統合する取り組み:開発用デプロイ環境をよりシンプルに明里 慶祐株式会社 アンドパッド2023/9/9大阪Ruby会議03 LT
View Slide
Copyright © 2023 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止1. 自己紹介株式会社アンドパッド / プラットフォーム開発チーム 明里 慶祐@k-akari@akarin05192022年5月入社。2023年3月まで、社内で最も古くから稼働する施工管理アプリ(Rails)のインフラ・CI/CD改善に従事。2023年4月よりANDPADの通知プラットフォーム(Go言語、gRPCサーバ)の開発に従事。Confidential
Copyright © 2023 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止2. 施工管理アプリとはConfidential社内で最も古くから稼働している巨大でモノリシックなRailsアプリケーション
Copyright © 2023 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止3. 改善前の施工管理アプリConfidential● デプロイ環境とRails.envが一対一● Rails.envが16個データベースRailsアプリケーション(Rails.env = staging)データベースRailsアプリケーション(Rails.env = staging2)データベースRailsアプリケーション(Rails.env = staging3)staging環境 staging2環境 staging3環境
Copyright © 2023 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止4. 何が問題なのか● 本番環境と厳密にコードが同一となる環境が存在しない。○ デプロイ環境毎にconfig/environmentsなどが異なる。○ Rails.envによる分岐ロジックが実装可能になる。● デプロイ環境毎の差分が把握しにくい。(=認知負荷高)○ config/environments?○ config/settings? (config gemを利用している場合)○ 環境変数?○ Rails.envの分岐ロジック?Confidential
Copyright © 2023 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止5. 解決方針● デプロイ環境ごとに異なる設定を全て環境変数化する。○ The Twelve-Factor Appでも推奨されている。● Rails.envを標準の3つ + stagingの合計4つにまで減らす。○ 最終的にはRails.envを標準の3つだけにしたい。Confidentialやることはシンプル!!!だが、地味で面倒😇まあ、やるしかない💪
Copyright © 2023 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止6. 取り組み手順1. 方針をDesign Docとしてまとめ、関係者の同意を得る。2. アプリケーションコードに記述されたRails.envによる分岐ロジックをconfig gemを利用した分岐ロジックに置き換える。例)Rails.env.production? => Settings.deploy_env==”production”3. 開発環境のconfig/environmentsファイルを統一する。デプロイ環境差分はconfig gemを利用して分岐させる。例)redis_host: Settings.redis.host4. デプロイ環境毎に異なる設定値を環境変数化し、config gemには環境変数の値を参照させる。例)host: <%= ENV.fetch('HOST') %>Confidential
Copyright © 2023 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止7. 結果● Rails.envを5つにまで削減🎉(残り一つはデプロイ環境ごと廃止予定。)○ これにより、デプロイ環境毎に異なる設定値は環境変数に設定するしか方法がない。● 要した期間はおよそ8ヶ月(2022年8月〜2023年3月)。Confidential
Copyright © 2023 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止8. 教訓● デプロイ環境毎にRails.envは増やさないでおく。○ デプロイ環境毎に異なる設定値がRails.envによって切り替わることを防げる。● デプロイ環境ごとに異なる設定は環境変数で一元管理する。Confidential
Copyright © 2023 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止9. 終わりにご清聴ありがとうございました🙏Confidential