Skip to content

Instantly share code, notes, and snippets.

@dthtien
Forked from osulyanov/config.yml
Created November 7, 2019 14:51
Show Gist options
  • Save dthtien/72d967d7537f9a9d62ab9f64cb327b77 to your computer and use it in GitHub Desktop.
Save dthtien/72d967d7537f9a9d62ab9f64cb327b77 to your computer and use it in GitHub Desktop.
Circle CI workflows config to test and deploy Ruby on Rails application with PostgreSQL database. Test with Rspec, precompile assets then deploy with Capistrano.
# Ruby CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
#
defaults: &defaults
working_directory: ~/repo
docker:
- image: circleci/ruby:2.4.1-node-browsers
environment:
RAILS_ENV: test
PGHOST: 127.0.0.1
DATABASE_URL: "postgres://ubuntu@localhost:5432/oferta_test"
- image: circleci/postgres:9.4
environment:
POSTGRES_USER: ubuntu
POSTGRES_DB: oferta_test
version: 2
jobs:
bundle_dependencies:
<<: *defaults
steps:
- checkout
- attach_workspace:
at: ~/repo
- restore_cache:
keys:
- v1-dependencies-{{ checksum "Gemfile.lock" }}
- run: bundle install --jobs=4 --retry=3 --path vendor/bundle
- save_cache:
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
paths:
- ~/repo/vendor/bundle
- persist_to_workspace:
root: .
paths: vendor/bundle
rake_test:
<<: *defaults
steps:
- checkout
- attach_workspace:
at: ~/repo
- run: bundle --path vendor/bundle
# - run:
# name: Rubocop
# command: bin/rubocop --rails
# Database setup
- run: bundle exec rake db:create
- run: bundle exec rake db:schema:load
- run:
name: run tests
command: |
mkdir /tmp/test-results
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
bundle exec rspec --format progress \
--format RspecJunitFormatter \
--out /tmp/test-results/rspec.xml \
--format progress \
-- \
$TEST_FILES
# collect reports
- store_test_results:
path: /tmp/test-results
- store_artifacts:
path: /tmp/test-results
destination: test-results
precompile_assets:
<<: *defaults
steps:
- checkout
- attach_workspace:
at: ~/repo
- run: bundle --path vendor/bundle
- run:
name: Precompile assets
command: bundle exec rake assets:precompile
- persist_to_workspace:
root: .
paths: public/assets
deploy:
<<: *defaults
steps:
- checkout
- attach_workspace:
at: ~/repo
- run: bundle --path vendor/bundle
- run:
command: bundle exec cap staging deploy
workflows:
version: 2
build-and-deploy:
jobs:
- bundle_dependencies
- rake_test:
requires:
- bundle_dependencies
- precompile_assets:
requires:
- bundle_dependencies
- deploy:
requires:
- rake_test
- precompile_assets
filters:
branches:
only: develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment