forked from StackStorm/st2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
circle.yml
276 lines (269 loc) · 10.3 KB
/
circle.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# Setup in CircleCI account the following ENV variables:
# PACKAGECLOUD_ORGANIZATION (default: stackstorm)
# PACKAGECLOUD_TOKEN
version: 2
jobs:
# Run st2 Unit Tests
unit:
# 'machine' executor runs Unit tests ~x1.5 faster, comparing to 'docker' executor
# but the fastest is still ~x1.5-2 slower, comparing to Travis
machine: true
parallelism: 4
working_directory: ~/st2
steps:
- checkout
- restore_cache:
keys:
- st2-unit-001-{{ checksum "fixed-requirements.txt" }}-{{ checksum "test-requirements.txt" }}
- run:
name: Prepare the environment
command: |
set -x
sudo .circle/install-mongo.sh
sudo .circle/configure-rabbitmq.sh
sudo apt-get -qq -y install python-virtualenv python-dev
- run:
name: Create stanley user
command: sudo .circle/add-itest-user.sh
- run:
name: Install pip requirements
command: make requirements
- run:
name: Run st2 Unit Tests
command: |
# Workaround for table width/height used in some tests
stty rows 50 cols 132
make ci-unit
- save_cache:
key: st2-unit-001-{{ checksum "fixed-requirements.txt" }}-{{ checksum "test-requirements.txt" }}
paths:
- ~/.cache/pip/
- virtualenv/
# Run st2 Integration tests
integration:
docker:
- image: circleci/python:2.7
- image: mongo:3.4
- image: rabbitmq:3
working_directory: ~/st2
steps:
- checkout
- restore_cache:
keys:
- st2-integration-001-{{ checksum "fixed-requirements.txt" }}-{{ checksum "test-requirements.txt" }}
- run:
# Download the mongo shell, needed to connect to Docker container + delete the DB
name: Install Mongo Shell
command: |
set -x
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.4 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
sudo apt-get -qq -y update
sudo apt-get -qq -y install mongodb-org-shell
- run:
name: Create stanley user
command: sudo .circle/add-itest-user.sh
- run:
name: Install pip requirements
command: make requirements
- run:
name: Run st2 Integration Tests
command: make ci-integration
- save_cache:
key: st2-integration-001-{{ checksum "fixed-requirements.txt" }}-{{ checksum "test-requirements.txt" }}
paths:
- ~/.cache/pip/
- virtualenv/
# Run st2 Lint Checks
lint:
docker:
- image: circleci/python:2.7
- image: mongo:3.4
- image: rabbitmq:3
working_directory: ~/st2
steps:
- checkout
- restore_cache:
keys:
# we can use the same caching env as for integration
- st2-integration-001-{{ checksum "fixed-requirements.txt" }}-{{ checksum "test-requirements.txt" }}
- run:
name: Install pip requirements
command: make requirements
- run:
name: Run st2 Lint Checks
command: make ci-checks
- run:
name: Run st2 Packs Tests
command: make ci-packs-tests
- save_cache:
# we can use the same caching env as for integration
key: st2-integration-001-{{ checksum "fixed-requirements.txt" }}-{{ checksum "test-requirements.txt" }}
paths:
- ~/.cache/pip/
- virtualenv/
# Build & Test st2 packages
packages:
parallelism: 4
# 4CPUs & 8GB RAM CircleCI machine
# sadly, it doesn't work with 'setup_remote_docker'
resource_class: large
docker:
# The primary container is an instance of the first list image listed. Your build commands run in this container.
- image: circleci/python:2.7
working_directory: ~/st2
environment:
- DISTROS: "trusty xenial el6 el7"
- ST2_PACKAGES_REPO: https://github.com/StackStorm/st2-packages
- ST2_PACKAGES: "st2"
- ST2_CHECKOUT: 0
- ST2_GITDIR: /tmp/st2
- BASH_ENV: ~/.buildenv
steps:
- checkout
- setup_remote_docker:
reusable: true # default - false
exclusive: true # default - true
- run:
name: Docker version
command: |
set -x
docker --version
docker-compose --version
- run:
name: Download st2-packages repository
command: |
set -x
git clone ${ST2_PACKAGES_REPO} ~/st2-packages
cd ~/st2-packages
git checkout ${CIRCLE_BRANCH} || true
- run:
name: Initialize packages Build Environment
command: |
set -x
export ST2_GITREV=${CIRCLE_BRANCH}
.circle/buildenv_st2.sh
working_directory: ~/st2-packages
# Verify that Docker environment is properly cleaned up and there is nothing left from the previous build
# See issue: https://discuss.circleci.com/t/no-space-left-on-device-while-creating-mongo/11532/13
- run:
name: Pre Docker cleanup
command: |
set -x
# Clean-up running containers
.circle/docker-compose2.sh clean
# Remove st2-packages-vol container
docker rm -v --force st2-packages-vol || true
# Clean-up any created volumes
docker volume prune --force
working_directory: ~/st2-packages
- run:
# Workaround for CircleCI docker-compose limitation where volumes don't work
# See detailed explanation: https://circleci.com/docs/2.0/building-docker-images/#mounting-folders
name: Copy st2-packages files to build containers
command: |
# creating dummy container which will hold a volume with data files
docker create -v /root/st2-packages -v ${ST2_GITDIR} -v /root/build -v /var/log/st2 -v /root/.cache/pip -v /tmp/wheelhouse --name st2-packages-vol alpine:3.4 /bin/true
# copy st2-packages data files into this volume
docker cp ~/st2-packages st2-packages-vol:/root
# copy st2 source files into this volume
docker cp . st2-packages-vol:${ST2_GITDIR}
- run:
name: Pull dependent Docker Images
command: .circle/docker-compose2.sh pull ${DISTRO}
working_directory: ~/st2-packages
- run:
name: Build the ${DISTRO} Packages
command: |
.circle/docker-compose2.sh build ${DISTRO}
# Once build container finishes we can copy packages directly from it
mkdir -p ~/st2/packages/${DISTRO}/log/
docker cp st2-packages-vol:/root/build/. ~/st2/packages/${DISTRO}
working_directory: ~/st2-packages
# # TODO: It works! (~0.5-1min speed-up) Enable CircleCI2.0 cache for pip and wheelhouse later
# - run:
# name: Build the ${DISTRO} Packages 2nd time (compare with pip/wheelhouse cached)
# command: |
# .circle/docker-compose2.sh build ${DISTRO}
# # Once build container finishes we can copy packages directly from it
# docker cp st2-packages-vol:/root/build /tmp/st2-packages
# working_directory: ~/st2-packages
- run:
name: Test the Packages
command: .circle/docker-compose2.sh test ${DISTRO}
working_directory: ~/st2-packages
- run:
when: always
name: Grab the st2 logs
command: docker cp st2-packages-vol:/var/log/st2 ~/st2/packages/${DISTRO}/log/st2
- store_artifacts:
path: ~/st2/packages
destination: packages
- persist_to_workspace:
root: packages
paths:
- .
# Verify that Docker environment is properly cleaned up, and there is nothing left for the next build
# See issue: https://discuss.circleci.com/t/no-space-left-on-device-while-creating-mongo/11532/13
- run:
name: Post Docker cleanup
# don't cleanup resources on error since failed container might be used for SSH debug
when: on_success
command: |
set -x
# Clean-up running containers
.circle/docker-compose2.sh clean
# Remove st2-packages-vol container
docker rm -v --force st2-packages-vol || true
# Clean-up any created volumes
docker volume prune --force
working_directory: ~/st2-packages
# Deploy produced deb/rpm packages to PackageCloud staging
deploy:
docker:
# The primary container is an instance of the first list image listed. Your build commands run in this container.
- image: circleci/ruby:2.4
working_directory: /tmp/deploy
environment:
- DISTROS: "trusty xenial el6 el7"
steps:
- attach_workspace:
at: .
- run:
name: List workspace files
command: find . | sed 's|[^/]*/| |g'
- run:
name: Install dependencies
command: |
set -x
sudo apt-get -y install parallel jq
gem install package_cloud
sudo wget -O /usr/local/bin/packagecloud.sh https://raw.githubusercontent.com/StackStorm/st2-packages/master/.circle/packagecloud.sh && sudo chmod +x /usr/local/bin/packagecloud.sh
- run:
name: Deploy deb/rpm packages to PackageCloud
command: "parallel -v -j0 --line-buffer packagecloud.sh deploy {} {} ::: ${DISTROS}"
# TODO: Return to workflows when "Auto-cancel redundant builds” feature is implemented for Workflows: https://discuss.circleci.com/t/auto-cancel-redundant-builds-not-working-for-workflow/13852
# Putting everything together
workflows:
version: 2
package-test-and-deploy:
jobs:
- packages
- deploy:
requires:
- packages
filters:
branches:
only:
- master
- /v[0-9]+\.[0-9]+/
- feature/circleci
experimental:
notify:
branches:
only:
- master
- /v[0-9]+\.[0-9]+/
notify:
webhooks:
- url: https://ci-webhooks.stackstorm.net/webhooks/build/events