[validation] Fix the slave-label
[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 STAGING_BUILD=${STAGING_BUILD:=''}
19 AUTOSTAGING=${AUTOSTAGING:=''}
20
21 set -e -u -x -o pipefail
22
23 echo '---> Starting build-docker'
24
25 if [ -f Dockerfile -a -x build-container.sh ]
26 then
27
28     # Let the project owner determine how the container is built.
29     bash ./build-container.sh
30
31 else
32
33     case "$PROJECT" in
34     portal_user_interface)
35         CON_NAME='akraino-portal'
36         if [ -n "$STAGING_BUILD" -a -n "$AUTOSTAGING" ]
37         then
38             # For a staging build, the $VERSION is fixed
39             VERSION=`xmlstarlet sel -N "x=http://maven.apache.org/POM/4.0.0" -t -v "/x:project/x:version" AECPortalMgmt/pom.xml`
40             VERSION=$(echo "$VERSION" | sed 's/-SNAPSHOT//')
41             WARFILE="${NEXUS_URL}/content/repositories/autostaging-${AUTOSTAGING}/org/akraino/${PROJECT}/${VERSION}/${PROJECT}-${VERSION}.war"
42             DOCKER_REPO='nexus3.akraino.org:10004'
43             curl -O "${WARFILE}"
44         else
45             # For a snapshot build - find the latest snapshot
46             VERSION=`xmlstarlet sel -N "x=http://maven.apache.org/POM/4.0.0" -t -v "/x:project/x:version" AECPortalMgmt/pom.xml`
47             XMLFILE="${NEXUS_URL}/service/local/repositories/snapshots/content/org/akraino/${PROJECT}/${VERSION}/maven-metadata.xml"
48             curl -O "${XMLFILE}"
49             V2=`grep value maven-metadata.xml | sed -e 's;</value>;;' -e 's;.*<value>;;' | uniq`
50             WARFILE="${NEXUS_URL}/service/local/repositories/snapshots/content/org/akraino/${PROJECT}/${VERSION}/${PROJECT}-${V2}.war"
51             curl -O "${WARFILE}"
52         fi
53
54         ln $(basename ${WARFILE}) AECPortalMgmt.war
55         (
56             echo 'FROM tomcat:8.5.31'
57             echo 'COPY AECPortalMgmt.war /usr/local/tomcat/webapps'
58         ) > Dockerfile
59         ;;
60
61     camunda_workflow)
62         CON_NAME='akraino-camunda-workflow-engine'
63         if [ -n "$STAGING_BUILD" -a -n "$AUTOSTAGING" ]
64         then
65             # For a staging build, the $VERSION is fixed
66             VERSION=`xmlstarlet sel -N "x=http://maven.apache.org/POM/4.0.0" -t -v "/x:project/x:version" akraino/pom.xml`
67             VERSION=$(echo "$VERSION" | sed 's/-SNAPSHOT//')
68             JARFILE="${NEXUS_URL}/content/repositories/autostaging-${AUTOSTAGING}/org/akraino/${PROJECT}/${VERSION}/${PROJECT}-${VERSION}.jar"
69             DOCKER_REPO='nexus3.akraino.org:10004'
70             curl -O "${JARFILE}"
71         else
72             # For a snapshot build - find the latest snapshot
73             VERSION=`xmlstarlet sel -N "x=http://maven.apache.org/POM/4.0.0" -t -v "/x:project/x:version" akraino/pom.xml`
74             XMLFILE="${NEXUS_URL}/service/local/repositories/snapshots/content/org/akraino/${PROJECT}/${VERSION}/maven-metadata.xml"
75             curl -O "${XMLFILE}"
76             V2=`grep value maven-metadata.xml | sed -e 's;</value>;;' -e 's;.*<value>;;' | uniq`
77             JARFILE="${NEXUS_URL}/service/local/repositories/snapshots/content/org/akraino/${PROJECT}/${VERSION}/${PROJECT}-${V2}.jar"
78             curl -O "${JARFILE}"
79         fi
80         ;;
81
82     postgres_db_schema)
83         CON_NAME='akraino_schema_db'
84         # Unfortunatly, there is another apt running in the background at this point, so this apt will always fail.
85         # E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
86         # Since it probably is not needed, I am just removing it.
87         # sudo apt install -y dos2unix
88         # dos2unix "${WORKSPACE}/version.properties"
89         source "$WORKSPACE/version.properties"
90
91         if [ -n "$STAGING_BUILD" -a -n "$AUTOSTAGING" ]
92         then
93             # For a staging build, the $VERSION is fixed
94             # Note: yaml_builds version MUST match the postgres_db_schema version
95             VERSION=$(echo "$VERSION" | sed 's/-SNAPSHOT//')
96             TGZFILE="${NEXUS_URL}/content/repositories/autostaging-${AUTOSTAGING}/yaml_builds-${VERSION}.tgz"
97             DOCKER_REPO='nexus3.akraino.org:10004'
98             curl -O "${TGZFILE}"
99        else
100             # For a snapshot build - find the latest snapshot
101             # Note: for some reason the project name is in the path twice for tar files
102             XMLFILE="${NEXUS_URL}/service/local/repositories/snapshots/content/org/akraino/yaml_builds/yaml_builds/${VERSION}/maven-metadata.xml"
103             curl -O "${XMLFILE}"
104             V2=`grep value maven-metadata.xml | sed -e 's;</value>;;' -e 's;.*<value>;;' | uniq`
105             TGZFILE="${NEXUS_URL}/service/local/repositories/snapshots/content/org/akraino/yaml_builds/yaml_builds/${VERSION}/yaml_builds-${V2}.tgz"
106             curl -O "${TGZFILE}"
107         fi
108         (mkdir yaml_builds; cd yaml_builds; tar xfv ../$(basename ${TGZFILE}))
109         mv yaml_builds/templates akraino-j2templates
110         ;;
111
112     *)
113         echo unknown project "$PROJECT"
114         exit 1
115         ;;
116     esac
117
118     # Append stream, if it is not the master stream
119     if [ "${STREAM}" != "master" ]
120     then
121         VERSION="${VERSION}-${STREAM}"
122     fi
123
124     # Build and push the Docker container
125     docker build -f Dockerfile -t ${CON_NAME}:${VERSION} .
126     docker tag ${CON_NAME}:${VERSION} ${DOCKER_REPO}/${CON_NAME}:${VERSION}
127     docker push ${DOCKER_REPO}/${CON_NAME}:${VERSION}
128
129 fi
130
131 set +u +x