blob: 5cd926a985b495e0c1adc359f7e53df5557c8245 [file] [log] [blame]
Gary Wud04e4402017-07-28 12:26:54 -07001#!/bin/bash
2#
3# Copyright 2016-2017 Huawei Technologies Co., Ltd.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17# $1 dirsrc
18# $2 autorelease build
19
20set -e
21
22dirsrc=$1
23
24if [ -z "$2" ]; then
25 BUILD="snapshots"
26else
27 BUILD=$2
28fi
29
30VERSION="1.1.0-SNAPSHOT"
31
32# docker root dir
33ROOT=`git rev-parse --show-toplevel`/test/csit/docker
34
35cd $ROOT
36dir=$dirsrc/target
37mkdir -p $dir
38
39if [ "$BUILD" = "snapshots" ]; then
40 $ROOT/scripts/gen-dockerfiles.py $dirsrc
41else
42 $ROOT/scripts/gen-dockerfiles.py $dirsrc --build $BUILD
43fi
44
45# Update build number in workaround files
46for file in `find $dirsrc -name 80-workaround.txt`; do
47 sed -i "s|autorelease-[0-9]\{4\}|$BUILD|" $file
48done
49
50
51cp $ROOT/../../../distribution/LICENSE $dir
52cp -f $dirsrc/*.txt $dir 2>/dev/null || :
53
54if [ -f $dir/20-mysql.txt ]; then
55 cp $ROOT/templates/init-mysql.sh $dir/init-mysql.sh
56else
57 rm -f $dir/init-mysql.sh
58fi
59
60
61# empty 30-tomcat.txt would be created by gen-dockerfiles.py where required
62if [ -f $dir/30-tomcat.txt ]; then
63 TOMCAT_VERSION=`$ROOT/scripts/get-tomcat-version.sh`
64 cat > $dir/30-tomcat.txt <<EOF
65# 30-tomcat.txt - AUTOGENERATED, DO NOT MODIFY MANUALLY
66# Set up tomcat
67RUN 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
68RUN echo 'export CATALINA_OPTS="\$CATALINA_OPTS -Xms64m -Xmx256m -XX:MaxPermSize=64m"' > /service/bin/setenv.sh
69ENV CATALINA_HOME /service
70
71EOF
72fi
73
74
75
76cat > $dir/docker-entrypoint.sh <<EOF
77#!/bin/bash
78#
79# Copyright 2016-2017 Huawei Technologies Co., Ltd.
80#
81# Licensed under the Apache License, Version 2.0 (the "License");
82# you may not use this file except in compliance with the License.
83# You may obtain a copy of the License at
84#
85# http://www.apache.org/licenses/LICENSE-2.0
86#
87# Unless required by applicable law or agreed to in writing, software
88# distributed under the License is distributed on an "AS IS" BASIS,
89# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
90# See the License for the specific language governing permissions and
91# limitations under the License.
92#
93#
94# This file was auto-generated by gen-all-dockerfiles.sh; do not modify manually.
95#
96# $dir/docker-entrypoint.sh
97#
98
99if [ -z "\$SERVICE_IP" ]; then
100 export SERVICE_IP=\`hostname -i\`
101fi
102echo
103echo Environment Variables:
104echo "SERVICE_IP=\$SERVICE_IP"
105
106EOF
107
108if [ $dirsrc != "common-services-msb" ]; then
109 cat >> $dir/docker-entrypoint.sh <<EOF
110if [ -z "\$MSB_ADDR" ]; then
111 echo "Missing required variable MSB_ADDR: Microservices Service Bus address <ip>:<port>"
112 exit 1
113fi
114echo "MSB_ADDR=\$MSB_ADDR"
115echo
116
117# Wait for MSB initialization
118echo Wait for MSB initialization
119for i in {1..20}; do
120 curl -sS -m 1 \$MSB_ADDR > /dev/null && break
121 sleep \$i
122done
123
124EOF
125fi
126
127cat >> $dir/docker-entrypoint.sh <<EOF
128echo
129
130# Configure service based on docker environment variables
131./instance-config.sh
132
133EOF
134if [ -f $dir/20-mysql.txt ]; then
135 cat >> $dir/docker-entrypoint.sh <<EOF
136# Start mysql
137su mysql -c /usr/bin/mysqld_safe &
138
139EOF
140fi
141if [ -f $dir/25-mongodb.txt ]; then
142 cat >> $dir/docker-entrypoint.sh <<EOF
143# Start mongodb
144mongod &
145
146EOF
147fi
148cat >> $dir/docker-entrypoint.sh <<EOF
149# Perform one-time config
150if [ ! -e init.log ]; then
151 # Perform workarounds due to defects in release binary
152 ./instance-workaround.sh
153
154EOF
155if [ -f $dir/20-mysql.txt ]; then
156 cat >> $dir/docker-entrypoint.sh <<EOF
157 # Init mysql; set root password
158 ./init-mysql.sh
159
160EOF
161fi
162cat >> $dir/docker-entrypoint.sh <<EOF
163 # microservice-specific one-time initialization
164 ./instance-init.sh
165
166 date > init.log
167fi
168
169# Start the microservice
170./instance-run.sh
171
172EOF
173
174cat > $dir/Dockerfile <<EOF
175#
176# This file was auto-generated by gen-all-dockerfiles.sh; do not modify manually.
177#
178# $dir/Dockerfile
179#
180
181EOF
182
183cat $dir/*.txt >> $dir/Dockerfile
184
185for file in instance-config.sh instance-init.sh instance-run.sh instance-workaround.sh; do
186 if [ ! -f $dirsrc/$file ]; then
187 cp -n $ROOT/templates/instance-script.sh $dirsrc/$file
188 fi
189done
190
191cp -f $dirsrc/instance-*.sh $dir
192touch $dir/instance-config.sh
193touch $dir/instance-init.sh
194touch $dir/instance-run.sh
195touch $dir/instance-workaround.sh
196chmod +x $dir/*.sh
197
198
199cat > $dir/pom.xml <<EOF
200<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">
201 <modelVersion>4.0.0</modelVersion>
202 <groupId>org.openo.integration.docker</groupId>
203 <artifactId>${dirsrc}</artifactId>
204 <version>${VERSION}</version>
205 <packaging>docker</packaging>
206 <build>
207 <plugins>
208 <plugin>
209 <groupId>io.fabric8</groupId>
210 <artifactId>docker-maven-plugin</artifactId>
211 <version>0.19.0</version>
212 <extensions>true</extensions>
213 <configuration>
214 <images>
215 <image>
216 <name>openoint/${dirsrc}</name>
217 <build>
218 <dockerFileDir>.</dockerFileDir>
219 <tags>
220 <tag>latest</tag>
221 </tags>
222 </build>
223 </image>
224 </images>
225 </configuration>
226 </plugin>
227 </plugins>
228 </build>
229</project>
230EOF