=> ERROR [build 7/7] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile

I am getting to errors when i compose my file one main one is related to managing the description MASTER_KEY and how to handle it when i am trying to build my docker

and the second one is related to letter opener
Would assistance from the community


C:\Users\user\last\64635>docker build .
[+] Building 14.3s (18/22)                                                                               docker:default
 => [internal] load build definition from Dockerfile                                                               0.0s
 => => transferring dockerfile: 2.21kB                                                                             0.0s
 => [internal] load .dockerignore                                                                                  0.1s
 => => transferring context: 756B                                                                                  0.0s
 => resolve image config for docker.io/docker/dockerfile:1                                                         3.4s
 => [auth] docker/dockerfile:pull token for registry-1.docker.io                                                   0.0s
 => CACHED docker-image://docker.io/docker/dockerfile:1@sha256:ac85f380a63b13dfcefa89046420e1781752bab202122f8f50  0.0s
 => [internal] load metadata for docker.io/library/ruby:3.2.2-slim                                                 2.5s
 => [auth] library/ruby:pull token for registry-1.docker.io                                                        0.0s
 => [internal] load build context                                                                                  0.2s
 => => transferring context: 60.73kB                                                                               0.2s
 => [base 1/3] FROM docker.io/library/ruby:3.2.2-slim@sha256:9654f1d43acae3032456fa89381076d3b997ea35d53259cf78a7  0.0s
 => => resolve docker.io/library/ruby:3.2.2-slim@sha256:9654f1d43acae3032456fa89381076d3b997ea35d53259cf78a7db65b  0.0s
 => CACHED [base 2/3] WORKDIR /rails                                                                               0.0s
 => CACHED [base 3/3] RUN gem update --system --no-document &&     gem install -N bundler                          0.0s
 => CACHED [build 1/7] RUN apt-get update -qq &&     apt-get install --no-install-recommends -y build-essential p  0.0s
 => CACHED [build 2/7] COPY --link Gemfile Gemfile.lock ./                                                         0.0s
 => CACHED [build 3/7] RUN bundle install &&     bundle exec bootsnap precompile --gemfile &&     rm -rf ~/.bundl  0.0s
 => [build 4/7] COPY --link . .                                                                                    0.1s
 => [build 5/7] RUN bundle exec bootsnap precompile app/ lib/                                                      2.4s
 => [build 6/7] RUN chmod +x bin/*                                                                                 0.6s
 => ERROR [build 7/7] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile                                      4.6s
------
 > [build 7/7] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile:
4.510 rails aborted!
4.512 NameError: uninitialized constant LetterOpenerWeb

I don’t exactly follow, but it looks like LetterOpenerWeb is being called from your application and it’s not finding it. You probably have LetterOpenerWeb in the development gem group, but your code is accessing it from the production environment.

You either need to remove the code that’s referencing that library or add the gem to your production Gemfile.

Tryin running ./bin/rails assets:precompile locally too and see if that works.

Yes, i have managed to solve the LetterOpenerWeb issues by creating a production do file alternative to run it

group :development do
  # Use console on exceptions pages [https://github.com/rails/web-console]
  gem "web-console"
  gem "letter_opener_web"
  # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
  # gem "rack-mini-profiler"

  # Speed up commands on slow machines / big apps [https://github.com/rails/spring]
  # gem "spring"
end

group :production do

  
  gem "letter_opener_web"

end


group :test do
  # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
  gem "capybara"
  gem "selenium-webdriver"
  gem "webdrivers"
end

But i am encountering a new error

argumentError: Missing secret_key_basefor 'production' environment, set this string withbin/rails credentials:edit`

Did you try this?

yes, here is how i tried going around it

C:\Users\user\last\64635>set rails credentials:edit
RAILS_MASTER_KEY=06dc6d87e1e3ec5cba02a85590c1e842

[+] Building 38.8s (21/21) FINISHED                                                                                                                          docker:default
 => [internal] load build definition from Dockerfile                                                                                                                   0.0s
 => => transferring dockerfile: 2.22kB                                                                                                                                 0.0s
 => [internal] load .dockerignore                                                                                                                                      0.1s
 => => transferring context: 756B                                                                                                                                      0.0s
 => resolve image config for docker.io/docker/dockerfile:1                                                                                                             1.4s
 => CACHED docker-image://docker.io/docker/dockerfile:1@sha256:ac85f380a63b13dfcefa89046420e1781752bab202122f8f50032edf31be0021                                        0.0s
 => [internal] load metadata for docker.io/library/ruby:3.2.2-slim                                                                                                     1.1s
 => [internal] load build context                                                                                                                                      0.1s
 => => transferring context: 7.75kB                                                                                                                                    0.0s
 => [base 1/3] FROM docker.io/library/ruby:3.2.2-slim@sha256:9654f1d43acae3032456fa89381076d3b997ea35d53259cf78a7db65b2e2121e                                          0.0s
 => => resolve docker.io/library/ruby:3.2.2-slim@sha256:9654f1d43acae3032456fa89381076d3b997ea35d53259cf78a7db65b2e2121e                                               0.0s
 => CACHED [base 2/3] WORKDIR /rails                                                                                                                                   0.0s
 => CACHED [base 3/3] RUN gem update --system --no-document &&     gem install -N bundler                                                                              0.0s
 => CACHED [build 1/7] RUN apt-get update -qq &&     apt-get install --no-install-recommends -y build-essential pkg-config                                             0.0s
 => CACHED [build 2/7] COPY --link Gemfile Gemfile.lock ./                                                                                                             0.0s
 => CACHED [build 3/7] RUN bundle install &&     bundle exec bootsnap precompile --gemfile &&     rm -rf ~/.bundle/ $BUNDLE_PATH/ruby/*/cache $BUNDLE_PATH/ruby/*/bun  0.0s
 => [build 4/7] COPY --link . .                                                                                                                                        0.1s
 => [build 5/7] RUN bundle exec bootsnap precompile app/ lib/                                                                                                          1.4s
 => [build 6/7] RUN chmod +x bin/*                                                                                                                                     0.6s
 => [build 7/7] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile                                                                                                3.0s
 => CACHED [stage-2 1/4] RUN apt-get update -qq &&     apt-get install --no-install-recommends -y curl libsqlite3-0 &&     rm -rf /var/lib/apt/lists /var/cache/apt/a  0.0s
 => CACHED [stage-2 2/4] COPY --from=build /usr/local/bundle /usr/local/bundle                                                                                         0.0s
 => [stage-2 3/4] COPY --from=build /rails /rails                                                                                                                      2.3s
 => [stage-2 4/4] RUN useradd rails --create-home --shell /bin/bash &&     mkdir /data &&     chown -R rails:rails db log storage tmp /data                           24.1s
 => exporting to image                                                                                                                                                 2.4s
 => => exporting layers                                                                                                                                                2.3s
 => => writing image sha256:848eb481a1b937410cd2f04cf31c386ea7cd1f750f212474c54650349978405c                                                                           0.0s

What's Next?
  View summary of image vulnerabilities and recommendations → docker scout quickview

C:\Users\user\last\64635>docker run 848eb481a1b937410cd2f04cf31c386ea7cd1f750f212474c54650349978405c
rails aborted!
ArgumentError: Missing `secret_key_base` for 'production' environment, set this string with `bin/rails credentials:edit`
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.7/lib/rails/application.rb:576:in `validate_secret_key_base'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.7/lib/rails/application.rb:419:in `secret_key_base'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.7/lib/rails/application.rb:157:in `key_generator'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.7/lib/rails/application.rb:181:in `message_verifier'
/rails/vendor/bundle/ruby/3.2.0/gems/activestorage-7.0.7/lib/active_storage/engine.rb:137:in `block (2 levels) in <class:Engine>'
/rails/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.7/lib/active_support/lazy_load_hooks.rb:92:in `block in execute_hook'
/rails/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.7/lib/active_support/lazy_load_hooks.rb:85:in `with_execution_control'
/rails/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.7/lib/active_support/lazy_load_hooks.rb:90:in `execute_hook'
/rails/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.7/lib/active_support/lazy_load_hooks.rb:76:in `block in run_load_hooks'
/rails/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.7/lib/active_support/lazy_load_hooks.rb:75:in `each'
/rails/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.7/lib/active_support/lazy_load_hooks.rb:75:in `run_load_hooks'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.7/lib/rails/application/finisher.rb:87:in `block in <module:Finisher>'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.7/lib/rails/initializable.rb:32:in `instance_exec'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.7/lib/rails/initializable.rb:32:in `run'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.7/lib/rails/initializable.rb:61:in `block in run_initializers'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.7/lib/rails/initializable.rb:60:in `run_initializers'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.7/lib/rails/application.rb:372:in `initialize!'
/rails/config/environment.rb:5:in `<main>'
/rails/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/rails/vendor/bundle/ruby/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/kernel.rb:38:in `require'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.7/lib/rails/application.rb:348:in `require_environment!'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.7/lib/rails/application.rb:506:in `block in run_tasks_blocks'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
/rails/vendor/bundle/ruby/3.2.0/gems/sentry-ruby-5.10.0/lib/sentry/rake.rb:24:in `execute'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:243:in `block in invoke_prerequisites'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:243:in `block in invoke_prerequisites'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.7/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.7/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.7/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.7/lib/rails/command.rb:51:in `invoke'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.7/lib/rails/commands.rb:18:in `<main>'
/rails/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
Tasks: TOP => db:prepare => db:load_config => environment
(See full trace by running task with --trace)

@rubys here is my dockerfile

# syntax = docker/dockerfile:1

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.2.2
FROM ruby:$RUBY_VERSION-slim as base

LABEL fly_launch_runtime="rails"

# Rails app lives here
WORKDIR /rails

# Set production environment
ENV RAILS_ENV="production" \
    BUNDLE_WITHOUT="development:test" \
    BUNDLE_DEPLOYMENT="1"

# Update gems and bundler
RUN gem update --system --no-document && \
    gem install -N bundler


# Throw-away build stage to reduce size of final image
FROM base as build

# Install packages needed to build gems
RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y build-essential pkg-config

# Install application gems
COPY --link Gemfile Gemfile.lock ./
RUN bundle install && \
    bundle exec bootsnap precompile --gemfile && \
    rm -rf ~/.bundle/ $BUNDLE_PATH/ruby/*/cache $BUNDLE_PATH/ruby/*/bundler/gems/*/.git

# Copy application code
COPY --link . .

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/

# Adjust binfiles to be executable on Linux
RUN chmod +x bin/*






# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile



# Final stage for app image
FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y curl libsqlite3-0 && \
    rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build /rails /rails

# Run and own only the runtime files as a non-root user for security
RUN useradd rails --create-home --shell /bin/bash && \
    mkdir /data && \
    chown -R rails:rails db log storage tmp /data
USER rails:rails

# Deployment options
ENV DATABASE_URL="sqlite3:///data/production.sqlite3" \
    RAILS_LOG_TO_STDOUT="1" \
    RAILS_SERVE_STATIC_FILES="true"

# Entrypoint prepares the database.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
VOLUME /data
CMD ["./bin/rails", "server"]

Try without set. See Securing Rails Applications — Ruby on Rails Guides for more information.

sure @rubys when i do that i successfully generate this

crendetial.yml
ws:
   access_key_id: 123
   secret_access_key: 345

 production:
  secret_key_base: e38a629b893098e71227e2708e5124409cccxxx86365c513e3e2274bd1e73e101533f57de1f5835cd5c4eec9db579be991140d59dae4a40917e2226a4164205df1e85

my question is how can i actually parse this keys succefully

Try removing the line containing production: and removing all indentation from the secret_key_base line.

Hello there, @rubys. Everything is working well now. The primary issue seems to be parsing the master.key to fly; I tried it locally by running docaker but it didn’t add up. So I believed something was amiss with the locally environment and used this command, which worked!

`

``
fly secrets set RAILS_MASTER_KEY=$(cat config/master.key)
If you are non-windows user you can use a respective commands

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.