Error: failed to fetch an image or build from source: error building: failed to solve: executor failed running [/bin/sh -c SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile]: exit code: 1

I’ve configure sendgrid account but when I try to add the secrets my deploy fails.

Remote builder fly-builder-red-wildflower-1038 ready
==> Building image with Docker
--> docker host: 20.10.12 linux x86_64
[+] Building 3.9s (21/24)
 => [internal] load build definition from Dockerfile                                                                                                                                              0.2s
 => => transferring dockerfile: 2.68kB                                                                                                                                                            0.2s
 => [internal] load .dockerignore                                                                                                                                                                 0.1s
 => => transferring context: 35B                                                                                                                                                                  0.1s
 => resolve image config for docker.io/docker/dockerfile:1                                                                                                                                        1.0s
 => CACHED docker-image://docker.io/docker/dockerfile:1@sha256:ac85f380a63b13dfcefa89046420e1781752bab202122f8f50032edf31be0021                                                                   0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                              0.0s
 => [internal] load metadata for docker.io/library/ruby:3.2.2-slim                                                                                                                                0.3s
 => [internal] load .dockerignore                                                                                                                                                                 0.0s
 => [internal] load build context                                                                                                                                                                 0.3s
 => => transferring context: 26.81kB                                                                                                                                                              0.3s
 => [base 1/3] FROM docker.io/library/ruby:3.2.2-slim@sha256:b86f08332ea5f9b73c427018f28af83628c139567cc72823270cac6ab056c4dc                                                                     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 [stage-2 1/4] RUN apt-get update -qq &&     apt-get install --no-install-recommends -y postgresql-client &&     rm -rf /var/lib/apt/lists /var/cache/apt/archives                      0.0s
 => CACHED [build 1/9] RUN apt-get update -qq &&     apt-get install --no-install-recommends -y build-essential curl libpq-dev node-gyp pkg-config python-is-python3                              0.0s
 => CACHED [build 2/9] RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ &&     /tmp/node-build-master/bin/node-build "18.16.0" /usr/local/node &&     n  0.0s
 => CACHED [build 3/9] COPY --link Gemfile Gemfile.lock ./                                                                                                                                        0.0s
 => CACHED [build 4/9] RUN bundle install &&     bundle exec bootsnap precompile --gemfile &&     rm -rf ~/.bundle/ $BUNDLE_PATH/ruby/*/cache $BUNDLE_PATH/ruby/*/bundler/gems/*/.git             0.0s
 => CACHED [build 5/9] COPY --link package.json package-lock.json yarn.lock ./                                                                                                                    0.0s
 => CACHED [build 6/9] RUN yarn install --frozen-lockfile                                                                                                                                         0.0s
 => [build 7/9] COPY --link . .                                                                                                                                                                   0.1s
 => [build 8/9] RUN bundle exec bootsnap precompile app/ lib/                                                                                                                                     0.8s
 => ERROR [build 9/9] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile                                                                                                                     1.2s
------
 > [build 9/9] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile:
#0 1.158 rails aborted!
#0 1.158 KeyError: key not found: "SMTP_PORT"
#0 1.158 /rails/config/environments/production.rb:69:in `fetch'
#0 1.158 /rails/config/environments/production.rb:69:in `block in <main>'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/railtie.rb:257:in `instance_eval'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/railtie.rb:257:in `configure'
#0 1.158 /rails/config/environments/production.rb:3:in `<main>'
#0 1.158 /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'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/zeitwerk-2.6.7/lib/zeitwerk/kernel.rb:38:in `require'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/engine.rb:562:in `block (2 levels) in <class:Engine>'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/engine.rb:561:in `each'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/engine.rb:561:in `block in <class:Engine>'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/initializable.rb:32:in `instance_exec'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/initializable.rb:32:in `run'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/initializable.rb:61:in `block in run_initializers'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/initializable.rb:50:in `each'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/initializable.rb:50:in `tsort_each_child'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/initializable.rb:60:in `run_initializers'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/application.rb:372:in `initialize!'
#0 1.158 /rails/config/environment.rb:5:in `<main>'
#0 1.158 /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'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/zeitwerk-2.6.7/lib/zeitwerk/kernel.rb:38:in `require'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/application.rb:348:in `require_environment!'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/application.rb:511:in `block in run_tasks_blocks'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/sprockets-rails-3.4.2/lib/sprockets/rails/task.rb:61:in `block (2 levels) in define'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:243:in `block in invoke_prerequisites'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/commands/rake/rake_command.rb:18:in `perform'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/command.rb:51:in `invoke'
#0 1.158 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/commands.rb:18:in `<main>'
#0 1.158 /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'
#0 1.158 Tasks: TOP => environment
#0 1.158 (See full trace by running task with --trace)
------
Error: failed to fetch an image or build from source: error building: failed to solve: executor failed running [/bin/sh -c SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile]: exit code: 1```

What’s on line 69 in config/environments/production.rb?

Line 69 is port: ENV.fetch(‘SMTP_PORT’),

config.action_mailer.smtp_settings = {
port: ENV.fetch(‘SMTP_PORT’),
address: ENV.fetch(‘SMTP_SERVER’),
user_name: ENV.fetch(‘SMTP_LOGIN’),
password: ENV.fetch(‘SMTP_PASSWORD’),
domain: ENV.fetch(‘SMTP_DOMAIN’),
authentication: :plain,
enable_starttls_auto: true
}

Secrets are not available at build time; but then again I doubt you will be wanting to send any emails during the course of the build. Consider adding if ENV[‘SMTP_PORT’] around that line.

How about the other lines? Can you show me how you would build the block?

config.action_mailer.smtp_settings = {
port: ENV.fetch(‘SMTP_PORT’),
address: ENV.fetch(‘SMTP_SERVER’),
user_name: ENV.fetch(‘SMTP_LOGIN’),
password: ENV.fetch(‘SMTP_PASSWORD’),
domain: ENV.fetch(‘SMTP_DOMAIN’),
authentication: :plain,
enable_starttls_auto: true
}

Thanks!

if ENV[‘SMTP_PORT’]
  config.action_mailer.smtp_settings = {
    port: ENV.fetch(‘SMTP_PORT’),
    address: ENV.fetch(‘SMTP_SERVER’),
    user_name: ENV.fetch(‘SMTP_LOGIN’),
    password: ENV.fetch(‘SMTP_PASSWORD’),
    domain: ENV.fetch(‘SMTP_DOMAIN’),
    authentication: :plain,
    enable_starttls_auto: true
  }
end

It seems now the error is different:

[build 9/9] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile:
#0 1.144 rails aborted!
#0 1.144 NameError: undefined local variable or method `‘SMTP_PORT’’

It looks like my apostrophes got converted to backtics. Can you try replacing these characters with single (or double) quotes?

1 Like

Done! It seems… :slight_smile:

if ENV[‘SMTP_PORT’] → if ENV[“SMTP_PORT”]

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