I’ve been trying to deploy some changes on my rails app and get the following error:
ERROR [build 9/9] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile
I’ve integrated stripe to my app and deleted credentials I had on ENV file and added them again using EDITOR=vim rails credentials:edit
.
After running fly deploy
I get the following:
> [build 9/9] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile:
#19 0.947 /usr/local/lib/ruby/2.7.0/net/protocol.rb:66: warning: already initialized constant Net::ProtocRetryError
#19 0.947 /rails/vendor/bundle/ruby/2.7.0/gems/net-protocol-0.2.1/lib/net/protocol.rb:68: warning: previous definition of ProtocRetryError was here
#19 0.948 /usr/local/lib/ruby/2.7.0/net/protocol.rb:206: warning: already initialized constant Net::BufferedIO::BUFSIZE
#19 0.948 /rails/vendor/bundle/ruby/2.7.0/gems/net-protocol-0.2.1/lib/net/protocol.rb:214: warning: previous definition of BUFSIZE was here
#19 0.948 /usr/local/lib/ruby/2.7.0/net/protocol.rb:503: warning: already initialized constant Net::NetPrivate::Socket
#19 0.948 /rails/vendor/bundle/ruby/2.7.0/gems/net-protocol-0.2.1/lib/net/protocol.rb:541: warning: previous definition of Socket was here
#19 1.108 rails aborted!
#19 1.109 NoMethodError: undefined method `[]' for nil:NilClass
#19 1.109 /rails/config/initializers/stripe.rb:3:in `<main>'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.7.2/lib/active_support/dependencies.rb:326:in `load'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.7.2/lib/active_support/dependencies.rb:326:in `block in load'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.7.2/lib/active_support/dependencies.rb:299:in `load_dependency'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.7.2/lib/active_support/dependencies.rb:326:in `load'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/railties-6.1.7.2/lib/rails/engine.rb:681:in `block in load_config_initializer'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.7.2/lib/active_support/notifications.rb:205:in `instrument'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/railties-6.1.7.2/lib/rails/engine.rb:680:in `load_config_initializer'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/railties-6.1.7.2/lib/rails/engine.rb:634:in `block (2 levels) in <class:Engine>'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/railties-6.1.7.2/lib/rails/engine.rb:633:in `each'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/railties-6.1.7.2/lib/rails/engine.rb:633:in `block in <class:Engine>'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/railties-6.1.7.2/lib/rails/initializable.rb:32:in `instance_exec'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/railties-6.1.7.2/lib/rails/initializable.rb:32:in `run'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/railties-6.1.7.2/lib/rails/initializable.rb:61:in `block in run_initializers'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/railties-6.1.7.2/lib/rails/initializable.rb:50:in `each'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/railties-6.1.7.2/lib/rails/initializable.rb:50:in `tsort_each_child'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/railties-6.1.7.2/lib/rails/initializable.rb:60:in `run_initializers'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/railties-6.1.7.2/lib/rails/application.rb:391:in `initialize!'
#19 1.109 /rails/config/environment.rb:5:in `<main>'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/zeitwerk-2.6.7/lib/zeitwerk/kernel.rb:38:in `require'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.7.2/lib/active_support/dependencies.rb:332:in `block in require'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.7.2/lib/active_support/dependencies.rb:299:in `load_dependency'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.7.2/lib/active_support/dependencies.rb:332:in `require'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/railties-6.1.7.2/lib/rails/application.rb:367:in `require_environment!'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/railties-6.1.7.2/lib/rails/application.rb:533:in `block in run_tasks_blocks'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/sprockets-rails-3.4.2/lib/sprockets/rails/task.rb:61:in `block (2 levels) in define'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:243:in `block in invoke_prerequisites'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/railties-6.1.7.2/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/railties-6.1.7.2/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/railties-6.1.7.2/lib/rails/commands/rake/rake_command.rb:18:in `perform'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/railties-6.1.7.2/lib/rails/command.rb:50:in `invoke'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/railties-6.1.7.2/lib/rails/commands.rb:18:in `<main>'
#19 1.109 /rails/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
#19 1.109 Tasks: TOP => environment
#19 1.109 (See full trace by running task with --trace)
------
Error failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile]: exit code: 1
My Dockerfile looks as follows:Preformatted text
# syntax = docker/dockerfile:1
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=2.7.4
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 and node modules
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential curl libpq-dev node-gyp pkg-config python-is-python3
# Install JavaScript dependencies
ARG NODE_VERSION=14.15.5
ARG YARN_VERSION=1.22.19
ENV PATH=/usr/local/node/bin:$PATH
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
npm install -g yarn@$YARN_VERSION && \
rm -rf /tmp/node-build-master
# Install application gems
COPY Gemfile Gemfile.lock .
RUN bundle install && \
bundle exec bootsnap precompile --gemfile
# Install node modules
COPY package.json yarn.lock .
RUN yarn install --frozen-lockfile
# Copy application code
COPY . .
# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/
# 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 postgresql-client && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives
# Run and own the application files as a non-root user for security
RUN useradd rails
USER rails:rails
# Copy built artifacts: gems, application
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build --chown=rails:rails /rails /rails
# Deployment options
ENV 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
CMD ["./bin/rails", "server"]