Permalink
Fetching contributors…
Cannot retrieve contributors at this time
108 lines (91 sloc) 2.75 KB
# Ruby CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
#
version: 2
jobs:
test:
docker:
- image: circleci/ruby:2.3-jessie-node-browsers
- image: circleci/mongo:3.2-ram
working_directory: ~/repo
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "Gemfile.lock" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run:
name: install dependencies
command: |
bundle check || bundle install --jobs=4 --retry=3 --path vendor/bundle
- save_cache:
paths:
- ./vendor/bundle
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
# Database setup
- run:
name: Wait for DB
command: dockerize -wait tcp://localhost:27017 -timeout 1m
# run tests
- 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
build_image:
machine: true
steps:
- checkout
- run: pwd
- run: ls -lah
- run: |
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
# build the application image
- run: docker build -t jnummelin/todo-example:$(echo $CIRCLE_SHA1 | cut -c1-7) .
# deploy the image
- run: docker push jnummelin/todo-example:$(echo $CIRCLE_SHA1 | cut -c1-7)
deploy:
docker:
- image: kontena/cli:latest
steps:
- checkout
- run: echo 'export TAG=$CIRCLE_BUILD_NUM' >> $BASH_ENV
- run:
environment:
# Variables for the stack
VHOST: todo-app.kontena.works
LOADBALANCER: ingress-lb/lb
command: |
export TAG=$(echo $CIRCLE_SHA1 | cut -c1-7)
echo "Using tag: $TAG"
kontena stack install || kontena stack upgrade todo
workflows:
version: 2
build-and-deploy:
jobs:
- test
- build_image:
filters:
branches:
only: master
- deploy:
requires:
- test
- build_image
filters:
branches:
only: master