Skip to content

Commit 065fc90

Browse files
committed
Setup dotenv
1 parent e032586 commit 065fc90

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

ruby_on_rails/app_initialisation.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ Some other adjustments must be performed manually.
5959
6060
> ⭐️bin/check, bin/fastcheck and bin/run are standardized tools for more convenience at Renuo.
6161
62-
6362
### Secrets
6463

6564
We store the secrets necessary to configure the project locally in a 1password Item.

ruby_on_rails/template.rb

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,14 @@
88
RUBY
99
end
1010

11-
insert_into_file "Gemfile", after: /^group :development, :test do\n/ do
12-
<<~RUBY
13-
gem "dotenv"
14-
RUBY
15-
end
16-
1711
# replace bin/rails db:prepare with bin/rails db:setup in bin/setup
1812
gsub_file "bin/setup", "bin/rails db:prepare", "bin/rails db:setup"
1913

20-
# add the renuo fetch-secrets command and copying the dotenv file in bin/setup, before bin/rails db:setup
14+
# add the renuo fetch-secrets command in bin/setup, before bin/rails db:setup
2115
insert_into_file "bin/setup", before: "\n puts \"\\n== Preparing database ==\"" do
2216
<<-RUBY
2317
puts "\\n== Fetching 1password dependencies =="
2418
system! 'renuo fetch-secrets'
25-
26-
puts "\n== Copying sample files =="
27-
unless File.exist?('.env')
28-
system! 'cp .env.example .env'
29-
end
3019
RUBY
3120
end
3221

@@ -48,25 +37,43 @@
4837
RUBOCOP
4938
end
5039

40+
answer = ask("Do you want to setup dotenv? (y/n)", default: "y")
5141

52-
create_file ".env.example", force: true do
53-
<<~ENV
54-
SECRET_KEY_BASE=<%= `bin/rails secret`.strip %>
55-
APP_PORT=3000
56-
ENV
57-
end
42+
if answer.downcase == "y"
43+
insert_into_file "Gemfile", after: /^group :development, :test do\n/ do
44+
<<~RUBY
45+
gem "dotenv"
46+
RUBY
47+
end
5848

59-
create_file ".env", force: true do
60-
<<~ENV
61-
SECRET_KEY_BASE=#{`bin/rails secret`.strip}
62-
APP_PORT=3000
63-
ENV
64-
end
49+
create_file ".env.example", force: true do
50+
<<~ENV
51+
SECRET_KEY_BASE=<%= `bin/rails secret`.strip %>
52+
APP_PORT=3000
53+
ENV
54+
end
55+
56+
create_file ".env", force: true do
57+
<<~ENV
58+
SECRET_KEY_BASE=#{SecureRandom.hex(64)}
59+
APP_PORT=3000
60+
ENV
61+
end
62+
63+
create_file "config/initializers/dotenv.rb", force: true do
64+
<<~DOTENV
65+
Dotenv.require_keys(Dotenv.parse(".env.example").keys)
66+
DOTENV
67+
end
6568

66-
create_file "config/initializers/dotenv.rb", force: true do
67-
<<~DOTENV
68-
Dotenv.require_keys(Dotenv.parse(".env.example").keys)
69-
DOTENV
69+
insert_into_file "bin/setup", before: "\n puts \"\\n== Preparing database ==\"" do
70+
<<-RUBY
71+
puts "\n== Copying sample files =="
72+
unless File.exist?('.env')
73+
system! 'cp .env.example .env'
74+
end
75+
RUBY
76+
end
7077
end
7178

7279
create_file "bin/run", force: true do

0 commit comments

Comments
 (0)