Introducing CircleCI to Rails

Introduction

If you introduce CircleCI to Rails and push it to GitHub, tests etc. will run automatically.

procedure

  1. Select the repository where you want to run CI with your CircleCI account
  2. Create config.yml under .circleci
  3. push

Implementation

Rails app creation (created with MySQL)

$ rails new circleci_practice -d mysql

Create a suitable CRUD with scaffold.

circleci_practic $ rails g scaffold users name:string email:string

Add rspec to Gemfile and bundle install

Try writing one suitable RSpec.

Create a .circleci directory and create a config.yml

You cannot connect to MySQL on Docker as it is, so edit the host part. For the time being, I think the following feeling is fine.

test:
  <<: *default
  database: circleci_parctice_test
 # ↓ Add this
  host:  <%= ENV['DATABASE_HOST'] } %>
version: 2

jobs:
  test:
    docker:
      - image: circleci/ruby:2.7.1-node
        environment:
          RAILS_ENV: test
          DATABASE_HOST: 127.0.0.1 
      - image: circleci/mysql:5.7
        environment:
          MYSQL_ALLOW_EMPTY_PASSWORD: true
          MYSQL_ROOT_PASSWORD: ''
          MYSQL_DATABASE: circleci_parctice_test
    working_directory: ~/circleci_parctice
    steps:
      - checkout
      - run:
          name: "bundle install"
          command: bundle install --path vendor/bundle
 #Wait until you can connect to MySQL
      - run:
          name: "waiting DB start"
          command: dockerize -wait tcp://127.0.0.1:3306 -timeout 1m
      - run:
          name: "initialize DB"
          command: |
            bundle exec rake db:create
            bundle exec rake db:migrate
      - run:
          name: RSpec
          command: bundle exec rspec


workflows:
  version: 2
  workflows:
    jobs:
      - test

If you push with this, CI will run automatically.

in conclusion

I think it would be nice to add rubocop or slim-lint. It's faster if you use cache with yarn install or bundle install.

Recommended Posts

Introducing CircleCI to Rails
Introducing Bootstrap to Rails 5
Introducing Bootstrap to Rails !!
Introducing full calendar to Rails application
Introducing React to Rails with react-rails
[Rails] Introducing jquery
[Rails] Introducing devise
I tried to introduce CircleCI 2.0 to Rails app
[Rails 6] Introducing Google Maps to your portfolio
The process of introducing Vuetify to Rails
How to write Rails
Introducing New Relic to Rails apps on Heroku
[Rails] Introducing Active Hash
Introduce Vue.js to Rails
How to uninstall Rails
Introducing Rails6 + Bootswatch / Honoka
[Rails] Introducing pay.jp (from view customization to registration)
[rails] How to post images
Introducing AWS CLI to CentOS 7
[Rails] How to use enum
Introducing past nvidia-driver to Ubuntu
[Rails] How to install devise
[Rails] How to use enum
How to read rails routes
Introducing Bootstrap and Font-Awesome (Rails)
How to use rails join
[Rails] Add column to devise
How to terminate rails server
How to write Rails validation
How to write Rails seed
[Rails] How to use validation
[Rails] How to disable turbolinks
Pass parameters to Rails link_to
[Rails] How to use authenticate_user!
[Rails] How to use "kaminari"
[Rails] How to implement scraping
[Rails] How to make seed
Incorporate circleCI into CircleCI Rails app
Introducing JITSI MEET to CentOS 8
How to write Rails routing
[Rails] How to install simple_calendar
[Rails] How to install reCAPTCHA
Introduced gRPC client to rails
Introduction to RSpec-Everyday Rails Summary-
[Rails] How to use Scope
[Rails] How to install Font Awesome
Rails new fails to install mysql
[Rails] How to use devise (Note)
[Rails] Two ways to write form_with
[Rails] Learn yield to understand content_for
[Rails] How to write in Japanese
[Rails] How to prevent screen transition
[Rails] Various ways to delete data
How to use Ruby on Rails
[Rails] Easy way to check columns
How to deploy Bootstrap on Rails
Until you introduce fonts to Rails
[Rails] How to speed up docker-compose
[Rails] How to add new pages
Deploy to EC2 with CircleCi + Capistrano
Rails on Tiles (how to write)