1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【CircleCI】コミット時にRSpec通す設定個人用メモ(database.yml書き換え無し)

Last updated at Posted at 2021-02-12

タイトルの通り。githubとの連携は済ませた状態です。初心者が独学とググりまくりで作ったものなのでお手柔らかにお願いします。。

環境

Mac OS X
Ruby: 2.7.1
Rails: 6.0.3.4
mysql: 8.0.2

実際のコード

config.yml
version: 2.1
orbs:
  ruby: circleci/ruby@0.1.2 

jobs:
  build:
    docker:
      - image: circleci/ruby:2.7.1-buster-browsers
        environment:
          BUNDLER_VERSION: 2.1.4
          RAILS_ENV: test

      - image: circleci/mysql:8.0.22
        command: [--default-authentication-plugin=mysql_native_password]
        environment:
          MYSQL_DATABASE: 'rails_practice_test'

    working_directory: ~/myappname

    steps:
      - checkout

      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "Gemfile.lock" }}
            - v1-dependencies-
      
      - run:
          name: setup bundler
          command: |
            sudo gem update --system
            sudo gem uninstall bundler
            sudo rm /usr/local/bin/bundle
            sudo gem install bundler

      - run:
          name: Which bundler?
          command: bundle -v

      - run:
          name: bundle install
          command: |
            bundle install --jobs=4 --retry=3 --path vendor/bundle

      - save_cache:
          paths:
            - ./vendor/bundle
          key: v1-dependencies-{{ checksum "Gemfile.lock" }}

      - run: mysql_config --socket
      - run: bundle exec rails db:create
      - run: bundle exec rails db:schema:load
      
      - run:
          name: install yarn
          command: |
            curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
            echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
            sudo apt update && sudo apt install yarn

      - run: bin/yarn

      - run: bin/webpack

      - run:
          name: run rspec
          command: bundle exec rspec

database.ymlのテスト環境も以下のように少し変える

database.yml
test:
  <<: *default
  database: 'rails_practice_test'
  username: <%= ENV.fetch("DB_USERNAME") { 'root' } %>
  port: <%= ENV.fetch("DB_PORT") { hoge } %>
  host: <%= ENV.fetch("DB_HOST") { 'hoge.hoge.hoge.hoge' } %>

自分はこれでローカルでもコミット時にもRSpecを走らせることができました。一部の変数は書き換えてるので適宜読み替えてください。

↓以下疑問に思ったことです

「CircleCiを回すときはconfig/database.ymlとconfig/database.ynl.ciを入れ替える必要がある」という記事が多く見られたのですが、これが一般的なのでしょうか?自分が入れ替えなくても通せたので疑問に思いました。

記事を読んでいただきありがとうございました。

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?