From 1a7c0e626085ac3345ee6e38d4e9b783ec6bb186 Mon Sep 17 00:00:00 2001 From: "Ilya N. Zykin" Date: Thu, 23 Feb 2023 16:00:36 +0300 Subject: [PATCH] Add DotEnv --- .env | 17 +++++++++++++++++ .env.development | 5 +++++ .env.production | 5 +++++ .env.test | 4 ++++ .gitignore | 6 ++++++ Gemfile | 4 ++++ Gemfile.lock | 5 +++++ config/_CONFIG.yml | 10 +++++----- config/credentials.yml.enc | 1 - 9 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 .env create mode 100644 .env.development create mode 100644 .env.production create mode 100644 .env.test delete mode 100644 config/credentials.yml.enc diff --git a/.env b/.env new file mode 100644 index 0000000..ceb507e --- /dev/null +++ b/.env @@ -0,0 +1,17 @@ +# DotEnv file for All Environments +# +# It is added to the repo to provide most common and required ENV vars +# To demonstrate a full list of variables that we need for the application +# +# `config/credentials.yml.enc` and `/config/master.key` were deleted +# `Rails7. StartKit` does not rely on them for now +# +RAILS_VERSION=7.0.4.2 +SECRET_KEY_BASE=abracadabra +ENV_NAME=unknown + +REDIS_HOST=redis +REDIS_PORT=6379 + +ELASTIC_HOST=elastic +ELASTIC_PORT=9200 diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..df9718c --- /dev/null +++ b/.env.development @@ -0,0 +1,5 @@ +# DotEnv file for `development` environment +# +# This file should redefine `.env` and setup environment specific values +# +ENV_NAME=development diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..6111910 --- /dev/null +++ b/.env.production @@ -0,0 +1,5 @@ +# DotEnv file for `production` environment +# +# This file should redefine `.env` and setup environment specific values +# +ENV_NAME=production diff --git a/.env.test b/.env.test new file mode 100644 index 0000000..ecc56e4 --- /dev/null +++ b/.env.test @@ -0,0 +1,4 @@ +# DotEnv file for `test` environment +# +# This file should redefine `.env` and setup environment specific values +ENV_NAME=test diff --git a/.gitignore b/.gitignore index 32f9516..b22cc26 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,9 @@ config/environments/*.local.yml # gem SimpleCov coverage + +# Dot Env gem +/.env.local +/.env.test.local +/.env.development.local +/.env.production.local diff --git a/Gemfile b/Gemfile index 43f74f7..1c2d51b 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,10 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby "3.2.1" +# Rails7. Start Kit +# env variables +gem "dotenv-rails", "2.8.1", require: "dotenv/rails-now" + # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" gem "rails", "7.0.4.2" diff --git a/Gemfile.lock b/Gemfile.lock index 8334e90..74f0d85 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -100,6 +100,10 @@ GEM warden (~> 1.2.3) diff-lcs (1.5.0) docile (1.4.0) + dotenv (2.8.1) + dotenv-rails (2.8.1) + dotenv (= 2.8.1) + railties (>= 3.2) dry-configurable (1.0.1) dry-core (~> 1.0, < 2) zeitwerk (~> 2.6) @@ -362,6 +366,7 @@ DEPENDENCIES config (= 4.1.0)! debug (= 1.7.1) devise (= 4.8.1) + dotenv-rails (= 2.8.1) faker (= 3.1.0) importmap-rails (= 1.1.5) jbuilder (= 2.11.5) diff --git a/config/_CONFIG.yml b/config/_CONFIG.yml index a937b02..9bb0ff2 100644 --- a/config/_CONFIG.yml +++ b/config/_CONFIG.yml @@ -8,12 +8,12 @@ # Settings.app.rails.version app: rails: - version: "7" + version: <%= ENV['RAILS_VERSION'] %> redis: - host: redis - port: 6379 + host: <%= ENV['REDIS_HOST'] %> + port: <%= ENV['REDIS_PORT'] %> elastic: - host: elastic - port: 9200 + host: <%= ENV['ELASTIC_HOST'] %> + port: <%= ENV['ELASTIC_PORT'] %> diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc deleted file mode 100644 index 0b64dd5..0000000 --- a/config/credentials.yml.enc +++ /dev/null @@ -1 +0,0 @@ -Aw6ZaRQ7bh+dw2Qif+u7djnAO1uZgH9zywcVuVr053RmmFO+o7CGBXXzMCfFDgAgqoW4mFUiybnbNCkCdRmgYpL/SC4aLZfk90feTZqj/oAKZk5PiSfack1gcvAepcybyVSgHt9hHIOKxNjaRWzG5UPnfU77FZF7XvX5OHsR/BpiZmYx/A4CGddBrTIVkPUZocVdHWkn7BFuF2EhJMqAHul2/2iS/tRzJCHurvmvQew6zofbx4vGV+U5Hp8E2sh1Y1OAhR9o9dH/9o8wGx7NoVTBxiI9xezcmYYPzydlRN5j8NriA2Gq34jXus8XmW7dAAI1jCLl76bzmhtf+GJie9fcIuOGd1Zb+SDAPHlMUQJf3pLWIqw/AiOORjqR9PlKOH0pHH6FKExz1TkfSjoPWg2PsFVwFXtXslt4--oCA17I7Usj/7EIcj--mks/8TJqSYpbLnar9bZeZg== \ No newline at end of file