Skip to content

Instantly share code, notes, and snippets.

@kitwalker12
Created March 7, 2018 22:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kitwalker12/c8c34081c84f5addeb4745c651ecf747 to your computer and use it in GitHub Desktop.
Save kitwalker12/c8c34081c84f5addeb4745c651ecf747 to your computer and use it in GitHub Desktop.
Upgrade Circleci to 2.0 Config
version: 2
jobs:
build:
parallelism: 3
working_directory: ~/foo/bar
docker:
- image: circleci/ruby:2.3-node-browsers
- image: circleci/postgres:9.4
- image: circleci/redis:3.2
- image: circleci/rabbitmq:3.6.6
steps:
- checkout
- add_ssh_keys
- restore_cache:
keys:
- foobar-dependency-cache-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
- foobar-dependency-cache-{{ .Branch }}-
- foobar-dependency-cache-
- run:
name: Export env
command: echo -e "export RAILS_ENV=test\nexport RACK_ENV=test" >> $BASH_ENV
- run:
name: Bundle Install
command: |
bundle config without development:production
bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=3 --retry=3
- save_cache:
key: foobar-dependency-cache-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
- run:
name: Wait for DB
command: dockerize -wait tcp://localhost:5432 -timeout 1m
- run:
name: Wait for Redis
command: dockerize -wait tcp://localhost:6379 -timeout 1m
- run:
name: Wait for Rabbit
command: dockerize -wait tcp://localhost:5672 -timeout 1m
- run:
name: Database setup
command: |
mkdir -p config && echo 'test:
adapter: postgresql
encoding: unicode
database: foobar_test
pool: 5
username: postgres
host: localhost
' > config/database.yml
export RAILS_ENV="test"
export RACK_ENV="test"
bundle exec rake db:create db:schema:load --trace
- type: shell
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)
- store_test_results:
path: test_results
deploy:
machine:
enabled: true
working_directory: ~/foo/bar
steps:
- checkout
- add_ssh_keys
- run:
name: Deploy
command: |
sudo apt-get -y -qq update
sudo apt-get install python-pip python-dev build-essential
sudo pip install awsebcli --upgrade
echo $EB_KEY | sed 's/\\n/\n/g' > ~/.ssh/aws-eb-key.pem
if [[ "${CIRCLE_BRANCH}" == master ]]; then
eb use foobar-dev
elif [[ "${CIRCLE_BRANCH}" == release ]]; then
eb use foobar-prod
fi
eb deploy -l $CIRCLE_SHA1 --timeout 15
workflows:
version: 2
build-and-deploy:
jobs:
- build:
filters:
branches:
only:
- release
- master
- /.*fix.*/
- /.*feature.*/
- deploy:
requires:
- build
filters:
branches:
only:
- release
- master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment