【发布时间】:2020-07-02 11:39:41
【问题描述】:
我正在尝试使用 heroku.yml 将我的 rails 应用程序部署到 Heroku。这是我的yml 设置
setup:
addons:
- plan: cleardb-mysql
as: DATABASE
build:
docker:
web: Dockerfile
config:
RAILS_ENV: development
DATABASE_URL: mysql2://abcdef:1234567@somewhere-someplace-123.cleardb.net/heroku_abcdefg123456
run:
web: bin/rails server -p $PORT -b 0.0.0.0
我使用 MySQL 作为数据库。这是我的Dockerfile,Heroku 正在使用它来构建图像。
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"]
这按预期工作,但问题是我必须在 heroku.yml 文件中传递数据库字符串。有没有办法可以引用 Heroku 中声明的配置变量?
我试过了,但它不起作用,因为 docs 还说 Heroku 中声明的 config-vars 在构建时不可用。
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
此问题可能的解决方法是什么?
【问题讨论】:
标签: docker heroku ruby-on-rails-5