|
1 |
| -version: 2 |
| 1 | +version: 2.1 |
| 2 | +orbs: |
| 3 | + docker: circleci/[email protected] |
2 | 4 | jobs:
|
3 |
| - build: |
| 5 | + checkout_code: |
4 | 6 | docker:
|
5 |
| - - image: circleci/ruby:2.5.1 |
| 7 | + - image: circleci/ruby:2.5 |
6 | 8 | working_directory: ~/app
|
7 | 9 | steps:
|
| 10 | + - restore_cache: |
| 11 | + name: Restore code from cache |
| 12 | + keys: |
| 13 | + - v1-source-{{ .Branch }}-{{ .Revision }} |
| 14 | + - checkout |
| 15 | + - save_cache: |
| 16 | + name: Save code cache |
| 17 | + key: v1-source-{{ .Branch }}-{{ .Revision }} |
| 18 | + paths: |
| 19 | + - '.git' |
| 20 | + - persist_to_workspace: |
| 21 | + root: ~/ |
| 22 | + paths: |
| 23 | + - app/* |
| 24 | + - app/**/* |
| 25 | + bundle: |
| 26 | + docker: |
| 27 | + - image: circleci/ruby:2.5-stretch-node-browsers |
| 28 | + environment: |
| 29 | + BUNDLE_PATH: vendor/bundle |
| 30 | + working_directory: ~/app |
| 31 | + steps: |
| 32 | + - attach_workspace: |
| 33 | + at: ~/ |
| 34 | + - run: |
| 35 | + name: Update Debian Packages for Building |
| 36 | + command: | |
| 37 | + sudo apt-get install -y software-properties-common build-essential make apt-utils |
| 38 | + - restore_cache: |
| 39 | + name: Restore bundle from cache |
| 40 | + keys: |
| 41 | + - v2-bundle-{{ checksum "Gemfile.lock" }} |
| 42 | + - run: |
| 43 | + name: Update bundler |
| 44 | + command: gem install bundler -v 2.1.4 |
| 45 | + - run: |
| 46 | + name: Install dependencies |
| 47 | + command: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3 --binstubs |
| 48 | + - save_cache: |
| 49 | + name: Save bundle cache |
| 50 | + key: v2-bundle-{{ checksum "Gemfile.lock" }} |
| 51 | + paths: |
| 52 | + - ~/app/vendor/bundle |
| 53 | + - persist_to_workspace: |
| 54 | + root: ~/ |
| 55 | + paths: |
| 56 | + - app/* |
| 57 | + - app/**/* |
| 58 | +# lint: |
| 59 | +# docker: |
| 60 | +# - image: circleci/ruby:2.5-stretch-node-browsers |
| 61 | +# environment: |
| 62 | +# BUNDLE_PATH: vendor/bundle |
| 63 | +# working_directory: ~/app |
| 64 | +# steps: |
| 65 | +# - attach_workspace: |
| 66 | +# at: ~/ |
| 67 | +# - run: |
| 68 | +# name: Update bundler |
| 69 | +# command: gem install bundler -v 2.1.4 && bundle install --binstubs |
| 70 | +# - run: |
| 71 | +# name: Run Rubocop |
| 72 | +# command: bundle exec rubocop |
| 73 | + test: |
| 74 | + docker: |
| 75 | + - image: circleci/ruby:2.5-stretch-node-browsers |
| 76 | + environment: |
| 77 | + HONEYCOMB_DATASET: api-test |
| 78 | + HONEYCOMB_DEBUG: 'true' |
| 79 | + HONEYCOMB_WRITEKEY: buzzzzzzzzzzzzzzzz |
| 80 | + HONEYCOMB_SERVICE: api-test |
| 81 | + RAILS_ENV: test |
| 82 | + - image: circleci/mysql:5.7.22 |
| 83 | + environment: |
| 84 | + MYSQL_ROOT_PASSWORD: monkeys |
| 85 | + MYSQL_USER: monkeys |
| 86 | + MYSQL_PASSWORD: monkeys |
| 87 | + MYSQL_DATABASE: api_test |
| 88 | + working_directory: ~/app |
| 89 | + steps: |
| 90 | + - attach_workspace: |
| 91 | + at: ~/ |
8 | 92 | - run:
|
9 | 93 | name: Update Debian Packages
|
10 | 94 | command: |
|
11 |
| - echo "deb http://http.debian.net/debian stretch-backports main" | sudo tee -a /etc/apt/sources.list |
12 | 95 | sudo apt-get update -qq
|
13 | 96 | sudo apt-get upgrade -qq
|
14 | 97 | sudo apt-get install -y -f software-properties-common build-essential default-libmysqlclient-dev nodejs make apt-utils
|
15 |
| - - checkout |
16 |
| - - restore_cache: |
17 |
| - key: gemfile-{{ checksum "Gemfile.lock" }} |
18 | 98 | - run:
|
19 |
| - name: Install Ruby Dependencies |
20 |
| - command: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3 |
21 |
| - - save_cache: |
22 |
| - key: gemfile-{{ checksum "Gemfile.lock" }} |
23 |
| - paths: |
24 |
| - - vendor/bundle |
25 |
| - - tmp/zips |
| 99 | + name: Wait for DB |
| 100 | + command: dockerize -wait tcp://localhost:3306 -timeout 1m |
| 101 | + - run: |
| 102 | + name: Update bundler srsly again |
| 103 | + command: gem install --force bundler |
| 104 | + - run: |
| 105 | + name: Bundle update srsly again |
| 106 | + command: bundle check --without production staging --path=vendor/bundle || bundle install --without production staging --path=vendor/bundle --jobs=4 --retry=3 --binstubs |
| 107 | + - run: |
| 108 | + command: bundle check --without production staging --path=vendor/bundle || bundle install --without production staging --path=vendor/bundle --jobs=4 --retry=3 --binstubs |
26 | 109 | - run:
|
27 |
| - name: Create DB |
| 110 | + name: Create and load MySQL data |
28 | 111 | command: bundle exec rake db:create db:schema:load --trace
|
29 | 112 | - run:
|
30 | 113 | name: Run Tests
|
31 | 114 | command: |
|
32 | 115 | bundle exec rspec --profile 10 \
|
| 116 | + --format RspecJunitFormatter \ |
33 | 117 | --out /tmp/test-results/rspec.xml \
|
34 | 118 | --format progress \
|
35 | 119 | $(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
|
36 |
| - - store_artifacts: |
37 |
| - path: coverage |
38 |
| - destination: coverage |
39 | 120 | - store_test_results:
|
40 |
| - path: /tmp/circle-junit |
| 121 | + path: /tmp/test-results |
| 122 | + - store_artifacts: |
| 123 | + path: /tmp/test-results |
| 124 | + destination: test-results |
| 125 | + - store_artifacts: |
| 126 | + path: ./tmp/screenshots |
| 127 | + - store_artifacts: |
| 128 | + path: ./tmp/capybara |
| 129 | + build_and_push_beavernetes: |
| 130 | + parameters: |
| 131 | + repo: |
| 132 | + type: string |
| 133 | + default: '' |
| 134 | + environment: |
| 135 | + type: string |
| 136 | + default: 'production' |
| 137 | + executor: |
| 138 | + name: 'docker/docker' |
| 139 | + environment: |
| 140 | + DOCKER_LOGIN: admin |
| 141 | + DOCKER_PASSWORD: admin |
| 142 | + working_directory: ~/app |
| 143 | + steps: |
| 144 | + - attach_workspace: |
| 145 | + at: ~/ |
| 146 | + - run: |
| 147 | + name: Generate deployed version |
| 148 | + command: | |
| 149 | + export GIT_SHORT_HASH=$(git rev-parse --short HEAD) |
| 150 | + export DATETIME=$(date "+%Y%m%d%H%M%S") |
| 151 | + echo export TAG="$DATETIME-$GIT_SHORT_HASH" >> $BASH_ENV |
| 152 | + echo export DEPLOYED_VERSION="$DATETIME-$GIT_SHORT_HASH" >> $BASH_ENV |
| 153 | + - setup_remote_docker |
| 154 | + - docker/check: |
| 155 | + registry: registry.library.oregonstate.edu |
| 156 | + - docker/build: |
| 157 | + registry: registry.library.oregonstate.edu |
| 158 | + image: osulp-api |
| 159 | + tag: $TAG |
| 160 | + extra_build_args: --build-arg RAILS_ENV=<< parameters.environment >> --build-arg DEPLOYED_VERSION=$DEPLOYED_VERSION |
| 161 | + - docker/push: |
| 162 | + registry: registry.library.oregonstate.edu |
| 163 | + image: osulp-api |
| 164 | + tag: $TAG |
| 165 | +workflows: |
| 166 | + ci: |
| 167 | + jobs: |
| 168 | + - checkout_code |
| 169 | + - bundle: |
| 170 | + requires: |
| 171 | + - checkout_code |
| 172 | +# - lint: |
| 173 | +# requires: |
| 174 | +# - bundle |
| 175 | + - test: |
| 176 | + requires: |
| 177 | + - bundle |
| 178 | +# - lint |
| 179 | + - build_and_push_beavernetes: |
| 180 | + name: build_and_push_beavernetes |
| 181 | + requires: |
| 182 | + - test |
| 183 | + filters: |
| 184 | + branches: |
| 185 | + only: master |
| 186 | + repo: osulp-api |
0 commit comments