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
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`
# 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"]
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