forked from rafaeltuelho/jboss-eap-managed-on-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare.sh
executable file
·190 lines (156 loc) · 6.94 KB
/
prepare.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
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
#!/bin/bash
SOFTWARE_DIR="./software"
IMAGES_DIR="./docker-images"
USER_TAG_NAME="rsoares"
DOCKER0_NETIFC_DEFAULT_ADDR="172.17.42.1"
current_docker0_addr=$DOCKER0_NETIFC_DEFAULT_ADDR
EAP_SERVER_PKG_NAME="jboss-eap-*.zip"
EAP_PATCH_PKG_NAME="jboss-eap-*-patch*.zip"
EAP_NATIVE_PKG_NAME="jboss-eap-native*.zip"
EWS_HTTPD_PKG_NAME="jboss-ews-httpd*.zip"
JON_SERVER_PKG_NAME="jon-server-*.zip"
JON_UPDATE_PKG_NAME="jon-server-*-update-*.zip"
JON_PLUGIN_PKG_NAME="jon-plugin-*.zip"
RHQ_AGENT_PKG_NAME="rhq-enterprise-agent*.jar"
RED='\033[0;31m'
ORG='\033[0;33m'
NC='\033[0m' # No Color
echo -e "\n This setup needs the following softwares packages (zip files):
* JBoss EAP 6.x
\t** JBoss EAP paches (OPTIONAL)
\t** JBoss EAP Natives (for your platform, eg: Linux x86_64)
\t** JBoss EWS 2 Httpd (for your platform, eg: Linux x86_64)
* JBoss ON 3.x
\t** JON Pluggin Pack for EAP
\t** JON paches (OPTIONAL)
Before continue access the Red Hat Customer Portal (https://access.redhat.com):
* download all the packages listed above and
* put them in its respective directories inside 'software/' \n"
read -e -p " Want to continue (Y,n)?" -n 1 -r
echo
[[ ! "$REPLY" =~ ^[Yy]$ ]] && exit 1
echo -e "\n >>> Test if docker and compose is installed..."
docker --version
[[ $? != 0 ]] && echo -e "\tdocker engine not installed or not present in your PATH" && exit 1
docker-compose --version
[[ $? != 0 ]] && echo -e "\tdocker-compose not installed or not present in your PATH" && exit 1
if [[ ! "$OSTYPE" == "linux"* ]]; # host not linux like
then
echo
echo -e "It appears your host is not a Linux OS. Let's check if your have Docker Machine/Boot2Docker"
echo
docker-machine --version
[[ $? != 0 ]] && \
echo -e "\tdocker-machine not installed or not present in your PATH\n
\tPLEASE make shure your docker-machine instance is started and execute\n
\t\t eval \"\$(docker-machine env <machine instance name>)\" " && \
exit 1
echo
docker-machine ls
echo -e "\n\t ENSURE your docker-machine instance have enough Disk and RAM mem available to run this setup. I recomend at least 20gb Disk and 4gb RAM"
else
# Verify the IP ADDR for the docker0 network bridge
current_docker0_addr=$(ip addr show docker0 | awk '$1 == "inet" {gsub(/\/.*$/, "", $2); print $2}')
if [[ ! "$DOCKER0_NETIFC_DEFAULT_ADDR" == "$current_docker0_addr" ]];
then
echo -e "\n\t ${ORG}It appears your 'docker0' network bridge got a different IP Addr: $current_docker0_addr"
echo -e "\t\t ${ORG} in this case we need to change the 'docker-compose.yml' descriptor to use this addr as dnsmasq bind addr."
sed_expr="s/$DOCKER0_NETIFC_DEFAULT_ADDR/$current_docker0_addr/g"
sed -i.bkp $sed_expr ./docker-compose.yml
else
echo -e "\n\t ${ORG}'docker0' network bridge IP Addr: $current_docker0_addr \n"
fi
fi
#read
tput sgr0
docker images >/dev/null 2>&1
[[ $? != 0 ]] && \
echo -e "\t ups! It appears you ($USER) can't execute docker commands.
If you are running on Linux:
ENSURE your docker engine daemon service is running.
\t on RHEL 7: > sudo systemctl start docker \n
PLEASE add the $USER to the docker's system group:\n\n
\tsudo groupadd docker
\tsudo usermod -aG docker $USER
\tsudo chown root:docker /var/run/docker.sock \n
\tnow open a new terminal session and execute this script again\n\n
\tor execute this script as root using sudo!" && exit 1
function test_bin_pkgs(){
# in case the pkgs was moved to their docker-images dirs before. Bring them back to the software dir
./reverse_packages.sh
find_result=$(find $SOFTWARE_DIR/ -name "$1")
[[ -z $find_result ]] && \
echo -e "\t $1 file not found!
PLEASE download the binary package and put into software dir" && \
exit 1
}
function build_image(){
IMG_NAME="${1}"
#test if the image is already on local docker repo
docker images | grep "$USER_TAG_NAME/$IMG_NAME" >/dev/null 2>&1
if [ $? != 0 ] # image not found in the local repo
then
echo -e "----->
\t '$USER_TAG_NAME/$IMG_NAME' not found on local docker repo.
\t\t I will try to build it \n<-----\n"
[[ ! -f $IMAGES_DIR/$IMG_NAME/Dockerfile ]] && \
echo -e "\t Dockerfile not found for base image: $IMG_NAME" && \
exit 1
docker build -t "$USER_TAG_NAME/$IMG_NAME" $IMAGES_DIR/$IMG_NAME
else
echo -e "\n\t ${ORG}The image \"${USER_TAG_NAME}/${IMG_NAME}\" was found in your local docker registry!\n"
tput sgr0
read -e -p " Want to REBUILD it(N,y)?" -n 1 -r
echo
[[ $REPLY =~ ^[Yy]$ ]] && \
docker build -t "$USER_TAG_NAME/$IMG_NAME" $IMAGES_DIR/$IMG_NAME
fi
}
function updateComposeYML(){
DOCKER_BRIDGE_IP_ADDR=$(ip a s docker0 | sed -ne '/127.0.0.1/!{s/^[ \t]*inet[ \t]*\([0-9.]\+\)\/.*$/\1/p}')
sed -i 's;#DOCKER_BRIDGE_IP#;$DOCKER_BRIDGE_IP_ADDR;g' ./docker-compose.yml
}
# avoid permission error during build process
chmod a+rx $SOFTWARE_DIR/*
echo -e "\n >>> Check the softwares required to setup the environment"
test_bin_pkgs $EAP_SERVER_PKG_NAME
#test_bin_pkgs $EAP_PATCH_PKG_NAME
test_bin_pkgs $EAP_NATIVE_PKG_NAME
test_bin_pkgs $EWS_HTTPD_PKG_NAME
test_bin_pkgs $JON_SERVER_PKG_NAME
#test_bin_pkgs $JON_UPDATE_PKG_NAME
test_bin_pkgs $JON_PLUGIN_PKG_NAME
echo -e "\n >>> extracting the rhq-agent JAR installer..."
unzip -j "$SOFTWARE_DIR/$JON_UPDATE_PKG_NAME" \
"jon-server-*/modules/org/rhq/server-startup/main/deployments/rhq.ear/rhq-downloads/rhq-agent/rhq-enterprise-agent-*.jar" \
-d software/
echo -e "\n >>> Move the zip pkgs files to its respective image's DIRs"
# this is necessary because Dockerfile COPY does not support relative paths (../somepath)
cp $SOFTWARE_DIR/$RHQ_AGENT_PKG_NAME $IMAGES_DIR/jon-agent/software/
mv $SOFTWARE_DIR/$RHQ_AGENT_PKG_NAME $IMAGES_DIR/jon-postgres/software/
mv $SOFTWARE_DIR/$JON_UPDATE_PKG_NAME $IMAGES_DIR/jon-server/software/patch/ >/dev/null 2>&1
mv $SOFTWARE_DIR/$JON_PLUGIN_PKG_NAME $IMAGES_DIR/jon-server/software/
mv $SOFTWARE_DIR/$JON_SERVER_PKG_NAME $IMAGES_DIR/jon-server/software/
mv $SOFTWARE_DIR/$EAP_NATIVE_PKG_NAME $IMAGES_DIR/ews/software/
mv $SOFTWARE_DIR/$EWS_HTTPD_PKG_NAME $IMAGES_DIR/ews/software/
mv $SOFTWARE_DIR/$EAP_PATCH_PKG_NAME $IMAGES_DIR/eap/software/patch/ >/dev/null 2>&1
mv $SOFTWARE_DIR/$EAP_SERVER_PKG_NAME $IMAGES_DIR/eap/software/
echo -e "\n >>> Build images..."
echo -e "\n\t *** This step takes some minutes to finish... PLEASE WAIT...\n"
build_image "centos7-base"
build_image "java-base"
build_image "dnsmasq"
build_image "jon-agent"
build_image "jon-postgres"
build_image "jon-server"
build_image "ews"
build_image "eap"
echo -e "\n----->"
echo -e " >>> ALL SET!"
echo -e "\t now you can start all tyyhe environment"
echo -e "\t from this repo's root directory enter the following command
> docker-compose up
wait some minutes and VOILA!
<-----"
echo -e "\n\t Remember to add an entry in your /etc/resolv.conf: \n
nameserver $current_docker0_addr"