LoginSignup
2
1

More than 5 years have passed since last update.

Heroku Container RegistryでRailsアプリを動かす

Posted at

手順

良い点

  • Buildpacksを考慮しないで済むようになる
  • Buildpacksで提供されてない環境を作れる
  • 他のDockerの環境に移行するのがしやすくなる

制限

  • Review Appsが使えない
  • Automatic deploysやManual deployが使えない

構築例

Dockerfile
FROM ruby:2.4.1

ENV RAILS_ENV production
ENV SECRET_KEY_BASE secret_key_base
ENV NODE_ENV production
ENV NPM_CONFIG_PRODUCTION false

RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb http://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get update -qq && apt-get install -y nodejs yarn
RUN mkdir /app
WORKDIR /app
ADD Gemfile /app/Gemfile
ADD Gemfile.lock /app/Gemfile.lock
RUN bundle install --without development test
ADD . /app
RUN cp /app/config/database.yml.nulldb /app/config/database.yml
RUN yarn install
RUN yarn run build
RUN bundle exec rake assets:precompile
RUN rm /app/config/database.yml

CMD bundle exec puma -C config/puma.rb
.dockerignore

.bundle

log
tmp

node_modules
yarn-error.log

.byebug_history

app/assets/javascripts/bundle.js
.env
.env.app
.env.db
.git

コマンド

SECRET_KEY_BASEはrake secretの実行結果を設定する。

heroku create
heroku container:push web -a kptboard
heroku config:set SECRET_KEY_BASE=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx RAILS_LOG_TO_STDOUT=true RAILS_SERVE_STATIC_FILES=true
heroku addons:create heroku-postgresql:hobby-dev
heroku run rake db:migrate
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1