Rails のアプリケーション環境をサクッと立ち上げるために Application Template を用意してみました。特徴としては, slim, rspec 初期化, rubocop の設定等々です。

https://gist.github.com/yuya-matsushima/827903535cd97894df74c385fcdc30b4

環境構築

docker-compose 環境の用意

Web サーバーなし, MySQL と Redis の image をベースに。

version: '3'
services:
  app:
    image: fillininc/rails:2.6.3-18.04
    volumes:
      - .:/opt/app
      - bundle:/usr/local/bundle
    ports:
      - 3000:3000
    stdin_open: true
    depends_on:
      - db
      - redis
  db:
    image: mysql:8.0
    command: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci
    volumes:
      - database:/var/lib/mysql
    ports:
      - 3306:3306
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: app_development
      TZ: Asia/Tokyo
  redis:
    image: redis:5.0
    ports:
      - 6379:6379

volumes:
  database:
  bundle:

Gemfile を用意

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gem 'rails', '~> 5.2.3'

Gem のインストール

$ docker-compose run --rm app

起動した app 内の bash で下記コマンドを実行。

-m に指定する URL は https://gist.github.com/yuya-matsushima/827903535cd97894df74c385fcdc30b4 の RAW。バージョンに注意。

$ bundle i --without production
$ bundle exec rails new . -d mysql -m https://gist.githubusercontent.com/yuya-matsushima/827903535cd97894df74c385fcdc30b4/raw/57832fecc737c9d03efbee85da06c29e363d66c4/template.rb

実行完了後に exit

起動

  • db/database.yml を環境に合わせ編集
  • $ docker-compose up -d で起動

作ってみて

gem_group が既存の group に対して追加ではなく Gemfile に追記していくのがちょっと不満。しかし結局はコメントの削除や並び替えを行うので問題はない。