Install redhat-rpm-config to ensure debuginfo packages
[git-tools-moved-to-github.git] / id-deb-build / docker-build.sh
index 5546b9f..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
             ;;
@@ -81,10 +81,37 @@ else
 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
@@ -113,49 +140,27 @@ if $upload; then
     exit 0
 fi
 
-if $centos; then
-    mkdir -p rpmbuild/BUILD
-    mkdir -p rpmbuild/BUILDROOT
-    mkdir -p rpmbuild/RPMS/noarch
-    mkdir -p rpmbuild/RPMS/x86_64
-    mkdir -p rpmbuild/SOURCES
-    mkdir -p rpmbuild/SPECS
-    mkdir -p rpmbuild/SRPMS
 
-    echo "%_topdir /home/mock/rpmbuild" >rpmbuild/rpmmacros
-    echo "%_source_filedigest_algorithm   0" >>rpmbuild/rpmmacros
-    echo "%_binary_filedigest_algorithm   0" >>rpmbuild/rpmmacros
-
-    cp ${ID_DEB_BUILD}/Dockerfile.mock rpmbuild
-    cp ${TAR} rpmbuild/SOURCES
-    SPEC=${PRODUCT}.spec
-    cat ${SPEC}|sed "s/%define idmetaversion.*/%define idmetaversion ${VERSION}/" >rpmbuild/SPECS/${SPEC}
-
-    if true; then
-       for dist in ${CENTOS_DIST}; do
-           case $dist in
-               centos5)
-                   r=epel-5-x86_64 ;;
-               centos6)
-                   r=epel-6-x86_64 ;;
-               centos7)
-                   r=epel-7-x86_64 ;;
-               *)
-                   r=$dist ;;
-           esac
-           echo -n "$r"
-
-           rm -f rpmbuild/run.sh
-           echo '#!/bin/sh' >rpmbuild/run.sh
-           echo "rpmbuild -bs rpmbuild/SPECS/${SPEC}" >>rpmbuild/run.sh
-           echo "/usr/bin/mock --resultdir=rpmbuild -r $r rpmbuild/SRPMS/${PRODUCT}-${VERSION}*src.rpm" >>rpmbuild/run.sh
+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
 
-           docker build -t indexdata-fedora-mock -f rpmbuild/Dockerfile.mock .
-           docker run --privileged -it --rm indexdata-fedora-mock rpmbuild/run.sh
-           echo "done"
-       done
-    fi
 fi
+
 if $debian; then
     MKDEBSRC=${ID_DEB_BUILD}/id-mk-deb-src.sh
     if test ! -x $MKDEBSRC; then
@@ -183,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
@@ -197,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: