Skip to content

Conversation

@yosifkit
Copy link
Member

@yosifkit yosifkit commented Oct 7, 2025

Fixes #397

# https://github.com/docker-library/redmine/issues/397
# empty string is truthy in ruby and so masks the generated fallback config
# https://github.com/rails/rails/blob/1aa9987169213ce5ce43c20b2643bc64c235e792/railties/lib/rails/application.rb#L454
export SECRET_KEY_BASE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think the bug is really closer to missing the unset SECRET_KEY_BASE below when it's empty and we already have a secret_token.rb, right? Maybe we should be more explicit about that half instead of the export half?

@tianon
Copy link
Member

tianon commented Oct 8, 2025

I pushed another commit, but I'm not convinced I actually like it - the original had simpler logic.

Comment on lines 159 to 164
fi
# generate SECRET_KEY_BASE if not set; this is not recommended unless the secret_token.rb is saved when container is recreated
if [ -z "$SECRET_KEY_BASE" ] && [ ! -f config/initializers/secret_token.rb ]; then
# generate SECRET_KEY_BASE in-file if not set; this is not recommended unless the secret_token.rb is saved when container is recreated
if [ -z "${SECRET_KEY_BASE:-}" ] && [ ! -f config/initializers/secret_token.rb ]; then
echo >&2 'warning: no *SECRET_KEY_BASE set; running `rake generate_secret_token` to create one in "config/initializers/secret_token.rb"'
unset SECRET_KEY_BASE # just in case
rake generate_secret_token
fi
Copy link
Member Author

@yosifkit yosifkit Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I like your change better but maybe we should also combine this second if to be inside the first rather than repeating the condition?

# left out indentation changes
-	fi
	# generate SECRET_KEY_BASE in-file if not set; this is not recommended unless the secret_token.rb is saved when container is recreated
-	if [ -z "${SECRET_KEY_BASE:-}" ] && [ ! -f config/initializers/secret_token.rb ]; then
+	if [ ! -f config/initializers/secret_token.rb ]; then
		echo >&2 'warning: no *SECRET_KEY_BASE set; running `rake generate_secret_token` to create one in "config/initializers/secret_token.rb"'
		rake generate_secret_token
	fi
+	fi

Comment on lines 158 to 159
unset SECRET_KEY_BASE
# generate SECRET_KEY_BASE in-file if not set; this is not recommended unless the secret_token.rb is saved when container is recreated
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The juxtaposition of "unset" followed by "if not set". 😆

Suggested change
unset SECRET_KEY_BASE
# generate SECRET_KEY_BASE in-file if not set; this is not recommended unless the secret_token.rb is saved when container is recreated
unset SECRET_KEY_BASE
# generate SECRET_KEY_BASE in-file since it is not set or empty; this is not recommended unless the secret_token.rb is saved when container is recreated

Copy link
Member Author

@yosifkit yosifkit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it's as much your PR as it is mine ❤️🙈, but LGTM.

@tianon tianon merged commit 01d5e42 into docker-library:master Oct 8, 2025
25 checks passed
@tianon tianon deleted the empty-truth branch October 8, 2025 23:35
docker-library-bot added a commit to docker-library-bot/official-images that referenced this pull request Oct 8, 2025
Changes:

- docker-library/redmine@01d5e42: Fix for rails getting confused by an empty env var (docker-library/redmine#398)
StamatisKourk pushed a commit to elastic/official-images that referenced this pull request Nov 11, 2025
Changes:

- docker-library/redmine@01d5e42: Fix for rails getting confused by an empty env var (docker-library/redmine#398)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Container restart causes HTTP 500 due to empty SECRET_KEY_BASE

2 participants