Gary Wu | d04e440 | 2017-07-28 12:26:54 -0700 | [diff] [blame] | 1 | #!/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 | |
| 20 | set -e |
| 21 | |
| 22 | dirsrc=$1 |
| 23 | |
| 24 | if [ -z "$2" ]; then |
| 25 | BUILD="snapshots" |
| 26 | else |
| 27 | BUILD=$2 |
| 28 | fi |
| 29 | |
| 30 | VERSION="1.1.0-SNAPSHOT" |
| 31 | |
| 32 | # docker root dir |
| 33 | ROOT=`git rev-parse --show-toplevel`/test/csit/docker |
| 34 | |
| 35 | cd $ROOT |
| 36 | dir=$dirsrc/target |
| 37 | mkdir -p $dir |
| 38 | |
| 39 | if [ "$BUILD" = "snapshots" ]; then |
| 40 | $ROOT/scripts/gen-dockerfiles.py $dirsrc |
| 41 | else |
| 42 | $ROOT/scripts/gen-dockerfiles.py $dirsrc --build $BUILD |
| 43 | fi |
| 44 | |
| 45 | # Update build number in workaround files |
| 46 | for file in `find $dirsrc -name 80-workaround.txt`; do |
| 47 | sed -i "s|autorelease-[0-9]\{4\}|$BUILD|" $file |
| 48 | done |
| 49 | |
| 50 | |
| 51 | cp $ROOT/../../../distribution/LICENSE $dir |
| 52 | cp -f $dirsrc/*.txt $dir 2>/dev/null || : |
| 53 | |
| 54 | if [ -f $dir/20-mysql.txt ]; then |
| 55 | cp $ROOT/templates/init-mysql.sh $dir/init-mysql.sh |
| 56 | else |
| 57 | rm -f $dir/init-mysql.sh |
| 58 | fi |
| 59 | |
| 60 | |
| 61 | # empty 30-tomcat.txt would be created by gen-dockerfiles.py where required |
| 62 | if [ -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 |
| 67 | 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 |
| 68 | RUN echo 'export CATALINA_OPTS="\$CATALINA_OPTS -Xms64m -Xmx256m -XX:MaxPermSize=64m"' > /service/bin/setenv.sh |
| 69 | ENV CATALINA_HOME /service |
| 70 | |
| 71 | EOF |
| 72 | fi |
| 73 | |
| 74 | |
| 75 | |
| 76 | cat > $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 | |
| 99 | if [ -z "\$SERVICE_IP" ]; then |
| 100 | export SERVICE_IP=\`hostname -i\` |
| 101 | fi |
| 102 | echo |
| 103 | echo Environment Variables: |
| 104 | echo "SERVICE_IP=\$SERVICE_IP" |
| 105 | |
| 106 | EOF |
| 107 | |
| 108 | if [ $dirsrc != "common-services-msb" ]; then |
| 109 | cat >> $dir/docker-entrypoint.sh <<EOF |
| 110 | if [ -z "\$MSB_ADDR" ]; then |
| 111 | echo "Missing required variable MSB_ADDR: Microservices Service Bus address <ip>:<port>" |
| 112 | exit 1 |
| 113 | fi |
| 114 | echo "MSB_ADDR=\$MSB_ADDR" |
| 115 | echo |
| 116 | |
| 117 | # Wait for MSB initialization |
| 118 | echo Wait for MSB initialization |
| 119 | for i in {1..20}; do |
| 120 | curl -sS -m 1 \$MSB_ADDR > /dev/null && break |
| 121 | sleep \$i |
| 122 | done |
| 123 | |
| 124 | EOF |
| 125 | fi |
| 126 | |
| 127 | cat >> $dir/docker-entrypoint.sh <<EOF |
| 128 | echo |
| 129 | |
| 130 | # Configure service based on docker environment variables |
| 131 | ./instance-config.sh |
| 132 | |
| 133 | EOF |
| 134 | if [ -f $dir/20-mysql.txt ]; then |
| 135 | cat >> $dir/docker-entrypoint.sh <<EOF |
| 136 | # Start mysql |
| 137 | su mysql -c /usr/bin/mysqld_safe & |
| 138 | |
| 139 | EOF |
| 140 | fi |
| 141 | if [ -f $dir/25-mongodb.txt ]; then |
| 142 | cat >> $dir/docker-entrypoint.sh <<EOF |
| 143 | # Start mongodb |
| 144 | mongod & |
| 145 | |
| 146 | EOF |
| 147 | fi |
| 148 | cat >> $dir/docker-entrypoint.sh <<EOF |
| 149 | # Perform one-time config |
| 150 | if [ ! -e init.log ]; then |
| 151 | # Perform workarounds due to defects in release binary |
| 152 | ./instance-workaround.sh |
| 153 | |
| 154 | EOF |
| 155 | if [ -f $dir/20-mysql.txt ]; then |
| 156 | cat >> $dir/docker-entrypoint.sh <<EOF |
| 157 | # Init mysql; set root password |
| 158 | ./init-mysql.sh |
| 159 | |
| 160 | EOF |
| 161 | fi |
| 162 | cat >> $dir/docker-entrypoint.sh <<EOF |
| 163 | # microservice-specific one-time initialization |
| 164 | ./instance-init.sh |
| 165 | |
| 166 | date > init.log |
| 167 | fi |
| 168 | |
| 169 | # Start the microservice |
| 170 | ./instance-run.sh |
| 171 | |
| 172 | EOF |
| 173 | |
| 174 | cat > $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 | |
| 181 | EOF |
| 182 | |
| 183 | cat $dir/*.txt >> $dir/Dockerfile |
| 184 | |
| 185 | for 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 |
| 189 | done |
| 190 | |
| 191 | cp -f $dirsrc/instance-*.sh $dir |
| 192 | touch $dir/instance-config.sh |
| 193 | touch $dir/instance-init.sh |
| 194 | touch $dir/instance-run.sh |
| 195 | touch $dir/instance-workaround.sh |
| 196 | chmod +x $dir/*.sh |
| 197 | |
| 198 | |
| 199 | cat > $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> |
| 230 | EOF |