-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.yml
191 lines (177 loc) · 4.77 KB
/
config.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
version: 2.1
executors:
docker-publisher:
environment:
IMAGE_NAME: suldlss/dor-services-app
docker:
- image: circleci/buildpack-deps:stretch
jobs:
test:
docker:
- image: circleci/ruby:2.7.0-stretch
environment:
BUNDLE_JOBS: 3
BUNDLE_RETRY: 3
BUNDLE_PATH: vendor/bundle
PGHOST: 127.0.0.1
PGUSER: circleci-demo-ruby
RAILS_ENV: test
NOKOGIRI_USE_SYSTEM_LIBRARIES: true
- image: circleci/postgres:11
environment:
POSTGRES_USER: postgres
POSTGRES_DB: dor_services_test
POSTGRES_PASSWORD: ""
steps:
- checkout
# Upgrade bundler
- run:
name: Install Bundler
command: gem install bundler
# Which version of bundler?
- run:
name: Which bundler?
command: bundle -v
# Restore bundle cache
- restore_cache:
keys:
- dor-services-app-bundle-v2-{{ checksum "Gemfile.lock" }}
- dor-services-app--bundle-v2-
- run:
name: Bundle Install
command: bundle check || bundle install
# Store bundle cache
- save_cache:
key: dor-services-app-bundle-v2-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
# Need `psql` command when you store the app schema as SQL instead of as Ruby
- run:
name: Install postgresql client
command: |
sudo apt update -y
sudo apt install -y postgresql-client || true
- run:
name: Wait for DB
command: dockerize -wait tcp://localhost:5432 -timeout 1m
- run:
name: Test prepare
command: bin/rails db:test:prepare
- run:
name: Check styles using rubocop
command: bundle exec rubocop
# Run rspec in parallel
- run:
name: Run rspec in parallel
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)
- run:
name: Validate API specification
command: |
sudo npm install -g openapi-enforcer-cli
result=$(openapi-enforcer validate openapi.json)
[[ $result =~ "Document is valid" ]] && {
echo "Validation good"
} || {
echo $result
exit 1
}
result=$(jq '' openapi.json)
[[ $? == "0" ]] && {
echo "JSON good"
exit 0
} || {
echo $result
exit 1
}
# Save test results for timing analysis
- store_test_results:
path: test_results
build-image:
executor: docker-publisher
steps:
- checkout
- setup_remote_docker
- run:
name: Build Docker image
command: |
docker build -t $IMAGE_NAME:latest .
- run:
name: Archive Docker image
command: |
docker save -o app_image.tar $IMAGE_NAME
- persist_to_workspace:
root: .
paths:
- ./app_image.tar
publish-latest:
executor: docker-publisher
steps:
- attach_workspace:
at: /tmp/workspace
- setup_remote_docker
- run:
name: Load archived Docker image
command: |
docker load -i /tmp/workspace/app_image.tar
- run:
name: Publish Docker Image to Docker Hub
command: |
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
docker push $IMAGE_NAME:latest
publish-tag:
executor: docker-publisher
steps:
- attach_workspace:
at: /tmp/workspace
- setup_remote_docker
- run:
name: Load archived Docker image
command: |
docker load -i /tmp/workspace/app_image.tar
- run:
name: Publish Docker Image to Docker Hub
command: |
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
docker tag $IMAGE_NAME:latest $IMAGE_NAME:$CIRCLE_TAG
docker push $IMAGE_NAME:$CIRCLE_TAG
workflows:
version: 2
test:
jobs:
- test:
filters:
branches:
ignore: master
build:
jobs:
- build-image:
filters:
branches:
only: master
- publish-latest:
requires:
- build-image
filters:
branches:
only: master
build-tags:
jobs:
- build-image:
filters:
tags:
only: /^[0-9]+\.[0-9]+\.[0-9]+/
branches:
ignore: /.*/
- publish-tag:
requires:
- build-image
filters:
tags:
only: /^[0-9]+\.[0-9]+\.[0-9]+/
branches:
ignore: /.*/