forked from kubenow/KubeNow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.travis.yml
213 lines (192 loc) · 8.27 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
---
language: python # (Ansible)
sudo: required
services:
- docker
branches:
except:
- /^experimental\/.*$/
- /^exp\/.*$/
- /^testing\/.*$/
- /^test\/.*$/
- /^doc\/.*$/
- /^docs\/.*$/
- /^documentation\/.*$/
env:
global:
- TERRAFORM_VERSION=0.10.7
- YAMLLINT_VERSION=1.8.1
matrix:
- HOST_CLOUD=openstack
- HOST_CLOUD=gce
- HOST_CLOUD=aws
before_install:
# Install code review tools
# Install Terraform
- >
travis_retry curl
"https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip"
> /tmp/terraform.zip
- sudo unzip /tmp/terraform.zip -d /usr/bin
- sudo chmod +x /usr/bin/terraform
# Install pip deps
- sudo pip install --upgrade pip
- >
sudo pip install
yamllint=="${YAMLLINT_VERSION}"
# Check code quality
# check Terraform
- terraform fmt -check=true common/cloudflare
- terraform fmt -check=true common/inventory
- terraform fmt -check=true "$HOST_CLOUD"
# check Ansible
# skip ANSIBLE0006: avoid using curl
# skip ANSIBLE0012: missing change_when on command/shell etc.
- docker run --rm -v ${PWD}/playbooks:/playbooks yokogawa/ansible-lint:v3.4.16 sh -c 'ansible-lint -x ANSIBLE0006,ANSIBLE0012 /playbooks/*.yml'
# check Shell
- docker run -v "$(pwd)":/mnt koalaman/shellcheck:v0.5.0 bootstrap/*
- docker run -v "$(pwd)":/mnt koalaman/shellcheck:v0.5.0 bin/*
- docker run -v "$(pwd)":/sh -w /sh jamesmstone/shfmt -i 2 -w bin/*
- docker run -v "$(pwd)":/sh -w /sh jamesmstone/shfmt -i 2 -w bootstrap/*
- git diff --exit-code
# check Dockerfile
- docker run --rm -i hadolint/hadolint:v1.13.0 hadolint --ignore DL3008 --ignore DL3015 --ignore DL3013 - < Dockerfile
# check YAML
- yamllint -c .yamllint.yml -s $(find . -type f -name "*.yml")
install:
# Build Docker image
# Create a docker image tag out of branch-name where / is replaced by -
- tag="${TRAVIS_BRANCH/\//-}"
- docker build -t kubenow/provisioners:$tag .
before_script:
# Copy kn bin
- sudo cp bin/kn /usr/local/bin/
# Init test deployment
- export KN_PROVISIONERS_IMG=kubenow/provisioners:$tag
- kn init ${HOST_CLOUD} test-deployment
- cd test-deployment
# Overwrite ssh-key for debug purposes
- echo -e "$TRAVIS_SSH_KEY_PRIV" > ssh_key
- echo -e "$TRAVIS_SSH_KEY_PUB" > ssh_key.pub
# RENDER CONFIGURATION
# Common
- sed -i -e "s/your-cluster-prefix/kubenow-ci-${TRAVIS_BUILD_NUMBER}-${HOST_CLOUD}/g" config.tfvars
# AWS
- sed -i -e "s/your-acces-key-id/${AWS_ACCESS_KEY_ID}/g" config.tfvars
- sed -i -e "s#your-secret-access-key#${AWS_SECRET_ACCESS_KEY}#g" config.tfvars
- sed -i -e "s/eu-west-1/${AWS_DEFAULT_REGION}/g" config.tfvars
# GCE
- printf '%s\n' "$GCE_CREDENTIALS" > "./service-account.json"
- sed -i -e "s/your_project_id/${GCE_PROJECT_ID}/g" config.tfvars
# OS
- sed -i -e "s/your-pool-name/${OS_POOL_NAME}/g" config.tfvars
- sed -i -e "s/external-net-uuid/${OS_EXTERNAL_NET_UUID}/g" config.tfvars
- sed -i -e "s/your-master-flavor/${OS_MASTER_FLAVOR}/g" config.tfvars
- sed -i -e "s/your-node-flavor/${OS_NODE_FLAVOR}/g" config.tfvars
- sed -i -e "s/your-edge-flavor/${OS_EDGE_FLAVOR}/g" config.tfvars
- sed -i -e "s/your-glusternode-flavor/${OS_NODE_FLAVOR}/g" config.tfvars
# Enable edges
- sed -i -e "s/# edge/edge/g" config.tfvars
# Enable glusternodes
- sed -i -e "s/# glusternode/glusternode/g" config.tfvars
# Cloudflare
- sed -i -e "s/# use_cloudflare/use_cloudflare/g" config.tfvars
- sed -i -e "s/# cloudflare_email = \"your-cloudflare-email\"/cloudflare_email = \"${CI_CLOUDFLARE_EMAIL}\"/g" config.tfvars
- sed -i -e "s/# cloudflare_token = \"your-cloudflare-token\"/cloudflare_token = \"${CI_CLOUDFLARE_TOKEN}\"/g" config.tfvars
- sed -i -e "s/# cloudflare_domain = \"your-domain-name\"/cloudflare_domain = \"${CI_CLOUDFLARE_DOMAIN}\"/g" config.tfvars
- >
sed -i -e
"s/# cloudflare_subdomain = \"your-subdomain-name\"/cloudflare_subdomain = \"kubenow-ci-${TRAVIS_BUILD_NUMBER}-${HOST_CLOUD}\"/g"
config.tfvars
# Enable etcd-encryption
- sed -i -e 's/\"encrypt_etcd.*false\"/\"encrypt_etcd\" = \"true\"/g' config.tfvars
script:
# First test commands outside the init-dir (before cluster is deployed)
- cd /tmp
- kn openstack --version # try to run an openstack command
- kn az --version # try to run an azure cli command
- kn gcloud --version # try to run an gcloud cli command
- cd -
# Deploy
- travis_retry kn apply
# Test
- kn ansible-playbook /opt/KubeNow/playbooks/infra-test.yml
- kn kubectl get nodes # try to list nodes
- kn helm list # try to helm list
- kn helm del --purge cheese # in order to allow other test later
- kn ssh master 'uname && exit' # ssh to master and execute commands
- sed -i -e "s/node_count = \"3\"/node_count = \"2\"/g" config.tfvars # test scaling function
- kn scale
# Making sure cluster is ok after kn scale
- kn kubectl get nodes # try to list nodes
- kn ansible-playbook /opt/KubeNow/playbooks/infra-test.yml
after_script:
- export TERRAFORM_OPT="-force" && travis_retry kn destroy
- >
travis_retry rm -f .terraform/plugin_path
&& terraform init "$HOST_CLOUD"
&& terraform destroy -force -var-file=config.tfvars "$HOST_CLOUD" # in case there is some problem with kn
jobs:
include:
# Docker push stage
- stage: Push container
before_install: true
install: true
before_script: true
after_script: true
script:
# Build and push Docker image (needs to be build again in this stage)
- docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
- >
if [[ -n "$TRAVIS_TAG" ]]; then
docker build -t kubenow/provisioners:$TRAVIS_TAG \
-t kubenow/provisioners:latest .
docker push kubenow/provisioners:$TRAVIS_TAG
docker push kubenow/provisioners:latest
elif [[ "$TRAVIS_BRANCH" == "master" ||
"$TRAVIS_BRANCH" == *"stable"* ||
"$TRAVIS_BRANCH" == *"development"* ]]; then
# Create a docker image tag out of branch-name where / is replaced by -
tag="${TRAVIS_BRANCH/\//-}"
docker build -t kubenow/provisioners:$tag .
docker push kubenow/provisioners:$tag
fi
# If tag, create a versioned kn CLI
- >
if [ ! -z $TRAVIS_TAG ]; then
sed -i -e "s/kubenow_version=\"master\"/kubenow_version=\"${TRAVIS_TAG}\"/g" bin/kn
fi
deploy:
provider: releases
file: bin/kn
skip_cleanup: true
api_key:
secure: >
kTW1R8oSIGm91Vc4p9fw921REV234A6hv9P1VN4Yf6WBp3/UW1hGKm2K9/QSkovpSTEW1W
nx3Sj63rb3L91xr+0sFGwI71nLGGWvjiOFKMl0HeJjF4OX+G6V6xdFF/CDW94hof+Lhzjk
flxri1iR66dt5X45FnH4frvybBvg0yCyqL2EidZc+0WEbiocEINsgRnGMHJjYNVty0ee9A
GOZJbts1UBoh5CmHkfNwchblvjipl/HqZ/KFcPmLpc5urb37ppe9qUA3smyYWnwzqQua0u
k3jj79MKjvXIUY5OliihWFbTeGDmdMsKYRFp4cVDXU+gKOYFFlmybzgnU7D15XhepCqvqd
CDAbgmUakti8R1dXbM2AKeP59xJLjEQeaJBL3uGcND4nu9+uHwnoT6k+rWwpJxkxdYoMgf
YGHsZn8voCL2JbsNujsDvR5G9k6Wt/z5dGsJzzrHrunkaTQ3vTTsa+R1xwwGuJVvNbnG9h
iAXr4ERmUfY6cMawVIyp6WKpNs+d20jWyEzEfOpxVIchLGLlNqH1/fHZqTZGiL0TvALxe7
R3iHvmMotMv8UUAM/qaHROzOmWke5xv3oBAa26iB4UFoiWltGy22o6MbqQpdn2JyocbZvH
m3xyck3pd6R7kQSHeDaQ4PpNwbDDYnTvb5sgjVtneNwswZPUZ4ojc=
on: # yamllint disable-line rule:truthy
tags: true
notifications:
email: true
slack:
on_success: change
on_failure: always
secure: >
ed+rC8Oc4EdZfptHGX1Xr5sNc+wQTyjb4rjJT0P/U/NBStmik7dnUfAK9vk6XYVDrrPZxmAz6A
cJmEaxY4kdG2HBLBPD0keRxKh2rN2ZbjCTWuGlAomMkmNDcyeVoQI95HcT0nYHzgoUCGn7lgZ7
9vBUhBqbJXUWbvkz7J5qn8Kx7PXWvmjW4YLu9RhuIP7JtZLDLJt9dgyeHXDm1CW3tvPPplv9e8
l1GOcF2DBqodwd8+U5BTCNXf1DdwdvlmzIaZemy3sAsvNEr5wEIuO0Zw2cayhV80nf9fWW58ne
NBV2i8oeAuCL/M3EkEE/Z4aI/zxBVRyTaeK0s+XKehlC7IDJxnMirbNn2X4yyUeWY/81DX+Hhb
pip46TGQpS0sST8rBd7JYj0LjGSXj585xOcP67s9HdncnkVRdIdTOFX63m2bSE5tddJuOPggHZ
VKM8k+twXsWpW7sCr95wnwlD/ARuuG3OTtV0HfnHpqvKLdBgJ1fEsmKXn6eAaDvcCQ0K5LUBUs
yaZ9HHU7LYv7S760XgrmUEMR1SBsb9grFzANkAyhzApWQJ7wQbGD1IFX1kJl2v1Ii4WRgdVNll
YcMeflpHWPYI0U0IVXYPPLuV5DOEoKfWsJpX3HtZswYLdNzrZkSB9DQ/LxkSAZZcbkj9GLCv2E
igZHjgC3Ey2wwGIYQ=