forked from accetto/ubuntu-vnc-xfce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilder.sh
116 lines (79 loc) · 2.57 KB
/
builder.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
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
#!/bin/bash
### @accetto, August 2021
docker_hub_connect() {
if [ -n "${DOCKERHUB_USERNAME}" ] && [ -n "${DOCKERHUB_PASSWORD}" ] ; then
echo "Logging-in on Docker Hub..."
echo "${DOCKERHUB_PASSWORD}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin
if [ ! $? ] ; then
echo "Docker Hub login failed"
return 1
fi
else
echo "Local pushing requires Docker Hub login."
echo "However, your environment does not provide required authentication data."
return 1
fi
return 0
}
main() {
local tag=${1?Need tag}
local cmd=${2?Need command}
local last_line
local test_result
case "${cmd}" in
build | test )
./hooks/"${cmd}" "${tag}"
;;
push )
docker_hub_connect
if [ $? -eq 0 ] ; then
### push to Docker Hub
./hooks/"${cmd}" "${tag}"
docker logout
else
echo "Unable to connect to Docker hub!"
fi
;;
all )
echo
echo "------------------"
echo "--> Building image"
echo "------------------"
echo
./hooks/build "${tag}"
echo
echo "---------------------------"
echo "--> Testing version sticker"
echo "---------------------------"
echo
### test version sticker
test_result=$( hooks/test "${tag}" 2>&1 | tail -n5 )
echo "${test_result}"
echo
last_line=$(echo "${test_result}" | tail -n1)
if [ "${last_line}" == '+ exit 0' ] ; then
docker_hub_connect
if [ $? -eq 0 ] ; then
echo
echo "-------------------------"
echo "--> Pushing to Docker Hub"
echo "-------------------------"
echo
hooks/push "${tag}"
docker logout
echo
echo "Refreshing README..."
./utils/util-refresh-readme.sh
else
echo "Unable to connect to Docker hub!"
fi
else
echo "Version sticker has changed. Adjust 'env' hook and refresh README using 'util-refresh-readme.sh'. Use 'test' command for details."
fi
;;
*)
echo "Unknown command: ${cmd}"
;;
esac
}
main $@