visit
6. If you are using , that's all you are going to need for now, just paste the address into the CLI when asked for it.
7.Navigate to the Ruby on Rails project root directory in the command line and enter
git remote add origin YOUR_REPOSITORY_URL
1. Click "Sign up with Github" on the .
cd path/to/your/project/root
mkdir .circleci
touch .circleci/config.yml
For the CircleCI to work you are going to need a specific setup in the config/database.yml file. Notice that the gem is used.
config/database.yml
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV['DB_POOL'] %>
username: <%= ENV['DB_USERNAME'] %>
password: <%= ENV['DB_PASSWORD'] %>
host: <%= ENV['DB_HOST'] %>
port: 5432
development:
<<: *default
database: hix_postgresql_development
test:
<<: *default
database: hix_postgresql_test
production:
<<: *default
database: hix_postgresql_production
version: 2.1
executors:
default:
working_directory: ~/hix_postgresql
docker:
- image: circleci/ruby:2.6.5
environment:
BUNDLE_JOBS: 3
BUNDLE_PATH: vendor/bundle
BUNDLE_RETRY: 3
BUNDLER_VERSION: 2.0.1
RAILS_ENV: test
DB_HOST: 127.0.0.1
PG_HOST: 127.0.0.1
PGUSER: hixonrails
- image: circleci/postgres:12.0
environment:
POSTGRES_DB: hix_postgresql_test
POSTGRES_USER: hixonrails
commands:
configure_bundler:
description: Configure bundler
steps:
- run:
name: Configure bundler
command: |
echo 'export BUNDLER_VERSION=$(cat Gemfile.lock | tail -1 | tr -d " ")' >> $BASH_ENV
source $BASH_ENV
gem install bundler
jobs:
build:
executor: default
steps:
- checkout
- restore_cache:
keys:
- hix_postgresql-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
- hix_postgresql-
- configure_bundler
- run:
name: Install bundle
command: bundle install
- run:
name: Wait for DB
command: dockerize -wait tcp://127.0.0.1:5432 -timeout 1m
- run:
name: Setup DB
command: bundle exec rails db:create db:schema:load --trace
- save_cache:
key: hix_postgresql-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
- persist_to_workspace:
root: ~/
paths:
- ./hix_postgresql
workflows:
version: 2
integration:
jobs:
- build
For the workflow to pass on the CircleCI, you need to have db/schema.rb file checked into the repository, which means that you need to create at least one database migration.
For the CircleCI to work you are going to need a specific setup in the config/database.yml file. Notice that the gem is used.
config/database.yml
default: &default
adapter: mysql2
encoding: utf8
pool: <%= ENV['DB_POOL'] %>
username: <%= ENV['DB_USERNAME'] %>
password: <%= ENV['DB_PASSWORD'] %>
host: <%= ENV['DB_HOST'] %>
port: 3306
development:
<<: *default
database: hix_mysql_development
test:
<<: *default
database: hix_mysql_test
production:
<<: *default
database: hix_mysql_production
version: 2.1
executors:
default:
working_directory: ~/hix_mysql
docker:
- image: circleci/ruby:2.6.5
environment:
BUNDLE_JOBS: 3
BUNDLE_PATH: vendor/bundle
BUNDLE_RETRY: 3
BUNDLER_VERSION: 2.0.1
RAILS_ENV: test
DB_HOST: 127.0.0.1
DB_USERNAME: root
DB_PASSWORD: ''
- image: circleci/mysql:8.0.18
command: [--default-authentication-plugin=mysql_native_password]
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'true'
MYSQL_ROOT_HOST: '%'
commands:
configure_bundler:
description: Configure bundler
steps:
- run:
name: Configure bundler
command: |
echo 'export BUNDLER_VERSION=$(cat Gemfile.lock | tail -1 | tr -d " ")' >> $BASH_ENV
source $BASH_ENV
gem install bundler
jobs:
build:
executor: default
steps:
- checkout
- restore_cache:
keys:
- hix_mysql-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
- hix_mysql-
- configure_bundler
- run:
name: Install bundle
command: bundle install
- run:
name: Wait for DB
command: dockerize -wait tcp://127.0.0.1:3306 -timeout 1m
- run:
name: Setup DB
command: bundle exec rails db:create db:schema:load --trace
- save_cache:
key: hix_mysql-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
- persist_to_workspace:
root: ~/
paths:
- ./hix_mysql
workflows:
version: 2
integration:
jobs:
- build
For the workflow to pass on the CircleCI, you need to have db/schema.rb file checked into the repository, which means that you need to create at least one database migration.
jobs:
build:
executor: default
steps:
- checkout
- restore_cache:
keys:
- hix-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
- hix-
- configure_bundler
- run:
name: Install bundle
command: bundle install
- run:
name: Wait for DB
command: dockerize -wait tcp://127.0.0.1:3306 -timeout 1m
- run:
name: Setup DB
command: bundle exec rails db:create db:schema:load --trace
- run:
name: RSpec
command: |
bundle exec rspec --profile 10 \
--format progress
- store_artifacts:
path: coverage
- save_cache:
key: hix-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
- persist_to_workspace:
root: ~/
paths:
- ./hix
workflows:
version: 2
integration:
jobs:
- build
comes additionally configured to use , which gives a nice test coverage percentage badge for your Ruby on Rails project's README.md.
rubocop:
executor: default
steps:
- attach_workspace:
at: ~/
- configure_bundler
- run:
name: Rubocop
command: bundle exec rubocop
workflows:
version: 2
integration:
jobs:
- build
- rubocop:
requires:
- build
brakeman:
executor: default
steps:
- attach_workspace:
at: ~/
- configure_bundler
- run:
name: Brakeman
command: bundle exec brakeman
workflows:
version: 2
integration:
jobs:
- build
- brakeman:
requires:
- build
Remember, that using any security audit tool does not guarantee that your Ruby on Rails application is 100% safe. Please read the and on top of other things, audit your website regularly with tools like Mozilla Observatory.
fasterer:
executor: default
steps:
- attach_workspace:
at: ~/
- configure_bundler
- run:
name: Fasterer
command: bundle exec fasterer
workflows:
version: 2
integration:
jobs:
- build
- fasterer:
requires:
- build
One option that is recommended to be turned off for Ruby on Rails project using Fasterer is the
each.with_index
versus the while
loop, all the rest of a default configuration is good to go. rails_best_practices:
executor: default
steps:
- attach_workspace:
at: ~/
- configure_bundler
- run:
name: Rails Best Practices
command: bundle exec rails_best_practices
workflows:
version: 2
integration:
jobs:
- build
- rails_best_practices:
requires:
- build
A lot of this knowledge was forged into static code analysis tools that let developers find their mistakes easily.
CircleCI is trivial to use yet very powerful Continuous Integration provider that lets you build, test and audit your Ruby on Rails application code with minimal setup, for free.If you care about the Ruby on Rails application code quality and easy maintenance, that's the perfect combination for you.(Originally published )