Create debs with Docker
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 10 Oct 2016 13:24:06 +0000 (15:24 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 10 Oct 2016 13:24:06 +0000 (15:24 +0200)
id-deb-build/docker-build.sh [new file with mode: 0755]
id-deb-build/in-docker.sh [new file with mode: 0755]

diff --git a/id-deb-build/docker-build.sh b/id-deb-build/docker-build.sh
new file mode 100755 (executable)
index 0000000..ad8a797
--- /dev/null
@@ -0,0 +1,172 @@
+#!/bin/sh
+usage()
+{
+    cat <<EOF
+Usage: docker-build.sh [OPTIONS]
+Options:
+        [--debian=distros]
+        [--ubuntu=distros]
+        [--upload]
+EOF
+    exit $1
+}
+set -x
+D0=`dirname $0`
+ID_DEB_BUILD=`cd $D0; pwd`
+
+UPLOAD_HOST=${UPLOAD_HOST:=ftp.indexdata.dk}
+UPLOAD_PATH=${UPLOAD_PATH:=/home/ftp/pub}
+upload=false
+while test $# -gt 0; do
+    case "$1" in
+        -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
+        *) optarg= ;;
+    esac
+    case $1 in
+        --debian=*)
+            DEBIAN_DIST_A=$optarg
+            ;;
+        --ubuntu=*)
+            UBUNTU_DIST_A=$optarg
+            ;;
+        --centos=*)
+            CENTOS_DIST_A=$optarg
+            ;;
+        --concurrency=*)
+            concurrency=$optarg
+            ;;
+        --upload)
+            upload=true
+            ;;
+        -*)
+            do_help=yes
+            ;;
+    esac
+    shift
+done
+if test -f IDMETA;  then
+    . ./IDMETA
+else
+    echo "IDMETA missing"
+    exit 1
+fi
+if test "$DEBIAN_DIST_A" -o "$UBUNTU_DIST_A" -o "$CENTOS_DIST_A"; then
+    DEBIAN_DIST=$DEBIAN_DIST_A
+    UBUNTU_DIST=$UBUNTU_DIST_A
+    CENTOS_DIST=$CENTOS_DIST_A
+fi
+
+if test "$CENTOS_DIST"; then
+    echo "CentOS not yet supported"
+    exit 1
+    centos=true
+else
+    centos=false
+fi
+
+if test "$DEBIAN_DIST" -o "$UBUNTU_DIST"; then
+    debian=true
+    DNAME=`awk '/Source:/ {print $2}' debian/control`
+    if test "$NAME" -a "$NAME" != "$DNAME"; then
+        echo "NAME in IDMETA ($NAME) does not match debian/control ($DNAME)"
+        exit 1
+    fi
+    PRODUCT=$DNAME
+else
+    debian=false
+fi
+
+if $upload; then
+    UPLOAD_URI=${UPLOAD_HOST}:${UPLOAD_PATH}/${PRODUCT}
+    echo "Uploading to ${UPLOAD_URI}"
+    if $debian; then
+       if test -n "${DEBIAN_DIST}"; then
+           for dist in ${DEBIAN_DIST}; do
+               ssh ${UPLOAD_HOST} "mkdir -p ${UPLOAD_PATH}/${PRODUCT}/debian/${dist}"
+               if ! scp build/debian/${dist}/* ${UPLOAD_URI}/debian/${dist}; then
+                   echo "Upload failed for $dist"
+                   exit 1
+               fi
+           done
+       fi
+       if test -n "${UBUNTU_DIST}"; then
+           for dist in ${UBUNTU_DIST}; do
+               ssh ${UPLOAD_HOST} "mkdir -p ${UPLOAD_PATH}/${PRODUCT}/ubuntu/${dist}"
+               if ! scp build/ubuntu/${dist}/* ${UPLOAD_URI}/ubuntu/${dist}; then
+                   echo "Upload failed for $dist"
+                   exit 1
+               fi
+           done
+       fi
+       if ! ssh ${UPLOAD_HOST} "sudo -n /home/indexdata/proj/git-tools/update-archive/update-archive.sh --ubuntu=\"${UBUNTU_DIST}\" --debian=\"${DEBIAN_DIST}\""; then
+           echo "update-archive.sh failed"
+           exit 1
+       fi
+    fi
+    echo "Upload successful - we hope"
+    exit 0
+fi
+
+if $debian; then
+    MKDEBSRC=${ID_DEB_BUILD}/id-mk-deb-src.sh
+    if test ! -x $MKDEBSRC; then
+        echo "$MKDEBSRC not found"
+        exit 1
+    fi
+    cp ${ID_DEB_BUILD}/in-docker.sh .
+    if ! ${ID_DEB_BUILD}/id-mk-deb-changelog.sh; then
+        echo "id-mk-deb-changelog.sh failed"
+    fi
+    if ! ${MKDEBSRC}; then
+        echo "id-mk-deb-src.sh failed"
+    fi
+    cd deb-src
+    for f in *.dsc; do
+        if test -f "$f"; then
+            DSC=$f
+        fi
+    done
+    cd ..
+    if test -z "$DSC"; then
+        echo "${DSC} does not exist"
+        exit 1
+    fi
+
+    if test "${DEBIAN_DIST}"; then
+       for dist in ${DEBIAN_DIST}; do
+           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
+       done
+    fi
+    if test "${UBUNTU_DIST}"; then
+       for dist in ${UBUNTU_DIST}; do
+           sudo rm -fr build/ubuntu/$dist
+           mkdir -p build/ubuntu
+           cp -a deb-src build/ubuntu/$dist
+           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
+
+# Local Variables:
+# mode:shell-script
+# sh-indentation: 4
+# sh-basic-offset: 4
+# End:
+
diff --git a/id-deb-build/in-docker.sh b/id-deb-build/in-docker.sh
new file mode 100755 (executable)
index 0000000..0aa867c
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/sh
+# in-docker.sh
+# Build Debian package in Docker. Use steps like this:
+#  make dist
+#  ../git-tools/id-deb-build/id-mk-deb-src.sh
+
+#  docker run -it --rm -v "$PWD:/build" -w /build/product-version debian:jessie ./in-docker.sh
+#
+
+set -x
+OS=$1
+DIST=$2
+DEBIAN_FRONTEND=noninteractive
+export DEBIAN_FRONTEND
+
+apt-get update && apt-get install -y wget devscripts equivs
+wget -q -O - http://ftp.indexdata.dk/debian/indexdata.asc|apt-key add -
+echo "deb http://ftp.indexdata.dk/${OS} ${DIST} main" >/etc/apt/sources.list.d/indexdata.list
+apt-get update
+
+mk-build-deps
+dpkg -i *-build-deps_*_all.deb || apt-get install -f -y
+rm *-build-deps_*_all.deb 
+dpkg-buildpackage -rfakeroot
+RET=$?
+
+exit $RET
+
+# Local Variables:
+# mode:shell-script
+# sh-indentation: 4
+# sh-basic-offset: 4
+# End:
+