-
Notifications
You must be signed in to change notification settings - Fork 954
/
ranger_in_docker
executable file
·257 lines (212 loc) · 7.39 KB
/
ranger_in_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
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/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.
#
# This script provides an reference implementation of what is specified in
# ./dev-support/ranger-docker/README.md
#
# Using this command, you should be able to build and run Apache Ranger
# within few minites (in a docker container)
#
# Pre Request:
#
# Java version 1.8.*
# Maven version 3.0+
# Docker Installation (docker, docker-compose, ...)
#
# By default, the directory where the script exists - is assumed to be RANGER_HOME.
# However, you can define RANGER_HOME to be a different directory before running this script via exported env variable.
#
# Also, you can force rebuild of ranger image by setting RANGER_REBUILD=1
# By default, the script will check if a ranger image does not exists and will do ranger build and docker image build.
#
# Also, you can force rebuild of ranger using local maven and java based build
# instead of building it using Docker based buid by setting DOCKER_MAVEN_BUILD=1.
#
# Also, you can optionally start services by setting ENABLED_RANGER_SERVICES env variables
# by defining comma separated optional services as following:
# ENABLED_RANGER_SERVICES="hadoop,hive,hbase,knox,kms"
# List of optional services:
# tagsync,hadoop,hbase,kafka,hive,knox,kms
#
if [ -z "${RANGER_HOME}" ]
then
rhd=`dirname $0`
RANGER_HOME=$(cd ${rhd}; pwd)
fi
RD_HOME=${RANGER_HOME}/dev-support/ranger-docker
ENV_FILE=${RD_HOME}/.env
source "${ENV_FILE}"
ENABLED_RANGER_SERVICE_FILE=${HOME}/.ranger_docker_services
[ -z "${RANGER_DB_TYPE}" ] && RANGER_DB_TYPE="postgres"
export ENABLE_DB_MOUNT
if [ "${ENABLE_DB_MOUNT}" = "true" ];
then
DB_SERVICE_NAME="ranger-${RANGER_DB_TYPE}-mounted"
else
DB_SERVICE_NAME="ranger-${RANGER_DB_TYPE}"
fi
CORE_SERVICES="ranger-base,ranger,${DB_SERVICE_NAME},ranger-usersync"
if [ -z "${ENABLED_RANGER_SERVICES}" ]
then
if [ -f ${ENABLED_RANGER_SERVICE_FILE} ]
then
ENABLED_RANGER_SERVICES="`cat ${ENABLED_RANGER_SERVICE_FILE}`"
fi
else
echo "${ENABLED_RANGER_SERVICES}" > ${ENABLED_RANGER_SERVICE_FILE}
fi
if [ ! -d "${RANGER_HOME}" ]
then
echo "ERROR: directory RANGER_HOME=[${RANGER_HOME}] does not exists."
exit 1
fi
export RD_HOME
cd ${RD_HOME}
ALL_SERVICES="${CORE_SERVICES} ${ENABLED_RANGER_SERVICES}"
for service in `echo ${ALL_SERVICES} | sed -e 's:,: :g'`
do
echo "${service}" | grep '^ranger' > /dev/null 2>&1
if [ $? -eq 0 ]
then
serviceFile="docker-compose.${service}.yml"
else
serviceFile="docker-compose.ranger-${service}.yml"
fi
[ -f ${serviceFile} ] && OPT="${OPT} -f ${serviceFile}"
done
#
# This is needed to build ranger-base build based on architecture
#
DOCKER_BUILDKIT=1
export DOCKER_BUILDKIT
if [ $# -eq 1 ]
then
DOCKER_ACTION="$1"
else
DOCKER_ACTION=""
fi
if [ "${DOCKER_ACTION}" != "up" -a "${DOCKER_ACTION}" != "down" ]
then
echo "ERROR: Invalid argument [${DOCKER_ACTION}]"
echo "USAGE: $0 <up|down>"
exit 1
fi
docker -v > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "ERROR: You must have a valid DOCKER installed on your system to do a docker build. (error running docker command)"
exit 1
fi
docker-compose --version > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "ERROR: You must have a valid DOCKER installed on your system to do a docker build. (error running docker-compose command)"
exit 1
fi
if [ -z "${DOCKER_MAVEN_BUILD}" ]
then
DOCKER_MAVEN_BUILD=0
fi
export RANGER_DB_TYPE
cd ${RANGER_HOME}
if [ ! -f ${ENV_FILE} ]
then
echo "ERROR: Environment file [${ENV_FILE}] is missing."
exit 1
fi
build_ranger=0
build_base_image=0
cd ${RD_HOME}
if [ ${DOCKER_ACTION} == "up" ]
then
DOCKER_COMPOSE_FLAGS="-d"
chmod +x download-archives.sh && ./download-archives.sh
if [ -z "${RANGER_REBUILD}" ]
then
noOfFiles=`ls -l ${RD_HOME}/dist/*.tar.gz 2> /dev/null| wc -l | awk '{ print $1 }'`
if [ ${noOfFiles} -lt 20 ]
then
#echo "Found only [${noOfFiles}] RANGER tar files. Enabling RANGER BUILD."
build_ranger=1
build_base_image=1
#else
#echo "Found [${noOfFiles}] RANGER tar files. Skipping RANGER BUILD. To Force RANGER BUILD, please set RANGER_REBUILD=1 before running this script."
fi
else
#echo "Found [RANGER_REBUILD as ${RANGER_REBUILD}]. Enabling RANGER BUILD."
build_base_image=1
build_ranger=1
fi
cd ${RD_HOME}
if [ ${build_base_image} -eq 0 ]
then
docker images ranger-base:latest 2> /dev/null | grep ranger-base > /dev/null 2>&1
if [ $? -ne 0 ]
then
build_base_image=1
fi
fi
if [ ${build_base_image} -eq 1 ]
then
echo "+ docker-compose -f docker-compose.ranger-base.yml build --no-cache"
docker-compose -f docker-compose.ranger-base.yml build --no-cache
fi
if [ ${build_ranger} -eq 1 ]
then
if [ ${DOCKER_MAVEN_BUILD} -eq 0 ]
then
cd ${RD_HOME}
echo "+ docker-compose -f docker-compose.ranger-base.yml -f docker-compose.ranger-build.yml down --remove-orphans"
docker-compose -f docker-compose.ranger-base.yml -f docker-compose.ranger-build.yml down --remove-orphans
echo "+ docker-compose -f docker-compose.ranger-base.yml -f docker-compose.ranger-build.yml up"
docker-compose -f docker-compose.ranger-base.yml -f docker-compose.ranger-build.yml up
if [ $? -ne 0 ]
then
echo "ERROR: Unable to complete RANGER build using DOCKER. Exiting ...."
exit 1
fi
else
cd ${RANGER_HOME}
mvn clean package -DskipTests
if [ $? -ne 0 ]
then
echo "ERROR: Unable to complete RANGER build. Exiting ...."
exit 1
fi
cp target/ranger-* ${RD_HOME}/dist
cp target/version ${RD_HOME}/dist
fi
fi
fi
cd ${RD_HOME}
docker-compose ${OPT} ${DOCKER_ACTION} ${DOCKER_COMPOSE_FLAGS}
echo
echo "################### LIST OF DOCKER PROCESSES EXPOSING PORTS #####################"
echo
docker container ls --format "table {{.Names}}\t{{.Ports}}" -a | grep ranger | \
grep -v '^$' | awk '{ for(i = 2 ; i <= NF; i++) { print $1, $i } }' | \
grep -- '->' | sed -e 's:,::g' | awk '{ s = $2 ; split(s,a, "->") ; f = split(a[1],b,":"); print $1, b[f] }' | \
sort | uniq | awk '{ printf("SERVICE: %25s ExposedPort: %10s\n", $1, $2 ) ; }'
echo
echo "###################################################################################"
echo
if [ "${DOCKER_ACTION}" == "up" ]
then
echo
echo "Now, You can run access RANGER portal via http://localhost:6080 (admin/rangerR0cks!)"
echo
fi