Revert "Add signing to Akraino deploy templates"
[ci-management.git] / jjb / shell / build-docker.sh
index db0c177..d745af6 100644 (file)
 # limitations under the License.
 
 DOCKER_REPO='nexus3.akraino.org:10003'
+STAGING_BUILD=${STAGING_BUILD:=''}
+AUTOSTAGING=${AUTOSTAGING:=''}
 
 set -e -u -x -o pipefail
 
 echo '---> Starting build-docker'
 
-case "$PROJECT" in
-portal_user_interface)
-    CON_NAME='akraino-portal'
-    VERSION=`xmlstarlet sel -N "x=http://maven.apache.org/POM/4.0.0" -t -v "/x:project/x:version" AECPortalMgmt/pom.xml`
-    WARFILE="https://nexus.akraino.org/repository/maven-snapshots/org/akraino/portal/portal/${VERSION}/portal-${VERSION}.war"
-    curl -O ${WARFILE}
-    ln $(basename ${WARFILE}) AECPortalMgmt.war
-
-    (
-        echo 'FROM tomcat:8.5.31'
-        echo 'COPY AECPortalMgmt.war /usr/local/tomcat/webapps'
-    ) > Dockerfile
-    ;;
-
-camunda_workflow)
-    CON_NAME='akraino-camunda-workflow-engine'
-    VERSION=`xmlstarlet sel -N "x=http://maven.apache.org/POM/4.0.0" -t -v "/x:project/x:version" akraino/pom.xml`
-    JARFILE="https://nexus.akraino.org/repository/maven-snapshots/org/akraino/camunda_workflow/${VERSION}/camunda_workflow-${VERSION}.jar"
-    curl -O ${JARFILE}
-    ;;
-
-postgres_db_schema)
-    CON_NAME='akraino_schema_db'
-    source $WORKSPACE/version.properties
-    TARFILE="https://nexus.akraino.org/repository/maven-snapshots/org/akraino/yaml_builds/${VERSION}/yaml_builds-${VERSION}.tgz"
-    curl -O ${TARFILE}
-    (mkdir yaml_builds; cd yaml_builds; tar xfv ../$(basename ${TARFILE}))
-    mv yaml_builds/templates akraino-j2templates
-    ;;
-
-*)
-    echo unknown project "$PROJECT"
-    exit 1
-    ;;
-esac
-
-# Build and push the Docker container
-docker build -f Dockerfile -t ${CON_NAME}:${VERSION} .
-docker tag ${CON_NAME}:${VERSION} ${DOCKER_REPO}/${CON_NAME}:${VERSION}
-docker push ${DOCKER_REPO}/${CON_NAME}:${VERSION}
+if [ -f Dockerfile -a -x build-container.sh ]
+then
+
+    # Let the project owner determine how the container is built.
+    bash ./build-container.sh
+
+else
+
+    case "$PROJECT" in
+    portal_user_interface)
+        CON_NAME='akraino-portal'
+        if [ -n "$STAGING_BUILD" -a -n "$AUTOSTAGING" ]
+        then
+            # For a staging build, the $VERSION is fixed
+            VERSION=`xmlstarlet sel -N "x=http://maven.apache.org/POM/4.0.0" -t -v "/x:project/x:version" AECPortalMgmt/pom.xml`
+            VERSION=$(echo "$VERSION" | sed 's/-SNAPSHOT//')
+            WARFILE="${NEXUS_URL}/content/repositories/autostaging-${AUTOSTAGING}/org/akraino/${PROJECT}/${VERSION}/${PROJECT}-${VERSION}.war"
+            DOCKER_REPO='nexus3.akraino.org:10004'
+            curl -O "${WARFILE}"
+        else
+            # For a snapshot build - find the latest snapshot
+            VERSION=`xmlstarlet sel -N "x=http://maven.apache.org/POM/4.0.0" -t -v "/x:project/x:version" AECPortalMgmt/pom.xml`
+            XMLFILE="${NEXUS_URL}/service/local/repositories/snapshots/content/org/akraino/${PROJECT}/${VERSION}/maven-metadata.xml"
+            curl -O "${XMLFILE}"
+            V2=`grep value maven-metadata.xml | sed -e 's;</value>;;' -e 's;.*<value>;;' | uniq`
+            WARFILE="${NEXUS_URL}/service/local/repositories/snapshots/content/org/akraino/${PROJECT}/${VERSION}/${PROJECT}-${V2}.war"
+            curl -O "${WARFILE}"
+        fi
+
+        ln $(basename ${WARFILE}) AECPortalMgmt.war
+        (
+            echo 'FROM tomcat:8.5.31'
+            echo 'COPY AECPortalMgmt.war /usr/local/tomcat/webapps'
+        ) > Dockerfile
+        ;;
+
+    camunda_workflow)
+        CON_NAME='akraino-camunda-workflow-engine'
+        if [ -n "$STAGING_BUILD" -a -n "$AUTOSTAGING" ]
+        then
+            # For a staging build, the $VERSION is fixed
+            VERSION=`xmlstarlet sel -N "x=http://maven.apache.org/POM/4.0.0" -t -v "/x:project/x:version" akraino/pom.xml`
+            VERSION=$(echo "$VERSION" | sed 's/-SNAPSHOT//')
+            JARFILE="${NEXUS_URL}/content/repositories/autostaging-${AUTOSTAGING}/org/akraino/${PROJECT}/${VERSION}/${PROJECT}-${VERSION}.jar"
+            DOCKER_REPO='nexus3.akraino.org:10004'
+            curl -O "${JARFILE}"
+        else
+            # For a snapshot build - find the latest snapshot
+            VERSION=`xmlstarlet sel -N "x=http://maven.apache.org/POM/4.0.0" -t -v "/x:project/x:version" akraino/pom.xml`
+            XMLFILE="${NEXUS_URL}/service/local/repositories/snapshots/content/org/akraino/${PROJECT}/${VERSION}/maven-metadata.xml"
+            curl -O "${XMLFILE}"
+            V2=`grep value maven-metadata.xml | sed -e 's;</value>;;' -e 's;.*<value>;;' | uniq`
+            JARFILE="${NEXUS_URL}/service/local/repositories/snapshots/content/org/akraino/${PROJECT}/${VERSION}/${PROJECT}-${V2}.jar"
+            curl -O "${JARFILE}"
+        fi
+        ;;
+
+    postgres_db_schema)
+        CON_NAME='akraino_schema_db'
+        # Unfortunatly, there is another apt running in the background at this point, so this apt will always fail.
+        # E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
+        # Since it probably is not needed, I am just removing it.
+        # sudo apt install -y dos2unix
+        # dos2unix "${WORKSPACE}/version.properties"
+        source "$WORKSPACE/version.properties"
+
+        if [ -n "$STAGING_BUILD" -a -n "$AUTOSTAGING" ]
+        then
+            # For a staging build, the $VERSION is fixed
+            # Note: yaml_builds version MUST match the postgres_db_schema version
+            VERSION=$(echo "$VERSION" | sed 's/-SNAPSHOT//')
+            TGZFILE="${NEXUS_URL}/content/repositories/autostaging-${AUTOSTAGING}/yaml_builds-${VERSION}.tgz"
+            DOCKER_REPO='nexus3.akraino.org:10004'
+            curl -O "${TGZFILE}"
+       else
+            # For a snapshot build - find the latest snapshot
+            # Note: for some reason the project name is in the path twice for tar files
+            XMLFILE="${NEXUS_URL}/service/local/repositories/snapshots/content/org/akraino/yaml_builds/yaml_builds/${VERSION}/maven-metadata.xml"
+            curl -O "${XMLFILE}"
+            V2=`grep value maven-metadata.xml | sed -e 's;</value>;;' -e 's;.*<value>;;' | uniq`
+            TGZFILE="${NEXUS_URL}/service/local/repositories/snapshots/content/org/akraino/yaml_builds/yaml_builds/${VERSION}/yaml_builds-${V2}.tgz"
+            curl -O "${TGZFILE}"
+        fi
+        (mkdir yaml_builds; cd yaml_builds; tar xfv ../$(basename ${TGZFILE}))
+        mv yaml_builds/templates akraino-j2templates
+        ;;
+
+    *)
+        echo unknown project "$PROJECT"
+        exit 1
+        ;;
+    esac
+
+    # Append stream, if it is not the master stream
+    if [ "${STREAM}" != "master" ]
+    then
+        VERSION="${VERSION}-${STREAM}"
+    fi
+
+    # Build and push the Docker container
+    docker build -f Dockerfile -t ${CON_NAME}:${VERSION} .
+    docker tag ${CON_NAME}:${VERSION} ${DOCKER_REPO}/${CON_NAME}:${VERSION}
+    docker push ${DOCKER_REPO}/${CON_NAME}:${VERSION}
+
+fi
 
 set +u +x