LoginSignup
5

More than 5 years have passed since last update.

CircleCI 2.0設定例 (rails 5.2 + webpacker + rspec + mysql)

Last updated at Posted at 2018-07-08

はじめに

Support for CircleCI 1.0 will end on August 31, 2018. Gain more flexibility with workflows, customize your environment with Docker, and access more powerful resources with CircleCI 2.0.

今までのCircleCI 1.0の設定で動くので8月までなので、CricelCI 2.0の設定に書き直す必要が出る。

設定例

.circleci/config.yml
version: 2

jobs:
  build:
    working_directory: ~/app
    docker:
      - image: circleci/ruby:2.5.1-node-browsers
        environment:
          RAILS_ENV: test
      - image: mysql:5.7
        environment:
          MYSQL_ALLOW_EMPTY_PASSWORD: yes
    steps:
      - checkout
      - restore_cache:
          keys:
            - app-{{ checksum "Gemfile.lock" }}-{{ checksum "yarn.lock" }}
            - app-
      - run: bundle install --path vendor/bundle
      - run: yarn install
      - save_cache:
          key: app-{{ checksum "Gemfile.lock" }}-{{ checksum "yarn.lock" }}
          paths:
            - vendor/bundle
            - node_modules
      - run: cp config/database.yml.circleci config/database.yml
      - run: bundle exec rake db:create db:schema:load
      - run: bundle exec bin/webpack
      - run: bundle exec rspec
config/database.yml.circleci
test:
  adapter: mysql2
  encoding: utf8
  pool: 5
  database: app_test
  username: root
  password:
  host: 127.0.0.1

引っかかったところ

  • database.ymlのhostはlocalhostだと接続できない
  • mysqlにパスワードなしで接続する場合はMYSQL_ALLOW_EMPTY_PASSWORDyesに設定しておく

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
5