Created
May 19, 2018 15:12
-
-
Save rasmar/8b1493d672315c1c5aac185c15c5647f to your computer and use it in GitHub Desktop.
Backend E2E CircleCI 2.0 config
This file contains 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 | |
defaults: &defaults | |
working_directory: ~/project | |
docker: | |
- image: circleci/ruby:2.5.1-stretch-browsers | |
environment: | |
BUNDLE_JOBS: 4 | |
BUNDLE_RETRY: 3 | |
BUNDLE_PATH: vendor/bundle | |
RAILS_ENV: test | |
ES_JAVA_OPTS: -Xms2g -Xmx2g | |
_JAVA_OPTIONS: -Xms1024m -Xmx2048m | |
- image: circleci/postgres:9.6.8-alpine-ram | |
environment: | |
POSTGRES_USER: postgres_user | |
POSTGRES_DB: project_test | |
POSTGRES_PASSWORD: "" | |
jobs: | |
build_rails_dependencies: | |
<<: *defaults | |
steps: | |
- checkout | |
- attach_workspace: | |
at: ~/project | |
- run: | |
name: Which bundler? | |
command: bundle -v | |
- restore_cache: | |
keys: | |
- bundle-{{ checksum "Gemfile.lock" }} | |
- bundle- | |
- run: | |
name: Bundle install | |
command: bundle check || bundle install | |
- save_cache: | |
key: bundle-{{ checksum "Gemfile.lock" }} | |
paths: | |
- vendor/bundle | |
- persist_to_workspace: | |
root: ~/project | |
paths: | |
- vendor/bundle | |
run_audits: | |
<<: *defaults | |
steps: | |
- checkout | |
- attach_workspace: | |
at: ~/project | |
- run: bundle exec bundle-audit check --update | |
- run: bundle exec brakeman -f plain | |
run_unit_tests: | |
<<: *defaults | |
parallelism: 2 | |
steps: | |
- checkout | |
- attach_workspace: | |
at: ~/project | |
- run: | |
name: Wait for DB | |
command: dockerize -wait tcp://localhost:5432 -timeout 1m | |
- run: | |
name: Create DB | |
command: bin/rails db:create db:schema:load --trace | |
- run: wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.1.tar.gz | |
- run: tar -xvf elasticsearch-5.5.1.tar.gz | |
- run: | |
command: elasticsearch-5.5.1/bin/elasticsearch | |
background: true | |
- run: | |
name: Run unit tests # NOTICE THE EXCLUDED features DIRECTORY BELOW | |
command: | | |
TEST_DIRS="controllers,jobs,lib,mailers,models,policies,queries,resources,tasks, | |
uploaders,validations,validators,workers" | |
TEST_COMMAND="$(circleci tests glob "spec/{$TEST_DIRS}/**/*_spec.rb" | | |
circleci tests split --split-by=timings)" | |
bundle exec rspec --exclude-pattern "spec/features/**/*_spec.rb" \ | |
--format RspecJunitFormatter \ | |
--out test_results/rspec.xml \ | |
--format progress \ | |
$TEST_COMMAND | |
- run: bundle exec codeclimate-test-reporter | |
- store_test_results: | |
path: test_results | |
deploy_to_staging: | |
<<: *defaults | |
steps: | |
- checkout | |
- attach_workspace: | |
at: ~/project | |
- run: cd deployment; bundle install; bundle exec cap staging deploy | |
deploy_to_production: | |
<<: *defaults | |
steps: | |
- checkout | |
- attach_workspace: | |
at: ~/project | |
- run: cd deployment; bundle install; bundle exec cap production deploy | |
workflows: | |
version: 2 | |
build_test_deploy: | |
jobs: | |
- build_rails_dependencies | |
- run_audits: | |
requires: | |
- build_rails_dependencies | |
- run_unit_tests: | |
requires: | |
- build_rails_dependencies | |
- deploy_to_staging: | |
requires: | |
- run_audits | |
- run_unit_tests | |
filters: | |
branches: | |
only: master | |
- deploy_to_production: | |
requires: | |
- run_audits | |
- run_unit_tests | |
filters: | |
branches: | |
only: production |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment