blob: 5cd926a985b495e0c1adc359f7e53df5557c8245 (
plain)
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
|
#!/bin/bash
#
# Copyright 2016-2017 Huawei Technologies Co., Ltd.
#
# Licensed 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.
#
# $1 dirsrc
# $2 autorelease build
set -e
dirsrc=$1
if [ -z "$2" ]; then
BUILD="snapshots"
else
BUILD=$2
fi
VERSION="1.1.0-SNAPSHOT"
# docker root dir
ROOT=`git rev-parse --show-toplevel`/test/csit/docker
cd $ROOT
dir=$dirsrc/target
mkdir -p $dir
if [ "$BUILD" = "snapshots" ]; then
$ROOT/scripts/gen-dockerfiles.py $dirsrc
else
$ROOT/scripts/gen-dockerfiles.py $dirsrc --build $BUILD
fi
# Update build number in workaround files
for file in `find $dirsrc -name 80-workaround.txt`; do
sed -i "s|autorelease-[0-9]\{4\}|$BUILD|" $file
done
cp $ROOT/../../../distribution/LICENSE $dir
cp -f $dirsrc/*.txt $dir 2>/dev/null || :
if [ -f $dir/20-mysql.txt ]; then
cp $ROOT/templates/init-mysql.sh $dir/init-mysql.sh
else
rm -f $dir/init-mysql.sh
fi
# empty 30-tomcat.txt would be created by gen-dockerfiles.py where required
if [ -f $dir/30-tomcat.txt ]; then
TOMCAT_VERSION=`$ROOT/scripts/get-tomcat-version.sh`
cat > $dir/30-tomcat.txt <<EOF
# 30-tomcat.txt - AUTOGENERATED, DO NOT MODIFY MANUALLY
# Set up tomcat
RUN wget -q http://mirrors.ocf.berkeley.edu/apache/tomcat/tomcat-8/v${TOMCAT_VERSION}/bin/apache-tomcat-${TOMCAT_VERSION}.tar.gz && tar --strip-components=1 -xf apache-tomcat-${TOMCAT_VERSION}.tar.gz && rm -f apache-tomcat-${TOMCAT_VERSION}.tar.gz && rm -rf webapps && mkdir -p webapps/ROOT
RUN echo 'export CATALINA_OPTS="\$CATALINA_OPTS -Xms64m -Xmx256m -XX:MaxPermSize=64m"' > /service/bin/setenv.sh
ENV CATALINA_HOME /service
EOF
fi
cat > $dir/docker-entrypoint.sh <<EOF
#!/bin/bash
#
# Copyright 2016-2017 Huawei Technologies Co., Ltd.
#
# Licensed 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 file was auto-generated by gen-all-dockerfiles.sh; do not modify manually.
#
# $dir/docker-entrypoint.sh
#
if [ -z "\$SERVICE_IP" ]; then
export SERVICE_IP=\`hostname -i\`
fi
echo
echo Environment Variables:
echo "SERVICE_IP=\$SERVICE_IP"
EOF
if [ $dirsrc != "common-services-msb" ]; then
cat >> $dir/docker-entrypoint.sh <<EOF
if [ -z "\$MSB_ADDR" ]; then
echo "Missing required variable MSB_ADDR: Microservices Service Bus address <ip>:<port>"
exit 1
fi
echo "MSB_ADDR=\$MSB_ADDR"
echo
# Wait for MSB initialization
echo Wait for MSB initialization
for i in {1..20}; do
curl -sS -m 1 \$MSB_ADDR > /dev/null && break
sleep \$i
done
EOF
fi
cat >> $dir/docker-entrypoint.sh <<EOF
echo
# Configure service based on docker environment variables
./instance-config.sh
EOF
if [ -f $dir/20-mysql.txt ]; then
cat >> $dir/docker-entrypoint.sh <<EOF
# Start mysql
su mysql -c /usr/bin/mysqld_safe &
EOF
fi
if [ -f $dir/25-mongodb.txt ]; then
cat >> $dir/docker-entrypoint.sh <<EOF
# Start mongodb
mongod &
EOF
fi
cat >> $dir/docker-entrypoint.sh <<EOF
# Perform one-time config
if [ ! -e init.log ]; then
# Perform workarounds due to defects in release binary
./instance-workaround.sh
EOF
if [ -f $dir/20-mysql.txt ]; then
cat >> $dir/docker-entrypoint.sh <<EOF
# Init mysql; set root password
./init-mysql.sh
EOF
fi
cat >> $dir/docker-entrypoint.sh <<EOF
# microservice-specific one-time initialization
./instance-init.sh
date > init.log
fi
# Start the microservice
./instance-run.sh
EOF
cat > $dir/Dockerfile <<EOF
#
# This file was auto-generated by gen-all-dockerfiles.sh; do not modify manually.
#
# $dir/Dockerfile
#
EOF
cat $dir/*.txt >> $dir/Dockerfile
for file in instance-config.sh instance-init.sh instance-run.sh instance-workaround.sh; do
if [ ! -f $dirsrc/$file ]; then
cp -n $ROOT/templates/instance-script.sh $dirsrc/$file
fi
done
cp -f $dirsrc/instance-*.sh $dir
touch $dir/instance-config.sh
touch $dir/instance-init.sh
touch $dir/instance-run.sh
touch $dir/instance-workaround.sh
chmod +x $dir/*.sh
cat > $dir/pom.xml <<EOF
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.openo.integration.docker</groupId>
<artifactId>${dirsrc}</artifactId>
<version>${VERSION}</version>
<packaging>docker</packaging>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.19.0</version>
<extensions>true</extensions>
<configuration>
<images>
<image>
<name>openoint/${dirsrc}</name>
<build>
<dockerFileDir>.</dockerFileDir>
<tags>
<tag>latest</tag>
</tags>
</build>
</image>
</images>
</configuration>
</plugin>
</plugins>
</build>
</project>
EOF
|