Last active
June 17, 2018 21:45
-
-
Save ibanez270dx/fdff7e68fcd15887d999b3b820b43506 to your computer and use it in GitHub Desktop.
CircleCI 2.0 w/ Ruby + RSpec, MySQL, Redis, ElasticSearch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: 2 | |
jobs: | |
build: | |
parallelism: 2 # however many CPUs you need/pay for | |
############################################# | |
# Container Setup | |
############################################# | |
docker: | |
- image: circleci/ruby:2.5.0 | |
environment: | |
- RAILS_ENV=test | |
- image: circleci/mysql:5.7 | |
environment: | |
- MYSQL_ROOT_HOST=% | |
- MYSQL_ROOT_PASSWORD=circleci | |
- image: redis:4.0.9 | |
- image: elasticsearch:2.3 | |
############################################# | |
# Build Steps | |
############################################# | |
steps: | |
- checkout | |
- run: | |
name: Configure secrets.yml | |
command: mv config/secrets.ci.yml config/secrets.yml | |
- run: | |
name: Configure database.yml | |
command: mv config/database.ci.yml config/database.yml | |
########################################### | |
# Bundler w/ caching | |
########################################### | |
- restore_cache: | |
keys: | |
- rails-bundle-{{ checksum "Gemfile.lock" }} | |
- rails-bundle- | |
- run: | |
name: Bundle Gems | |
command: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle | |
- save_cache: | |
key: rails-bundle-{{ checksum "Gemfile.lock" }} | |
paths: | |
- vendor/bundle | |
########################################### | |
# Database | |
########################################### | |
- run: | |
name: Wait for MySQL | |
command: dockerize -wait tcp://127.0.0.1:3306 -timeout 1m | |
- run: | |
name: Load DB schema | |
command: bin/rails db:schema:load --trace | |
########################################### | |
# Run rspec in parallel | |
########################################### | |
- run: | |
name: Run rspec in parallel | |
command: | | |
bundle exec rspec --profile 10 \ | |
--format RspecJunitFormatter \ | |
--out test_results/rspec.xml \ | |
--format progress \ | |
$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings) | |
# Save test results for timing analysis | |
- store_test_results: | |
path: test_results | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test: | |
adapter: mysql2 | |
database: circle_test | |
username: root | |
password: circleci | |
host: 127.0.0.1 | |
encoding: utf8mb4 | |
collation: utf8mb4_bin | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test: | |
secret_key_base: test | |
redis_url: 127.0.0.1:6379 | |
elasticsearch_url: 127.0.0.1:9200 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment