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