Install redhat-rpm-config to ensure debuginfo packages
[git-tools-moved-to-github.git] / id-deb-build / docker-build.sh
index ad8a797..4a03468 100755 (executable)
@@ -6,11 +6,11 @@ Usage: docker-build.sh [OPTIONS]
 Options:
         [--debian=distros]
         [--ubuntu=distros]
+        [--verbose]
         [--upload]
 EOF
     exit $1
 }
-set -x
 D0=`dirname $0`
 ID_DEB_BUILD=`cd $D0; pwd`
 
@@ -32,12 +32,12 @@ while test $# -gt 0; do
         --centos=*)
             CENTOS_DIST_A=$optarg
             ;;
-        --concurrency=*)
-            concurrency=$optarg
-            ;;
         --upload)
             upload=true
             ;;
+        --verbose)
+           set -x
+            ;;
         -*)
             do_help=yes
             ;;
@@ -57,8 +57,12 @@ if test "$DEBIAN_DIST_A" -o "$UBUNTU_DIST_A" -o "$CENTOS_DIST_A"; then
 fi
 
 if test "$CENTOS_DIST"; then
-    echo "CentOS not yet supported"
-    exit 1
+    RNAME=`awk '/Name:/ {print $2}' *.spec`
+    if test "$NAME" -a "$NAME" != "$RNAME"; then
+       echo "NAME in IDMETA ($NAME) does not match RPM spec NAME ($RNAME)"
+       exit 1
+    fi
+    PRODUCT=$RNAME
     centos=true
 else
     centos=false
@@ -76,9 +80,38 @@ else
     debian=false
 fi
 
+TAR=${PRODUCT}-${VERSION}.tar.gz
+if test ! -f "$TAR"; then
+    echo "tar $TAR missing"
+    exit 1
+fi
+
 if $upload; then
     UPLOAD_URI=${UPLOAD_HOST}:${UPLOAD_PATH}/${PRODUCT}
     echo "Uploading to ${UPLOAD_URI}"
+    if $centos; then
+       for dist in ${CENTOS_DIST}; do
+           case $dist in
+               centos5)
+                   F=5.5;;
+               centos6)
+                   F=6;;
+               centos7)
+                   F=7;;
+               *)
+                   echo "$dist not supported"
+                   exit 1
+           esac
+           ssh ${UPLOAD_HOST} "mkdir -p ${UPLOAD_PATH}/${PRODUCT}/redhat/centos/$F/RPMS"
+           ssh ${UPLOAD_HOST} "mkdir -p ${UPLOAD_PATH}/${PRODUCT}/redhat/centos/$F/SRPMS"
+           scp -r build/centos/$dist/rpmbuild/RPMS ${UPLOAD_URI}/redhat/centos/$F
+           scp -r build/centos/$dist/rpmbuild/SRPMS ${UPLOAD_URI}/redhat/centos/$F
+       done
+       if ! ssh ${UPLOAD_HOST} "sudo -n /home/indexdata/proj/git-tools/update-archive/update-yum-archive.sh" >yum-update.log 2>&1; then
+           echo "update-yum-archive.sh failed; inspect yum-update.log"
+           exit 1
+       fi
+    fi
     if $debian; then
        if test -n "${DEBIAN_DIST}"; then
            for dist in ${DEBIAN_DIST}; do
@@ -107,6 +140,27 @@ if $upload; then
     exit 0
 fi
 
+
+if $centos; then
+    for dist in ${CENTOS_DIST}; do
+       test -d build/centos/$dist && sudo rm -fr build/centos/$dist
+       mkdir -p build/centos/$dist/rpmbuild
+       mkdir -p build/centos/$dist/rpmbuild/BUILD
+       mkdir -p build/centos/$dist/rpmbuild/BUILDROOT
+       mkdir -p build/centos/$dist/rpmbuild/RPMS/noarch
+       mkdir -p build/centos/$dist/rpmbuild/RPMS/x86_64
+       mkdir -p build/centos/$dist/rpmbuild/SOURCES
+       mkdir -p build/centos/$dist/rpmbuild/SPECS
+       mkdir -p build/centos/$dist/rpmbuild/SRPMS
+       cp ${TAR} build/centos/$dist/rpmbuild/SOURCES
+       SPEC=${PRODUCT}.spec
+       cp ${SPEC} build/centos/$dist/rpmbuild/SPECS
+       cp IDMETA build/centos/$dist/rpmbuild
+       cp ${ID_DEB_BUILD}/in-docker-rpm.sh build/centos/$dist
+    done
+
+fi
+
 if $debian; then
     MKDEBSRC=${ID_DEB_BUILD}/id-mk-deb-src.sh
     if test ! -x $MKDEBSRC; then
@@ -134,7 +188,7 @@ if $debian; then
 
     if test "${DEBIAN_DIST}"; then
        for dist in ${DEBIAN_DIST}; do
-           sudo rm -fr build/debian/$dist
+           test -f build/debian/$dist && sudo rm -fr build/debian/$dist
            mkdir -p build/debian
            cp -a deb-src build/debian/$dist
            cp ${ID_DEB_BUILD}/in-docker.sh build/debian/$dist
@@ -148,20 +202,80 @@ if $debian; then
            cp ${ID_DEB_BUILD}/in-docker.sh build/ubuntu/$dist
        done
     fi
-    if test "${DEBIAN_DIST}"; then
-       for dist in ${DEBIAN_DIST}; do
-           cd build/debian/$dist
-           docker run -it --rm  -v "$PWD:/build" -w /build/$PRODUCT-$VERSION debian:$dist ../in-docker.sh debian $dist
-           cd ../../..
-       done
-    fi
-    if test "${UBUNTU_DIST}"; then
-       for dist in ${UBUNTU_DIST}; do
-           cd build/ubuntu/$dist
-           docker run -it --rm  -v "$PWD:/build" -w /build/$PRODUCT-$VERSION ubuntu:$dist ../in-docker.sh ubuntu $dist
-           cd ../../..
-       done
-    fi
+fi
+
+if test "${CENTOS_DIST}"; then
+    for dist in ${CENTOS_DIST}; do
+       case $dist in
+           centos5)
+               F=5.5
+               D=5;;
+           centos6)
+               F=6
+               D=6;;
+           centos7)
+               F=7
+               D=7;;
+           *)
+               echo "$dist not supported"
+               exit 1
+       esac
+       cd build/centos/$dist
+
+       echo "FROM centos:$D" >Dockerfile
+       echo "RUN yum install -y wget yum-utils redhat-rpm-config rpm-build gcc gcc-c++ make" >>Dockerfile
+       echo "RUN rpm --import http://ftp.indexdata.com/pub/yum/centos/$F/RPM-GPG-KEY-indexdata" >>Dockerfile
+       echo "RUN wget http://ftp.indexdata.com/pub/yum/centos/$F/indexdata.repo -P /etc/yum.repos.d/" >>Dockerfile
+       echo 'ENTRYPOINT ["/bin/sh", "-c"]' >>Dockerfile
+       docker build -t indexdata-build-centos-$D .
+       echo -n "$dist "
+       docker run --rm  -v "$PWD:/build" -w /build/rpmbuild indexdata-build-centos-$D ../in-docker-rpm.sh >log 2>&1
+       if test $? -eq 0; then
+               echo Done
+       else
+               echo "Fail. Inspect build/centos/$dist/log"
+               exit 1
+       fi
+       cd ../../..
+    done
+fi
+if test "${DEBIAN_DIST}"; then
+    for dist in ${DEBIAN_DIST}; do
+       cd build/debian/$dist
+       echo "FROM debian:$dist" >Dockerfile
+       echo 'RUN apt-get update && apt-get -q install -y wget devscripts equivs' >>Dockerfile
+       echo 'RUN wget -q -O - http://ftp.indexdata.dk/debian/indexdata.asc|apt-key add -' >>Dockerfile
+       echo "RUN echo \"deb http://ftp.indexdata.dk/debian $dist main\" >/etc/apt/sources.list.d/indexdata.list" >>Dockerfile
+       docker build -t indexdata-build-debian-$dist .
+       echo -n "Debian $dist "
+       docker run --rm  -v "$PWD:/build" -w /build/$PRODUCT-$VERSION indexdata-build-debian-$dist ../in-docker.sh >log 2>&1
+       if test $? -eq 0; then
+               echo Done
+       else
+               echo "Fail. Inspect build/debian/$dist/log"
+               exit 1
+       fi
+       cd ../../..
+    done
+fi
+if test "${UBUNTU_DIST}"; then
+    for dist in ${UBUNTU_DIST}; do
+       cd build/ubuntu/$dist
+       echo "FROM ubuntu:$dist" >Dockerfile
+       echo 'RUN apt-get update && apt-get -q install -y wget devscripts equivs' >>Dockerfile
+       echo 'RUN wget -q -O - http://ftp.indexdata.dk/debian/indexdata.asc|apt-key add -' >>Dockerfile
+       echo "RUN echo \"deb http://ftp.indexdata.dk/ubuntu $dist main\" >/etc/apt/sources.list.d/indexdata.list" >>Dockerfile
+       docker build -t indexdata-build-ubuntu-$dist .
+       echo -n "Ubuntu $dist "
+       docker run --rm  -v "$PWD:/build" -w /build/$PRODUCT-$VERSION indexdata-build-ubuntu-$dist ../in-docker.sh >log 2>&1
+       if test $? -eq 0; then
+               echo Done
+       else
+               echo "Fail. Inspect build/ubuntu/$dist/log"
+               exit 1
+       fi
+       cd ../../..
+    done
 fi
 
 # Local Variables: