-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathcreate_docker
executable file
·127 lines (109 loc) · 5.01 KB
/
create_docker
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
#!/bin/bash
IMAGE_REPO="scoopex666"
IMAGE_NAME="zabbix-agent-with-agent-extensions"
CONTAINER_TEST_NAME="zabbix-agent-extentions-test"
VERSION="${2:-$(git describe --abbrev=0 --tags)}"
FAILED_TESTS=""
assertSuccess(){
local STRATEGY="$1"
local CMD="docker exec -u root -ti ${CONTAINER_TEST_NAME} $2"
echo "****************************************************************************"
echo "** EXECUTE: $CMD";
eval "$CMD 2>&1"
local RET="$?"
echo "**"
if [ "$RET" != "0" ];then
echo "** ERROR: execution failed (returncode $RET)"
FAILED_TESTS="$FAILED_TESTS#assertSuccess => $CMD"
echo "****************************************************************************"
if [ "$STRATEGY" = "STOP_ON_ERROR" ];then
exit 100
else
return 100
fi
fi
echo "****************************************************************************"
return 0
}
testPackage(){
buildDocker
docker stop ${CONTAINER_TEST_NAME}
set -x
docker run --privileged --rm \
-d \
--network host \
-v $PWD:/src \
-e ZBX_HOSTNAME=${CONTAINER_TEST_NAME} \
-e ZBX_SERVER_HOST=127.0.0.1 \
-e ZBX_PASSIVESERVERS=127.0.0.1 \
--name ${CONTAINER_TEST_NAME} ${IMAGE_NAME}:${VERSION}
set +x
echo '{ "{#FOO}" : "BAR" }' | docker exec -i -u root ${CONTAINER_TEST_NAME} tee /etc/zabbix/zabbix-discovery-generic/foo-bar.json
assertSuccess STOP_ON_ERROR "ls -l /etc/zabbix/zabbix-discovery-generic/foo-bar.json"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'generic.discovery[foo,json]' | tee /dev/stderr | grep -q -P 'BAR'" # Without sudo
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k linux.dmesg | tee /dev/stderr | grep -q -P 'OK: ALL OK|ERROR:'" # Without sudo
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k linux.dmesg | tee /dev/stderr | grep -q -P 'OK: ALL OK|ERROR:'" # Without sudo
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k linux.multipath | tee /dev/stderr | grep -q 'OK:'" # With sudo
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'custom.process[zabbix_agentd,minage]'|tee /dev/stderr | grep -q -P '^\d+'"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'custom.process[zabbix_agentd,maxage]'|tee /dev/stderr | grep -q -P '^\d+'"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'custom.process[nosuchprocess,maxage]'|tee /dev/stderr | grep -q -P '^\d+'"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'zabbix.agent_extensions.version'|tee /dev/stderr | grep -q -P '^\d+'"
docker exec -i -u root ${CONTAINER_TEST_NAME} mkdir -m 755 -p /opt/puppetlabs/puppet/cache/state/
docker exec -i -u root ${CONTAINER_TEST_NAME} cp /src/extension-files/test/last_run_summary.yaml /opt/puppetlabs/puppet/cache/state/last_run_summary.yaml
docker exec -i -u root ${CONTAINER_TEST_NAME} cp /src/extension-files/test/last_run_report.yaml /opt/puppetlabs/puppet/cache/state/last_run_report.yaml
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'puppet[state]'|tee /dev/stderr | grep -q -P '^OK: puppetrun successful, no changes'"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'puppet[changes,total]'|tee /dev/stderr | grep -q -P '^\d+'"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'puppet[environment]'|tee /dev/stderr | grep -q -P '^production_master'"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k vfs.dev.discovery | tee /dev/stderr | grep -q '#BLOCKDEVICE'"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k vfs.fs.discovery | grep -v /proc"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k nfs.rpc.calls|grep -P '^\d+'"
docker stop ${CONTAINER_TEST_NAME}
echo
echo
echo "*** SUMMARY"
if [ -z "$FAILED_TESTS" ];then
echo "ALL TESTS PASSED"
return 0
else
echo "THE FOLLOWING TESTS FAILED"
echo "$FAILED_TESTS"|tr '#' '\n'|sed '~s,^, ,'
return 1
fi
}
buildDocker(){
set -x
docker rmi ${IMAGE_NAME}:${VERSION}
set -e
docker build --progress plain \
--build-arg BUILD_DATE="$(date "+%Y-%m-%d")" \
--build-arg BUILD_VERSION="$VERSION" \
-t ${IMAGE_NAME}:${VERSION} -f Dockerfile .
sed "~s,${IMAGE_REPO}/${IMAGE_NAME}:latest,${IMAGE_REPO}/${IMAGE_NAME}:${VERSION}," zabbix-agent-daemonset-kubernetes.yaml > \
zabbix-agent-daemonset-kubernetes-release.yaml
set +xe
}
inspectDocker(){
set -x
docker stop ${CONTAINER_TEST_NAME}
exec docker run --network host --rm --name ${CONTAINER_TEST_NAME} -ti ${IMAGE_NAME}:${VERSION} /bin/bash
}
publishDocker(){
buildDocker
set -xe
docker tag ${IMAGE_NAME}:${VERSION} ${IMAGE_REPO}/${IMAGE_NAME}:${VERSION}
docker push ${IMAGE_REPO}/${IMAGE_NAME}:${VERSION}
docker tag ${IMAGE_NAME}:${VERSION} ${IMAGE_REPO}/${IMAGE_NAME}:latest
docker push ${IMAGE_REPO}/${IMAGE_NAME}:latest
set +xe
}
if [ "$1" = "build" ];then
buildDocker
elif [ "$1" = "inspect" ];then
inspectDocker
elif [ "$1" = "publish" ];then
publishDocker
elif [ "$1" = "test" ];then
testPackage
else
echo "$0 build|inspect|publish|test"
fi