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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
source sandbox-env.sh
build() {
# prepare puppet recipes
cp -r ../../bigtop-deploy/puppet bigtop-puppet
# docker build
docker-compose build --force-rm --no-cache --pull
if [ $? -eq 0 ]; then
echo "-------------------------------------------------"
echo "Image $ACCOUNT/sandbox:$TAG built"
echo "-------------------------------------------------"
fi
}
cleanup() {
rm -rf bigtop-puppet site.yaml.template Dockerfile
}
generate_config() {
cat > site.yaml.template << EOF
bigtop::hadoop_head_node: ${HEAD_NODE:-"head.node.fqdn"}
hadoop::hadoop_storage_dirs: [/data/1, /data/2]
bigtop::bigtop_repo_uri: ${REPO}
hadoop_cluster_node::cluster_components: [${COMPONENTS}]
bigtop::jdk_package_name: ${JDK}
EOF
}
generate_dockerfile() {
cat > Dockerfile << EOF
FROM bigtop/puppet:${OS}
ADD startup.sh /startup.sh
ADD bigtop-puppet /bigtop-puppet
ADD bigtop-puppet/hiera.yaml /etc/puppet/hiera.yaml
ADD bigtop-puppet/hieradata /etc/puppet/hieradata
ADD site.yaml.template /etc/puppet/hieradata/site.yaml.template
RUN /startup.sh --bootstrap
CMD /startup.sh --foreground
EOF
}
generate_tag() {
if [ -z "$TAG" ]; then
TAG="${OS}_`echo ${COMPONENTS//,/_} | tr -d ' '`"
fi
}
detect_jdk() {
for RPM in ${RPMS[*]}; do
[[ $OS == $RPM ]] && JDK=$RPM_JDK
done
for DEB in ${DEBS[*]}; do
[[ $OS == $DEB ]] && JDK=$DEB_JDK
done
}
detect_repo() {
OS_SEP_BY_SLASH=${OS/-//}
REPO=${REPO:-"http://bigtop-repos.s3.amazonaws.com/releases/${BIGTOP_VERSION}/${OS_SEP_BY_SLASH}/x86_64"}
}
image_config_validator() {
invalid=1
if [ -z "$ACCOUNT" ]; then
echo "account unset!"
invalid=0
fi
if [ -z "$OS" ]; then
echo "operating system unset!"
invalid=0
fi
if [ -z "$TAG" ]; then
echo "tag unset!"
invalid=0
fi
if [ $invalid -eq 0 ]; then
usage
fi
}
deploy_config_validator() {
invalid=1
if [ -z "$REPO" ]; then
echo "repository unset!"
invalid=0
fi
if [ -z "$JDK" ]; then
echo "jdk unset!"
invalid=0
fi
if [ -z "$COMPONENTS" ]; then
echo "components unset!"
invalid=0
fi
if [ $invalid -eq 0 ]; then
usage
fi
}
show_image_configs() {
echo "-------------------------------------------------"
echo "IMAGE CONFIGS:"
echo "ACCOUNT $ACCOUNT"
echo "OS $OS"
echo "TAG $TAG"
echo "IMAGE $ACCOUNT/sandbox:$TAG"
echo "-------------------------------------------------"
}
show_deploy_configs() {
echo "-------------------------------------------------"
echo "DEPLOY CONFIGS:"
echo "REPOSITORY $REPO"
echo "COMPONENTS $COMPONENTS"
echo "JDK $JDK"
echo "-------------------------------------------------"
}
log() {
echo -e "\n[LOG] $1\n"
}
usage() {
echo "usage: $PROG args"
echo " -a, --account Specify account name for image."
echo " -c, --components Specify components to build."
echo " You need to specify a comma separated, quoted string."
echo " For example: --components \"hadoop, yarn\""
echo " -d, --dryrun Generate the Dockerfile and configuration and skip the build."
echo " -f, --file Specify a written site.yaml config file."
echo " -o, --operating-system Specify an OS from Bigtop supported OS list."
echo " RPM base: ${RPMS[*]}"
echo " DEB base: ${DEBS[*]}"
echo " -t, --tag Specify tag for image."
echo " If not specified, this will be auto filled by specified OS and components."
exit 1
}
while [ $# -gt 0 ]; do
case "$1" in
-a|--account)
if [ $# -lt 2 ]; then
usage
fi
ACCOUNT=$2
shift 2;;
-d|--dryrun)
DRYRUN=true
shift;;
-c|--components)
if [ $# -lt 2 ]; then
usage
fi
COMPONENTS=$2
shift 2;;
-f|--file)
if [ $# -lt 2 ]; then
usage
fi
FILE=$2
shift 2;;
-o|--operating-system)
if [ $# -lt 2 ]; then
usage
fi
OS=$2
shift 2;;
-t|--tag)
if [ $# -lt 2 ]; then
usage
fi
TAG=$2
shift 2;;
*)
echo "Unknown argument: '$1'" 1>&2
usage;;
esac
done
cleanup
generate_tag
image_config_validator
show_image_configs
if [ -z "$FILE" ]; then
detect_jdk
detect_repo
deploy_config_validator
generate_config
show_deploy_configs
else
if [ -f "$FILE" ]; then
cp -vfr $FILE site.yaml.template
else
log "$FILE not exist!"
exit 1
fi
fi
export ACCOUNT
export TAG
generate_dockerfile
if [ "$DRYRUN" == true ]; then
log "Generated Dockerfile:"
cat Dockerfile
exit 0
fi
build
cleanup
|