Fix mastodon:setup to take dotenv/docker-compose differences into account (#16896)
In order to work around https://github.com/mastodon/mastodon/issues/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-composeshrike
parent
11d4f9eefc
commit
5ba46952af
|
@ -4,6 +4,12 @@
|
||||||
# not demonstrate all available configuration options. Please look at
|
# not demonstrate all available configuration options. Please look at
|
||||||
# https://docs.joinmastodon.org/admin/config/ for the full documentation.
|
# https://docs.joinmastodon.org/admin/config/ for the full documentation.
|
||||||
|
|
||||||
|
# Note that this file accepts slightly different syntax depending on whether
|
||||||
|
# you are using `docker-compose` or not. In particular, if you use
|
||||||
|
# `docker-compose`, the value of each declared variable will be taken verbatim,
|
||||||
|
# including surrounding quotes.
|
||||||
|
# See: https://github.com/mastodon/mastodon/issues/16895
|
||||||
|
|
||||||
# Federation
|
# Federation
|
||||||
# ----------
|
# ----------
|
||||||
# This identifies your server and cannot be changed safely later
|
# This identifies your server and cannot be changed safely later
|
||||||
|
|
|
@ -333,8 +333,12 @@ namespace :mastodon do
|
||||||
prompt.say 'This configuration will be written to .env.production'
|
prompt.say 'This configuration will be written to .env.production'
|
||||||
|
|
||||||
if prompt.yes?('Save configuration?')
|
if prompt.yes?('Save configuration?')
|
||||||
|
incompatible_syntax = false
|
||||||
|
|
||||||
env_contents = env.each_pair.map do |key, value|
|
env_contents = env.each_pair.map do |key, value|
|
||||||
if value.is_a?(String) && value =~ /[\s\#\\"]/
|
if value.is_a?(String) && value =~ /[\s\#\\"]/
|
||||||
|
incompatible_syntax = true
|
||||||
|
|
||||||
if value =~ /[']/
|
if value =~ /[']/
|
||||||
value = value.to_s.gsub(/[\\"\$]/) { |x| "\\#{x}" }
|
value = value.to_s.gsub(/[\\"\$]/) { |x| "\\#{x}" }
|
||||||
"#{key}=\"#{value}\""
|
"#{key}=\"#{value}\""
|
||||||
|
@ -346,12 +350,19 @@ namespace :mastodon do
|
||||||
end
|
end
|
||||||
end.join("\n")
|
end.join("\n")
|
||||||
|
|
||||||
File.write(Rails.root.join('.env.production'), "# Generated with mastodon:setup on #{Time.now.utc}\n\n" + env_contents + "\n")
|
generated_header = "# Generated with mastodon:setup on #{Time.now.utc}\n\n"
|
||||||
|
|
||||||
|
if incompatible_syntax
|
||||||
|
generated_header << "Some variables in this file will be interpreted differently whether you are\n"
|
||||||
|
generated_header << "using docker-compose or not.\n\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
File.write(Rails.root.join('.env.production'), "#{generated_header}#{env_contents}\n")
|
||||||
|
|
||||||
if using_docker
|
if using_docker
|
||||||
prompt.ok 'Below is your configuration, save it to an .env.production file outside Docker:'
|
prompt.ok 'Below is your configuration, save it to an .env.production file outside Docker:'
|
||||||
prompt.say "\n"
|
prompt.say "\n"
|
||||||
prompt.say File.read(Rails.root.join('.env.production'))
|
prompt.say "#{generated_header}#{env.each_pair.map { |key, value| "#{key}=#{value}" }.join("\n")}"
|
||||||
prompt.say "\n"
|
prompt.say "\n"
|
||||||
prompt.ok 'It is also saved within this container so you can proceed with this wizard.'
|
prompt.ok 'It is also saved within this container so you can proceed with this wizard.'
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue