.circleci/config.yml
# Fan In/Fan Out Workflow
# environment variables
postgres_environment: &postgres_environment
environment:
POSTGRES_DB: nokul_test
POSTGRES_USER: nokul
POSTGRES_PASSWORD: nokul
rails_environment: &rails_environment
environment:
TZ: '/usr/share/zoneinfo/Asia/Istanbul'
RAILS_ENV: test
RACK_ENV: test
RDS_USERNAME: nokul
RDS_PASSWORD: nokul
RDS_HOSTNAME: localhost
RDS_PORT: 5432
BUNDLER_VERSION: 2.0.1
# cache keys
restore_bundle: &restore_bundle
keys:
- nokul-bundle-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
- nokul-bundle-{{ checksum "Gemfile.lock" }}
restore_yarn: &restore_yarn
keys:
- nokul-yarn-{{ .Branch }}-{{ checksum "yarn.lock" }}
- nokul-yarn-{{ checksum "yarn.lock" }}
repository: &repository
key: nokul-repo-{{ .Environment.CIRCLE_SHA1 }}
# build image
ruby_2_6: &ruby_2_6
docker:
- image: circleci/ruby:2.6.2-node-browsers
<<: *rails_environment
- image: circleci/postgres:11.1-alpine
<<: *postgres_environment
# build jobs
version: 2
jobs:
prepare_project:
<<: *ruby_2_6
steps:
- checkout
- save_cache:
<<: *repository
paths:
- ~/project
bundle_dependencies:
<<: *ruby_2_6
steps:
- restore_cache:
<<: *repository
- restore_cache:
<<: *restore_bundle
- run: gem uninstall bundler
- run: gem install bundler
- run: bundle install --path vendor/bundle --without development
- run: bin/plugdo bundle install --path "$(readlink -m vendor/bundle)" --without development
- save_cache:
key: nokul-bundle-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
- save_cache:
key: nokul-bundle-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
bundle_assets:
<<: *ruby_2_6
steps:
- restore_cache:
<<: *repository
- restore_cache:
<<: *restore_bundle
- restore_cache:
<<: *restore_yarn
- run: gem uninstall bundler
- run: gem install bundler
- run: bin/yarn install
- save_cache:
key: nokul-yarn-{{ .Branch }}-{{ checksum "yarn.lock" }}
paths:
- node_modules/
- save_cache:
key: nokul-yarn-{{ checksum "yarn.lock" }}
paths:
- node_modules/
quality:
<<: *ruby_2_6
steps:
- restore_cache:
<<: *repository
- restore_cache:
<<: *restore_bundle
- restore_cache:
<<: *restore_yarn
- run: gem uninstall bundler
- run: gem install bundler
- run: bin/yarn install
- run: bundle --path vendor/bundle --without development
- run: bundle exec rake quality:all
- run: bin/yarn run lint
security:
<<: *ruby_2_6
steps:
- restore_cache:
<<: *repository
- restore_cache:
<<: *restore_bundle
- restore_cache:
<<: *restore_yarn
- run: gem uninstall bundler
- run: gem install bundler
- run: bin/yarn install
- run: bundle --path vendor/bundle --without development
- run: bundle exec rake security:all
database:
<<: *ruby_2_6
steps:
- restore_cache:
<<: *repository
- restore_cache:
<<: *restore_bundle
- restore_cache:
<<: *restore_yarn
- run: gem uninstall bundler
- run: gem install bundler
- run: bin/yarn install
- run: bundle --path vendor/bundle --without development
- run: bundle exec rake database:all
test_suite:
<<: *ruby_2_6
steps:
- restore_cache:
<<: *repository
- restore_cache:
<<: *restore_bundle
- restore_cache:
<<: *restore_yarn
- run: gem uninstall bundler
- run: gem install bundler
- run: bin/yarn install
- run: sudo apt install -y postgresql-client || true
- run: bundle --path vendor/bundle --without development
- run: bin/plugdo bundle install --path "$(readlink -m vendor/bundle)" --without development
- run: bundle exec rake db:create db:structure:load
- run: bundle exec rails test:system test
deploy_develop:
machine:
enabled: true
steps:
- checkout
- run:
name: Deploy Develop to Dokku
command: |
git remote add beta dokku@app.omu.sh:nokul-develop &&
git push beta develop:master
deploy_master:
machine:
enabled: true
steps:
- checkout
- run:
name: Deploy Master to Dokku
command: |
git remote add production dokku@app.omu.sh:nokul &&
git push production master
# build flow
workflows:
version: 2
build-test-and-deploy:
jobs:
- prepare_project
- bundle_dependencies:
requires:
- prepare_project
- bundle_assets:
requires:
- bundle_dependencies
- quality:
requires:
- bundle_assets
- security:
requires:
- bundle_assets
- database:
requires:
- bundle_assets
- test_suite:
requires:
- bundle_assets
# - deploy_develop:
# requires:
# - quality
# - security
# - database
# - test_suite
# filters:
# branches:
# only: develop
# - deploy_master:
# requires:
# - quality
# - security
# - database
# - test_suite
# filters:
# branches:
# only: master