This repository has been archived by the owner on Oct 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
.travis.yml
236 lines (188 loc) · 11.6 KB
/
.travis.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
sudo: required
language: minimal
services:
- docker
notifications:
slack:
secure: pP5E+YX1+qR3chyZmyBwt/00wZ2HL4ENjFBSxqLbf/0rOjr+SBwf/IwQbFCEqdWkAGxccD71uegZ0q7Kgs4nCNqItCyau/2S61QWBOvGUJtdhsnSZQ7sQjLOKBUUgeQlZGC7xDandxRV6XgVegUu6/l28xttxTkNcE1Q3i/0WoAXUcmOyH32Flw454WxIlSMgOX0xb1Npj+15F+sKoo3od26/Nd7UyHnGQD3fO0Kk5DHLMs2Kr8x1UFI7+nIrQmI4FVGcVEnOMa+mKI0LlhvAi7Ma6C8l+BQJTAwPG3HqamCrq7l7cyWmDpQY3ySjPSfp2f1LzPBLx3Bx54wb0YQiLt0nQlW/oymlXDH+8q53KEIyXm72yOTvWZR5bldmjf5Ap7OEAWLbSZRMEleZCcKrZ6q8zJn+IRuSqT0VJQUS89IjTlG9MKznipD0qBmI9N5QbPl8wk502po+5U3oYuptGV+JOSC2aC6RcJqWtgKaElHFJMfAqm80VDzuW9+9f7llIsLEpwbKCj3xpysHZQOYVT0zwo2gP/15kGr445xbGOaYhJ7rEnTXhixgyRD+SeXmJkzTLX6HY1HlPaNLNy3ggcbg+4yEr/t4lN61RVGK+hfsO0DwSta++rLC8xj/prfI91BPS4ttCB8/5R5f5plN15sRgkyZ9zboUAxv0ERWyE=
on_success: change
on_failure: always
cache:
directories:
- "unbrake-frontend/node_modules"
addons:
ssh_known_hosts:
- unbrake-hom.ml
- unbrake.ml
env:
global:
- DOCKER_COMPOSE_VERSION=1.23.2
- DOCKER_DEVELOPMENT_TAG="latest-development"
# Staging things
- DOCKER_STAGING_TMP_TAG="latest-staging-tmp"
- DOCKER_STAGING_TAG=latest-staging
- STAGING_HOST=unbrake-hom.ml
# Production things
- DOCKER_PRODUCTION_TAG=latest
- PRODUCTION_HOST=unbrake.ml
# code climate test reporter id (it's not so secret)
- secure: "CFCx6LcmtNOBVyFjxgW8NcrmAs3Fr7ueq4tbjg8f7LCHRodsQMxAAL8+8BbeP41YDZ34mqEwemc8QG5dXXSE8lFVAzJfUUQnYncpu1YiywwYmxP6cNWcBtu1h6sBUOfObBz2mQyJnt1yL2TKob4vaK0jtzy099Mew8aIxRzqcHL04TqxG902ITdGiraH89nIN64MKw7CQMUy65S0kRo1RJkQQDJ9s5CKVnBy3n0Vv8qJj+JqKrzJeRSOrpxElg0yOEe7hFNQkavyBbyGt++f0O1AupQxP9drCxrWRsYTUt/+WNWiZnkNXWSBqHgwrYn13ObthrmgHw5vNTA8sYnzav68kypRbuQm4b4oUaSuQWa5c6cfl0wKa7Uk5t8np78wVByK9+yy84+KL91kDYrxFVEoWe55CDDvL1G6HWP28x1cmL8GA35H+rADDdXQaxxEeDpbExTwOf7N3brNfUh416psDF9VyVqDq46wtJapuAE3Onj9rWmP+EMYxaBdVeV+2wi24/sowwqPQF+sBHWnW0pM+xmOztrptZRdMnwCuVzWt+ROV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ZwVzNgr3LwOdIVaFoI68wI1QWIsR6RmIbB+M+WDnQpmYFEC4HEO6wzFk/kaJqwUxpw68K2szdO+TpqgrCx07uP06VdZrQnmfsekmEjp6s8rDQkKu84zFd1b5ZRgvSjDeNbTFP5vJOma5DQE0X03U0295oKJacEa2H6jiLJitWrrsEG+Wvb4OHeAUUGxLKmCQnQ4R4GpSq6HH5zhmLkCJ9CUz3SPouhUFztfRbfcnln/2nxbZm84vdm0TBio0RVi5oLdCboR6obCcEpmsTYo8pcUwKSVg/0rgVINNnsIGhPFwGuoDl9q833PD4gkJxJUY45wu9k/YZJye0TijfxQYlOaTxa91AvYlxi9F3M9VYuodoaRpHN1gzUiWEnorKwwf24BmrQFy3wZeAHvlmsCDS5IHlbJYJHWP+lVd3afl6jVckZWcSHiyA="
before_install:
# Update Docker Compose
- sudo rm /usr/local/bin/docker-compose
- curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin
# Update Docker
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- sudo apt-get update
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
# General secrets from API
- openssl aes-256-cbc -K $encrypted_ec73e88a7c5d_key -iv $encrypted_ec73e88a7c5d_iv -in unbrake-api/secrets/API_DJANGO_SECRET_KEY.enc -out unbrake-api/secrets/API_DJANGO_SECRET_KEY -d
- openssl aes-256-cbc -K $encrypted_e2b707099939_key -iv $encrypted_e2b707099939_iv -in unbrake-api/secrets/DB_PASSWORD.enc -out unbrake-api/secrets/DB_PASSWORD -d
- openssl aes-256-cbc -K $encrypted_12b7f6274154_key -iv $encrypted_12b7f6274154_iv -in unbrake-api/secrets/HTTPS_KEY.enc -out unbrake-api/secrets/HTTPS_KEY -d
# Deploy Key
- openssl aes-256-cbc -K $encrypted_46d61bdc678c_key -iv $encrypted_46d61bdc678c_iv -in deploy/deploy_key.enc -out deploy/deploy_key -d
# MQTT environment variables
- openssl aes-256-cbc -K $encrypted_a8aa7a1b7e93_key -iv $encrypted_a8aa7a1b7e93_iv -in deploy/.env_mqtt.enc -out deploy/.env_mqtt -d
- openssl aes-256-cbc -K $encrypted_ddb8f7363e54_key -iv $encrypted_ddb8f7363e54_iv -in unbrake-api/secrets/MQTT_READING_KEY.enc -out unbrake-api/secrets/MQTT_READING_KEY -d
- openssl aes-256-cbc -K $encrypted_6d56a259a9f3_key -iv $encrypted_6d56a259a9f3_iv -in unbrake-api/secrets/MQTT_WRITING_KEY.enc -out unbrake-api/secrets/MQTT_WRITING_KEY -d
before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
# Aliases -------------------------------------------------------
build_staging: &build_development
stage: "build staging/development environments"
before_script: skip
script:
- docker build "$BUILD_FOLDER/" -t "$DOCKER_IMAGE:${DOCKER_DEVELOPMENT_TAG}" -f "$BUILD_FOLDER/Dockerfile"
- echo "$DOCKER_PASSWORD" | docker login -u "${DOCKER_USERNAME}" --password-stdin
- docker push "$DOCKER_IMAGE:${DOCKER_DEVELOPMENT_TAG}"
- docker logout
build_staging: &build_staging
stage: "build staging/development environments"
before_script: skip
script:
- docker build "$BUILD_FOLDER/" -t "$DOCKER_IMAGE:${DOCKER_STAGING_TMP_TAG}" -f "$BUILD_FOLDER/production/Dockerfile"
- echo "$DOCKER_PASSWORD" | docker login -u "${DOCKER_USERNAME}" --password-stdin
- docker push "$DOCKER_IMAGE:${DOCKER_STAGING_TMP_TAG}"
- docker logout
deploy_staging: &deploy_staging
stage: "deploy staging images"
if: branch = devel AND type != pull_request
before_script: skip
script:
- docker pull "$DOCKER_IMAGE:${DOCKER_STAGING_TMP_TAG}"
- docker tag "$DOCKER_IMAGE:${DOCKER_STAGING_TMP_TAG}" "$DOCKER_IMAGE:${DOCKER_STAGING_TAG}"
- echo "$DOCKER_PASSWORD" | docker login -u "${DOCKER_USERNAME}" --password-stdin
- docker push "$DOCKER_IMAGE:${DOCKER_STAGING_TAG}"
- docker logout
# --------------------------------------------------------------
jobs:
include:
# Build all these images images on parallel for speed
- <<: *build_development
name: "Build frontend (development)"
env:
- BUILD_FOLDER=unbrake-frontend
- DOCKER_IMAGE=unbrake/frontend
- <<: *build_development
name: "Build API (development)"
env:
- BUILD_FOLDER=unbrake-api
- DOCKER_IMAGE=unbrake/api
- <<: *build_staging
name: "Build frontend (staging)"
env:
- BUILD_FOLDER=unbrake-frontend
- DOCKER_IMAGE=unbrake/frontend
- <<: *build_staging
name: "Build API (staging)"
env:
- BUILD_FOLDER=unbrake-api
- DOCKER_IMAGE=unbrake/api
- stage: "development checkings and tests"
name: "General git checks"
before_install: skip
before_script: skip
script:
- git diff --check || (echo 'Trailing whitespaces or conflict marks found!' && exit 1)
- if [ -d unbrake ]; then echo 'The unbrake folder must not exist!' && (exit 1); fi
- name: "Static analysis"
script:
- sudo docker pull "unbrake/api:$DOCKER_DEVELOPMENT_TAG"
- sudo docker pull "unbrake/frontend:$DOCKER_DEVELOPMENT_TAG"
- sudo docker pull "unbrake/local"
- sed -i -e "/\s\+build/d" -e "/\s\+context/d" -e "/\s\+dockerfile/d" docker-compose.yml
- docker-compose up -d
- docker-compose exec frontend npm run check_format
- docker-compose exec frontend npm run check_lint
- docker-compose exec api python manage.py check_format
- docker-compose exec api python manage.py check_lint
- docker-compose down -v
- (cd unbrake-local && ./scripts/check_format)
- (cd unbrake-local && ./scripts/check_lint)
- name: "Run tests and collect coverage"
script:
- sudo docker pull "unbrake/api:$DOCKER_DEVELOPMENT_TAG"
- sudo docker pull "unbrake/frontend:$DOCKER_DEVELOPMENT_TAG"
- sudo docker pull "unbrake/local"
- sed -i -e "/\s\+build/d" -e "/\s\+context/d" -e "/\s\+dockerfile/d" docker-compose.yml
- docker-compose up -d
- docker-compose exec frontend npm run check_tests:coverage
- docker-compose exec api python manage.py check_tests_coverage
- docker-compose down -v
- (cd unbrake-local && ./scripts/check_tests_coverage)
# Collect coverage
- mkdir coverage
- (cd unbrake-frontend && ./../cc-test-reporter format-coverage -t lcov -o ../coverage/frontend.json -p /app/frontend src/tests/coverage/lcov.info)
- (cd unbrake-api && ./../cc-test-reporter format-coverage -t coverage.py -o ../coverage/api.json -p /app/api)
- (cd unbrake-local && ./../cc-test-reporter format-coverage -t gocov -o ../coverage/local.json -p github.com/fga-eps-mds/2019.1-unbrake/unbrake-local coverage.out)
# Merge coverage results and upload
- ./cc-test-reporter sum-coverage -o coverage/codeclimate.json -p 3 coverage/*.json
- if [[ "$TRAVIS_TEST_RESULT" == 0 ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then ./cc-test-reporter upload-coverage -i coverage/codeclimate.json; fi
- <<: *deploy_staging
name: "Deploy frontend"
env:
- DOCKER_IMAGE=unbrake/frontend
- <<: *deploy_staging
name: "Deploy API"
env:
- DOCKER_IMAGE=unbrake/api
- stage: "deploy to staging environment"
name: "Deploy to staging environment"
if: branch = devel AND type != pull_request
script:
# Deploy key to travis environment
- eval "$(ssh-agent -s)"
- chmod 600 deploy/deploy_key
- ssh-add deploy/deploy_key
# Deploy to staging environment
- (cd deploy && bash scripts/deploy "$STAGING_HOST" staging)
- stage: "deploy to production environment"
name: "Deploy to production environment"
if: branch = master AND type != pull_request
script:
# Pull latest staging images
- docker pull "unbrake/frontend:${DOCKER_STAGING_TAG}"
- docker pull "unbrake/api:${DOCKER_STAGING_TAG}"
# Re-tag lastest staging images to production images
- docker tag "unbrake/frontend:${DOCKER_STAGING_TAG}" "unbrake/frontend:${DOCKER_PRODUCTION_TAG}"
- docker tag "unbrake/api:${DOCKER_STAGING_TAG}" "unbrake/api:${DOCKER_PRODUCTION_TAG}"
# Push images as production images
- echo "$DOCKER_PASSWORD" | docker login -u "${DOCKER_USERNAME}" --password-stdin
- docker push "unbrake/frontend:${DOCKER_PRODUCTION_TAG}"
- docker push "unbrake/api:${DOCKER_PRODUCTION_TAG}"
- docker logout
# Deploy key to travis environment
- eval "$(ssh-agent -s)"
- chmod 600 deploy/deploy_key
- ssh-add deploy/deploy_key
# Deploy to staging environment
- (cd deploy && bash scripts/deploy "$PRODUCTION_HOST" prod)