Skip to content

Commit afe1c4e

Browse files
ClearlyClairekadoshita
authored andcommitted
Fix mastodon:setup to take dotenv/docker-compose differences into account (mastodon#16896)
In order to work around mastodon#16895, add a warning to .env.production.sample, and change the mastodon:setup rake task to: - output a warning if a variable will be interpreted differently by dotenv and docker-compose - ensure the printed config is compatible with docker-compose
1 parent 583fc6e commit afe1c4e

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

.env.production.sample

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
# not demonstrate all available configuration options. Please look at
55
# https://docs.joinmastodon.org/admin/config/ for the full documentation.
66

7+
# Note that this file accepts slightly different syntax depending on whether
8+
# you are using `docker-compose` or not. In particular, if you use
9+
# `docker-compose`, the value of each declared variable will be taken verbatim,
10+
# including surrounding quotes.
11+
# See: https://github.com/mastodon/mastodon/issues/16895
12+
713
# Federation
814
# ----------
915
# This identifies your server and cannot be changed safely later

lib/tasks/mastodon.rake

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,12 @@ namespace :mastodon do
333333
prompt.say 'This configuration will be written to .env.production'
334334

335335
if prompt.yes?('Save configuration?')
336+
incompatible_syntax = false
337+
336338
env_contents = env.each_pair.map do |key, value|
337339
if value.is_a?(String) && value =~ /[\s\#\\"]/
340+
incompatible_syntax = true
341+
338342
if value =~ /[']/
339343
value = value.to_s.gsub(/[\\"\$]/) { |x| "\\#{x}" }
340344
"#{key}=\"#{value}\""
@@ -346,12 +350,19 @@ namespace :mastodon do
346350
end
347351
end.join("\n")
348352

349-
File.write(Rails.root.join('.env.production'), "# Generated with mastodon:setup on #{Time.now.utc}\n\n" + env_contents + "\n")
353+
generated_header = "# Generated with mastodon:setup on #{Time.now.utc}\n\n"
354+
355+
if incompatible_syntax
356+
generated_header << "Some variables in this file will be interpreted differently whether you are\n"
357+
generated_header << "using docker-compose or not.\n\n"
358+
end
359+
360+
File.write(Rails.root.join('.env.production'), "#{generated_header}#{env_contents}\n")
350361

351362
if using_docker
352363
prompt.ok 'Below is your configuration, save it to an .env.production file outside Docker:'
353364
prompt.say "\n"
354-
prompt.say File.read(Rails.root.join('.env.production'))
365+
prompt.say "#{generated_header}#{env.each_pair.map { |key, value| "#{key}=#{value}" }.join("\n")}"
355366
prompt.say "\n"
356367
prompt.ok 'It is also saved within this container so you can proceed with this wizard.'
357368
end

0 commit comments

Comments
 (0)