forked from mendersoftware/deployments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.travis.yml
261 lines (209 loc) · 9.51 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
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
language: go
# Forces travis to use VM insted container, required to be able to build containers.
sudo: required
services:
- docker
- mongodb
# Golang version matrix
go:
- 1.7.4
addons:
#Add alias to localhost, required for fakes3
hosts:
- mender-artifact-storage.localhost
env:
matrix:
- JOB_TYPE=compile_and_basic_tests
- JOB_TYPE=compile_and_integration_tests_fast
- JOB_TYPE=compile_and_integration_tests_slow
global:
# Should be encrypted or set as private travis variables (in travis settings):
# AWS_ACCESS_KEY_ID
# AWS_SECRET_ACCESS_KEY
# GITHUB_RELEASE_TOKEN
# DOCKER_HUB_EMAIL
# DOCKER_HUB_USERNAME
# DOCKER_HUB_PASSWORD
# AWS S3 bucket name, need to have access setup.
# Can be overridden by travis private variable set in travis settings: AWS_BUCKET_OVERRIDE
- AWS_BUCKET_DEFAULT=mender-buildsystem
# AWS S3 bucket name, to store updated docs
- AWS_BUCKET_DOCS=mender-docs
# AWS region.
# Can be overridden by travis private variable set in travis settings: AWS_REGION_OVERRIDE
- AWS_REGION_DEFAULT=eu-west-1
# AWS S3 ACL for build artifacts.
# Valid ACL values are: private, public_read, public_read_write, authenticated_read,
# bucket_owner_read, bucket_owner_full_control.
# Can be overridden by travis private variable set in travis settings: AWS_S3_ACL_OVERRIDE
- AWS_S3_ACL_DEFAULT=private
# Perform deployment steps if the build is performed for build: user/repo_name
# $TRAVIS_REPO_SLUG could be used if want to perform deploy on any repo.
# Currently perform deployment steps only of building main repository.
# Can be overridden by travis private variable set in travis settings: DEPLOY_REPO_OVERRIDE
- DEPLOY_REPO_DEFAULT=mendersoftware/deployments
# Default configuration file (to be uploaded to S3 and Github Release).
- CONFIG_FILE=config.yaml
# Binary name to be uploaded to github release.
- GITHUB_RELEASE_BINARY=deployments
# Build artifacts list, fomat: "file1 file2 ./dir/file3"
# Can be overridden by travis private variable set in travis settings: BUILD_ARTIFATS_OVERRIDE
- BUILD_ARTIFATS_DEFAULT="deployments"
# Docker repository name
- DOCKER_REPOSITORY="mendersoftware/deployments"
# INTERNAL VARIABLES (for default/overrite management)
- AWS_BUCKET=${AWS_BUCKET_OVERRIDE:-$AWS_BUCKET_DEFAULT}
- AWS_REGION=${AWS_REGION_OVERRIDE:-$AWS_REGION_DEFAULT}
- AWS_S3_ACL=${AWS_S3_ACL_OVERRIDE:-$AWS_S3_ACL_DEFAULT}
- DEPLOY_REPO=${DEPLOY_REPO_OVERRIDE:-$DEPLOY_REPO_DEFAULT}
- BUILD_ARTIFATS=${BUILD_ARTIFATS_OVERRIDE:-$BUILD_ARTIFATS_DEFAULT}
before_install:
# Install code coverage / tooling
- go get -u github.com/axw/gocov/gocov
- go get -u golang.org/x/tools/cmd/cover
# Install cyclomatic dependency analysis tool
- go get -u github.com/fzipp/gocyclo
# Install fakes3
- gem install fakes3
# Install mongo 3.2
- sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
- echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
- sudo apt-get -qq update
- sudo apt-get install -y mongodb-org
- sudo apt-get -qq update && sudo apt-get -qq install -y npm e2tools
- sudo npm install -g swagger-cli
- pip2.7 install -U --user paramiko fabric PyYAML pytest requests
# Get our own Swagger verifier
- wget https://raw.githubusercontent.com/mendersoftware/autodocs/master/verify_docs.py
before_script:
# Print build info that binary is compiled with.
- echo $TRAVIS_COMMIT
- echo $TRAVIS_TAG
- echo $TRAVIS_BRANCH
- echo $TRAVIS_BUILD_NUMBER
- echo $TRAVIS_REPO_SLUG
# Test if code was formatted with 'go fmt'
# Command will format code and return modified files
# fail if any have been modified.
- if [ -n "$(go fmt)" ]; then echo 'Code is not formatted with "go fmt"'; false; fi
# Perform static code analysys
- go vet `go list ./... | grep -v vendor`
# Fail builds when the cyclomatic complexity reaches 15 or more
- gocyclo -over 15 `find . -iname '*.go' | grep -v 'vendor' | grep -v '_test.go'`
# Verify that the Swagger docs are valid
- swagger validate docs/*.yml
# Verify that the Swagger docs follow the autodeployment requirements
- python2.7 verify_docs.py `find docs -name "*.yml"`
script:
# go list supply import paths for all sub directories.
# Exclude vendor directory, we don't want to run tests and coverage for all dependencies every time,
# also including their coverage may introduce to much noice. Concentrate on the coverage of local packages.
# Execute go test on every local subpackage (resolved as dependencies) and generate covreage report for each.
# Test packages pararell (xargs -P)
- go list ./... | grep -v vendor | xargs -n1 -I {} -P 4 go test -v -covermode=atomic -coverprofile=../../../{}/coverage.txt {}
# Insert build information into compiled binary using ldflags
- CGO_ENABLED=0 go build -ldflags "-X main.Commit=`echo $TRAVIS_COMMIT` -X main.Tag=`echo $TRAVIS_TAG` -X main.Branch=`echo $TRAVIS_BRANCH` -X main.BuildNumber=`echo $TRAVIS_BUILD_NUMBER`"
# Build docker image from docker file
- sudo docker build -t $DOCKER_REPOSITORY:pr .
# Clone integration repo. for api testing (purposely after license checking..)
- git clone https://github.com/mendersoftware/integration.git integration_new
# Move script to testing directory
- mv integration_new/extra/travis-testing/run-test-environment tests
- if [ "$JOB_TYPE" = compile_and_integration_tests_fast ]; then
( cd $PWD/integration_new/tests && bash run.sh --runfast --docker-compose-file=../../tests/docker-compose-integration.yml );
fi
- if [ "$JOB_TYPE" = compile_and_integration_tests_slow ]; then
( cd $PWD/integration_new/tests && bash run.sh --runslow --docker-compose-file=../../tests/docker-compose-integration.yml );
fi
after_success:
# Integrate with https://codecov.io
- bash <(curl -s https://codecov.io/bash)
# Make build directory and copy all artifacts to this directory.
- mkdir build
- cp $BUILD_ARTIFATS $CONFIG_FILE build/
# Check if api docs have changed
- git show --stat ${TRAVIS_COMMIT_RANGE} | grep -E "docs/.+\.yml" && export API_DOCS_CHANGED=true
before_deploy:
# Master is always lastest
- if [ ! -z "$TRAVIS_TAG" ]; then export IMAGE_TAG=$TRAVIS_TAG; else export IMAGE_TAG=$TRAVIS_BRANCH; fi
- docker tag $DOCKER_REPOSITORY:pr $DOCKER_REPOSITORY:$IMAGE_TAG
# Upload image to docker registry only on PUSH
- docker login --email=$DOCKER_HUB_EMAIL --username=$DOCKER_HUB_USERNAME --password=$DOCKER_HUB_PASSWORD
# Set latest tag only for HEAD of master branch
- if [ "$TRAVIS_BRANCH" = "master" ]; then
docker tag $DOCKER_REPOSITORY:pr $DOCKER_REPOSITORY:latest;
docker push $DOCKER_REPOSITORY:latest;
fi
- docker push $DOCKER_REPOSITORY:$IMAGE_TAG
deploy:
# In case tag is set. Deploy build as github release.
# List of files to be uploaded need to be specified in 'file' field
-
provider: releases
api_key: $GITHUB_RELEASE_TOKEN
file:
-$GITHUB_RELEASE_BINARY
-$CONFIG_FILE
skip_cleanup: true
on:
repo: $DEPLOY_REPO
tags: true
all_branches: true
# Deploy tag builds to S3 in structure /user/repo/release/tag/os_arch/
-
provider: s3
access_key_id: $AWS_ACCESS_KEY_ID
secret_access_key: $AWS_SECRET_ACCESS_KEY
bucket: $AWS_BUCKET
region: $AWS_REGION
upload-dir: $DEPLOY_REPO/release/$TRAVIS_TAG/`go env GOOS`_`go env GOARCH`
local_dir: build
skip_cleanup: true
acl: $AWS_S3_ACL
on:
repo: $DEPLOY_REPO
tags: true
all_branches: true
# Deploy all development builds to S3 in structure /user/repo/dev/branch/build/os_arch/
-
provider: s3
access_key_id: $AWS_ACCESS_KEY_ID
secret_access_key: $AWS_SECRET_ACCESS_KEY
bucket: $AWS_BUCKET
region: $AWS_REGION
upload-dir: $DEPLOY_REPO/dev/$TRAVIS_BRANCH/$TRAVIS_BUILD_NUMBER/`go env GOOS`_`go env GOARCH`
local_dir: build
skip_cleanup: true
acl: $AWS_S3_ACL
on:
repo: $DEPLOY_REPO
tags: false
all_branches: true
# Deploy all builds to S3 as latest folder /user/repo/latest/branch/os_arch
-
provider: s3
access_key_id: $AWS_ACCESS_KEY_ID
secret_access_key: $AWS_SECRET_ACCESS_KEY
bucket: $AWS_BUCKET
region: $AWS_REGION
upload-dir: $DEPLOY_REPO/latest/$TRAVIS_BRANCH/`go env GOOS`_`go env GOARCH`
local_dir: build
skip_cleanup: true
acl: $AWS_S3_ACL
on:
repo: $DEPLOY_REPO
# Store docs for auto-deployment script
-
provider: s3
access_key_id: $AWS_ACCESS_KEY_ID
secret_access_key: $AWS_SECRET_ACCESS_KEY
bucket: $AWS_BUCKET_DOCS
region: $AWS_REGION
upload-dir: $DEPLOY_REPO/latest/$TRAVIS_BRANCH
local_dir: docs
skip_cleanup: true
acl: public_read
on:
repo: $DEPLOY_REPO
all_branches: true
condition: $API_DOCS_CHANGED = true