I'm trying to deploy my rails app to the Heroku using
heroku.yml. This is my
setup: addons: - plan: cleardb-mysql as: DATABASE build: docker: web: Dockerfile config: RAILS_ENV: development DATABASE_URL: mysql2://abcdef:firstname.lastname@example.org/heroku_abcdefg123456 run: web: bin/rails server -p $PORT -b 0.0.0.0
and I'm using MySQL as a database. And here's my
Dockerfile that the Heroku is using to build the image.
FROM ruby:2.6.5-alpine ARG DATABASE_URL ARG RAILS_ENV # Adding the required dependencies # Installing Required Gems # Other Configs... # Copying Gem Files COPY Gemfile Gemfile.lock ./ # Installing Gems RUN bundle install --jobs=4 --retry=9 # Copying package and package.lock COPY package.json yarn.lock ./ # Installing node_modules RUN yarn # Copy everything to the from current dir to container_root COPY . ./ #Compiling assets RUN bundle exec rake assets:precompile # this precompilation step need DATABASE_URL CMD ["rails", "server", "-b", "0.0.0.0"]
This is working as expected but the problem is I've to pass the database string in the
heroku.yml file. Is there a way I can reference the config vars that are declared in the Heroku?
I tried this but it's not working as the docs also saying that the config-vars declared in Heroku are not available at the build time.
setup: addons: - plan: cleardb-mysql as: DATABASE build: docker: web: Dockerfile config: RAILS_ENV: $RAILS_ENV DATABASE_URL: $DATABASE_URL run: web: bin/rails server -p $PORT -b 0.0.0.0
What could be the possible workaround for this issue?