-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtravis.sh
executable file
·91 lines (83 loc) · 1.7 KB
/
travis.sh
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
#!/bin/bash
EXIT_CODE=0
ROOT_DIR=$(pwd)
packer_validate() {
cd ${ROOT_DIR}
echo -e "Packer templates validate:\r\n"
for template in packer/*.json; do
if [[ ${template} == "packer/variables.json" ]]
then {
continue
}
fi
echo -n "Checking template: $template: "
result="$(packer validate -var-file=packer/variables.json.example ${template})"
if grep -q "success" <<< ${result}
then {
echo -e "Success"
continue
}
fi
echo -e "Fail: $template"
echo "$result"
EXIT_CODE=1
done
}
ansible_validate() {
cd ${ROOT_DIR}
echo -e "\r\nAnsible playbooks validation:\r\n"
if (ansible-lint ansible/playbooks/*.yml)
then {
echo -e "Success"
return
}
fi
echo -e "Fail"
EXIT_CODE=1
}
terraform_validate() {
env=${1}
cd ${ROOT_DIR}/terraform/${env}
echo -e "\r\nTerraform validate. Environment ${env}:\r\n"
vars_example_filename="terraform.tfvars"
cp terraform.tfvars.example ${vars_example_filename}
terraform init -backend=false
result="$(terraform validate)"
if grep -q "error:" <<< ${result}
then {
echo -e "Fail"
EXIT_CODE=1
return
}
fi
result="$(tflint)"
rm -f ${vars_example_filename}
if grep -q "Awesome!" <<< ${result}
then {
echo -e "Success"
return
}
fi
echo -e "Fail"
EXIT_CODE=1
}
readme_build_status_validate() {
cd ${ROOT_DIR}
echo -e "\r\nReadme validate:\r\n"
if grep -q "\[Build Status\]" README.md
then {
echo -e "Success"
return
}
fi
echo -e "Fail"
EXIT_CODE=1
}
mkdir ~/.ssh
touch ~/.ssh/appuser.pub ~/.ssh/appuser
packer_validate
ansible_validate
terraform_validate stage
terraform_validate prod
readme_build_status_validate
exit ${EXIT_CODE}