Robin PRO CircleCI config
version: 2.1 | |
orbs: | |
aws-cli: circleci/aws-cli@0.1.13 | |
jobs: | |
test: | |
parallelism: 1 | |
working_directory: ~/src | |
docker: | |
- image: circleci/ruby:2.6-node-browsers | |
environment: | |
BUNDLE_JOBS: 1 | |
BUNDLE_RETRY: 1 | |
BUNDLE_PATH: vendor/bundle | |
PGHOST: 127.0.0.1 | |
PGUSER: jan | |
RAILS_ENV: test | |
- image: circleci/postgres:10-alpine-ram | |
environment: | |
POSTGRES_DB: robin_pro_test | |
POSTGRES_USER: jan | |
steps: | |
- checkout | |
# JS bundle | |
- restore_cache: | |
key: yarn-{{ checksum "yarn.lock" }} | |
- run: | |
name: Install yarn dependencies | |
command: yarn install --frozen-lockfile | |
- save_cache: | |
key: yarn-{{ checksum "yarn.lock" }} | |
paths: | |
- node_modules | |
- ~/.cache/yarn | |
- restore_cache: | |
key: bundle-{{ checksum "Gemfile.lock" }} | |
- run: | |
name: Install bundle | |
command: bin/bundle install --path vendor/bundle | |
- save_cache: | |
key: bundle-{{ checksum "Gemfile.lock" }} | |
paths: | |
- vendor/bundle | |
- run: | |
name: Verify bundle security | |
# TODO: remove once fixed | |
command: bundle exec bundle-audit check --update --ignore CVE-2015-9284 | |
- run: | |
name: Compile TypeScript code | |
command: yarn tsc | |
# Environment setup | |
- run: | |
name: Set up app environment | |
command: cp config/application.yml.example config/application.yml | |
# Make `psql` available so we can load DB structure from SQL | |
- run: | |
name: Set up PG client | |
command: sudo apt install -y postgresql-client || true | |
- run: | |
name: Wait for DB | |
command: dockerize -wait tcp://localhost:5432 -timeout 1m | |
# Database setup | |
- run: | |
name: Set up database | |
command: | | |
bundle exec rake db:create db:structure:load --trace | |
# Run rspec in parallel | |
- run: | |
name: Run tests | |
command: | | |
bundle exec rspec \ | |
--no-fail-fast \ | |
--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 | |
deploy-master: | |
machine: | |
image: circleci/classic:latest | |
working_directory: ~/src | |
steps: | |
- checkout | |
- run: | |
name: Deploy Master to Heroku | |
command: | | |
git push https://heroku:${HEROKU_API_KEY}@git.heroku.com/${HEROKU_APP_NAME}.git master | |
- run: | |
name: Migrate database | |
command: | | |
heroku run rake db:migrate --app ${HEROKU_APP_NAME} | |
publish-client: | |
docker: | |
- image: circleci/ruby:2.6-node-browsers | |
environment: | |
BUNDLE_JOBS: 1 | |
BUNDLE_RETRY: 1 | |
BUNDLE_PATH: vendor/bundle | |
PGHOST: 127.0.0.1 | |
PGUSER: jan | |
RAILS_ENV: test | |
working_directory: ~/src | |
steps: | |
- checkout | |
# JS bundle | |
- restore_cache: | |
key: yarn-{{ checksum "yarn.lock" }} | |
- run: | |
name: Install yarn dependencies | |
command: yarn install --frozen-lockfile | |
# Ruby | |
- restore_cache: | |
key: bundle-{{ checksum "Gemfile.lock" }} | |
- run: | |
name: Install bundle | |
command: bin/bundle install --path vendor/bundle | |
# AWS CLI | |
- aws-cli/install | |
- aws-cli/configure | |
# Environment setup needed for asset precompilation | |
- run: | |
name: Set up app environment | |
command: cp config/application.yml.example config/application.yml | |
- run: | |
name: Publish client | |
command: bin/publish_client | |
workflows: | |
version: 2 | |
build-deploy: | |
jobs: | |
- test | |
- deploy-master: | |
requires: | |
- test | |
filters: | |
branches: | |
only: master | |
- publish-client: | |
requires: | |
- deploy-master | |
filters: | |
branches: | |
only: master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment