-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathbuilder.sh
163 lines (116 loc) · 3.69 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
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
#!/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 repo=${1?Need repo}
local tag=${2?Need tag}
local cmd=${3?Need command}
local backup_pwd
local context
local last_line
local test_result
local -i exit_code=0
case "${repo}" in
base )
context="docker/ubuntu-vnc-xfce"
;;
chromium )
context="docker/ubuntu-vnc-xfce-chromium"
;;
firefox )
context="docker/ubuntu-vnc-xfce-firefox"
;;
firefox-plus )
context="docker/ubuntu-vnc-xfce-firefox-plus"
;;
* )
echo "Supported 'repo' values: base, chromium, firefox, firefox-plus"
;;
esac
backup_pwd=${PWD}
case "${cmd}" in
build | test )
cd "${context}"
hooks/"${cmd}" "${tag}"
exit_code=$?
;;
push )
cd "${context}"
docker_hub_connect
if [ $? -eq 0 ] ; then
### push to Docker Hub
hooks/"${cmd}" "${tag}"
exit_code=$?
docker logout
else
echo "Unable to connect to Docker hub!"
exit_code=1
fi
;;
all )
echo
echo "------------------"
echo "--> Building image"
echo "------------------"
echo
cd "${context}"
hooks/build "${tag}"
if [ $? -eq 0 ] ; then
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}"
exit_code=$?
docker logout
echo
echo "Refreshing README..."
cd ../../utils
./util-refresh-readme.sh
else
echo "Unable to connect to Docker hub!"
exit_code=1
fi
else
echo "Version sticker has changed. Adjust 'env' hook and refresh README using 'util-refresh-readme.sh'. Use 'test' command for details."
exit_code=1
fi
fi
;;
*)
echo "Unknown command: ${cmd}"
exit_code=1
;;
esac
cd "${backup_pwd}"
return ${exit_code}
}
main $@