Selectively skipping code during assets:precompile #19
-
I'm using a gem that I initialize by looking up a secret key from the Rails credentials file. When the asset compilation is done in the Dockerfile, this results in an error because I'm not providing the master key. I know I can move the secret key into an environment variable but I prefer to keep things in the credentials file where possible. I see that the option to defer asset precompilation has been added recently, but I prefer to precompile. I came up with this hack: '# Precompiling assets for production without requiring secret RAILS_MASTER_KEY.
# You can skip an initializer that you don't want to run during this phase by checking for the existence of
# ENV["RUNNING_ASSETS_PRECOMPILE"]. (see config/initializers/shrine.rb)
RUN RUNNING_ASSETS_PRECOMPILE=1 SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile # RUNNING_ASSETS_PRECOMPILE is set to true when running assets:precompile in the Dockerfile. This is to prevent the app
# from accessing credentials when compiling assets.
unless ENV["RUNNING_ASSETS_PRECOMPILE"]
Shrine.plugin :derivation_endpoint, secret_key: Rails.application.credentials.shrine_secret_key
end Now I can selectively wrap any piece of code that I don't need to run during the asset precompilation stage. Has anyone found a better way to do this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Perhaps try: if Rails.application.credentials.shrine_secret_key
Shrine.plugin :derivation_endpoint, secret_key: Rails.application.credentials.shrine_secret_key
end |
Beta Was this translation helpful? Give feedback.
Perhaps try: