【问题标题】:Deploy Rails app into Heroku with Docker using heroku.yml使用 heroku.yml 使用 Docker 将 Rails 应用程序部署到 Heroku
【发布时间】:2021-01-01 07:46:30
【问题描述】:

按照https://devcenter.heroku.com/articles/build-docker-images-heroku-yml 上的教程后,不清楚我们应该在Dockerfile 中放入哪些内容。

对于 Rails 应用程序,我们的 Dockerfile 中需要什么?

【问题讨论】:

    标签: ruby-on-rails docker heroku dockerfile


    【解决方案1】:

    有一个 Rails 5 示例可以作为解决方案的基础:https://github.com/jahangiranwari/rails5-docker-heroku/

    对于 Rails 6 项目,我使用了以下 Dockerfile

    FROM ruby:2.6.6
    
    # Install node & yarn
    RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
    RUN apt-get install -y nodejs
    RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
    RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
    RUN apt-get update && apt-get install -y yarn
    
    # Install base deps or additional (e.g. tesseract)
    ARG INSTALL_DEPENDENCIES
    RUN apt-get update -qq \
      && apt-get install -y --no-install-recommends ${INSTALL_DEPENDENCIES} \
        build-essential libpq-dev git \
      && apt-get clean autoclean \
      && apt-get autoremove -y \
      && rm -rf \
        /var/lib/apt \
        /var/lib/dpkg \
        /var/lib/cache \
        /var/lib/log
    
    # Install deps with bundler
    RUN mkdir /app
    WORKDIR /app
    COPY Gemfile* /app/
    ARG BUNDLE_INSTALL_ARGS
    RUN gem install bundler:2.1.4
    RUN bundle config set without 'development test'
    RUN bundle install ${BUNDLE_INSTALL_ARGS} \
      && rm -rf /usr/local/bundle/cache/* \
      && find /usr/local/bundle/gems/ -name "*.c" -delete \
      && find /usr/local/bundle/gems/ -name "*.o" -delete
    COPY . /app/
    
    # Compile assets
    ARG RAILS_ENV=development
    RUN if [ "$RAILS_ENV" = "production" ]; then SECRET_KEY_BASE=$(rake secret) bundle exec rake assets:precompile; fi
    
    

    还有这个 heroku.yml 文件:

    build:
      docker:
        web: Dockerfile
      config:
        BUNDLE_INSTALL_ARGS: --jobs 10 --retry=3
        RAILS_ENV: production
        # Put extra deps here
        INSTALL_DEPENDENCIES: curl openssh-server python
    run:
      web: bundle exec puma -C config/puma.rb
    

    20-1-22 更新: 它适用于 Rails 7

    【讨论】:

    • 谢谢,这将适用于 rails 7 吗?
    • 尚未将此应用程序更新到 Rails 7,但它应该可以工作。完成后我会更新答案。
    • @Petran 我确认它适用于 Rails 7
    猜你喜欢
    • 2019-10-31
    • 1970-01-01
    • 2018-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-07
    • 2015-12-25
    • 2021-05-21
    相关资源
    最近更新 更多