Let user determine how the container is built
[ci-management.git] / jjb / shell / build-docker.sh
1 #!/bin/bash
2 #
3 # Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
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 DOCKER_REPO='nexus3.akraino.org:10003'
18
19 set -e -u -x -o pipefail
20
21 echo '---> Starting build-docker'
22
23 if [ -f Dockerfile -a -x build-container.sh ]
24 then
25
26     # Let the project owner determine how the container is built.
27     bash ./build-container.sh
28
29 else
30
31     case "$PROJECT" in
32     portal_user_interface)
33         CON_NAME='akraino-portal'
34         VERSION=`xmlstarlet sel -N "x=http://maven.apache.org/POM/4.0.0" -t -v "/x:project/x:version" AECPortalMgmt/pom.xml`
35
36         XMLFILE="${NEXUS_URL}/service/local/repositories/snapshots/content/org/akraino/${PROJECT}/${VERSION}/maven-metadata.xml"
37         curl -O "${XMLFILE}"
38         V2=`grep value maven-metadata.xml | sed -e 's;</value>;;' -e 's;.*<value>;;' | uniq`
39         WARFILE="${NEXUS_URL}/service/local/repositories/snapshots/content/org/akraino/${PROJECT}/${VERSION}/${PROJECT}-${V2}.war"
40         curl -O "${WARFILE}"
41
42         ln $(basename ${WARFILE}) AECPortalMgmt.war
43         (
44             echo 'FROM tomcat:8.5.31'
45             echo 'COPY AECPortalMgmt.war /usr/local/tomcat/webapps'
46         ) > Dockerfile
47         ;;
48
49     camunda_workflow)
50         CON_NAME='akraino-camunda-workflow-engine'
51         VERSION=`xmlstarlet sel -N "x=http://maven.apache.org/POM/4.0.0" -t -v "/x:project/x:version" akraino/pom.xml`
52
53         XMLFILE="${NEXUS_URL}/service/local/repositories/snapshots/content/org/akraino/${PROJECT}/${VERSION}/maven-metadata.xml"
54         curl -O "${XMLFILE}"
55         V2=`grep value maven-metadata.xml | sed -e 's;</value>;;' -e 's;.*<value>;;' | uniq`
56         JARFILE="${NEXUS_URL}/service/local/repositories/snapshots/content/org/akraino/${PROJECT}/${VERSION}/${PROJECT}-${V2}.jar"
57         curl -O ${JARFILE}
58         ;;
59
60     postgres_db_schema)
61         CON_NAME='akraino_schema_db'
62         source $WORKSPACE/version.properties
63
64         # Note: for some reason the project name is in the path twice for tar files
65         XMLFILE="${NEXUS_URL}/service/local/repositories/snapshots/content/org/akraino/yaml_builds/yaml_builds/${VERSION}/maven-metadata.xml"
66         curl -O "${XMLFILE}"
67         V2=`grep value maven-metadata.xml | sed -e 's;</value>;;' -e 's;.*<value>;;' | uniq`
68         TGZFILE="${NEXUS_URL}/service/local/repositories/snapshots/content/org/akraino/yaml_builds/yaml_builds/${VERSION}/yaml_builds-${V2}.tgz"
69         curl -O "${TGZFILE}"
70         (mkdir yaml_builds; cd yaml_builds; tar xfv ../$(basename ${TGZFILE}))
71         mv yaml_builds/templates akraino-j2templates
72         ;;
73
74     *)
75         echo unknown project "$PROJECT"
76         exit 1
77         ;;
78     esac
79
80     # Append stream, if it is not the master stream
81     if [ "${STREAM}" != "master" ]
82     then
83         VERSION="${VERSION}-${STREAM}"
84     fi
85
86     # Build and push the Docker container
87     docker build -f Dockerfile -t ${CON_NAME}:${VERSION} .
88     docker tag ${CON_NAME}:${VERSION} ${DOCKER_REPO}/${CON_NAME}:${VERSION}
89     docker push ${DOCKER_REPO}/${CON_NAME}:${VERSION}
90
91 fi
92
93 set +u +x