From 4ae0d5b843703175405eaabb084c5d5e985abbd7 Mon Sep 17 00:00:00 2001 From: Shane McDonald Date: Wed, 26 Oct 2016 17:24:15 -0400 Subject: [PATCH] Build debs with pbuilder (#18165) * Build debs with pbuilder * Update README in packaging/debian * Add Dockerfile for building debs * Add local_deb makefile target - Allows users to build debs using locally installed dependencies. This was the `deb` target before moving to pbuilder. --- .gitignore | 2 +- Makefile | 24 +++++++++++++++++++++++- packaging/debian/Dockerfile | 16 ++++++++++++++++ packaging/debian/README.md | 37 +++++++++++++++++++++++++------------ packaging/debian/rules | 3 --- 5 files changed, 65 insertions(+), 17 deletions(-) create mode 100644 packaging/debian/Dockerfile diff --git a/.gitignore b/.gitignore index 3dbd0190ef8..4ebacf429ab 100644 --- a/.gitignore +++ b/.gitignore @@ -43,7 +43,7 @@ docsite/htmlout docs-api/rst/ docs-api/_build/ # deb building stuff... -debian/ +/debian/ deb-build # Vim swap files *.swp diff --git a/Makefile b/Makefile index 8628ea35373..4dbede47224 100644 --- a/Makefile +++ b/Makefile @@ -77,6 +77,12 @@ DEB_PPA ?= ppa # Choose the desired Ubuntu release: lucid precise saucy trusty DEB_DIST ?= unstable +# pbuilder parameters +PBUILDER_ARCH ?= amd64 +PBUILDER_CACHE_DIR = /var/cache/pbuilder +PBUILDER_BIN ?= pbuilder +PBUILDER_OPTS ?= --debootstrapopts --variant=buildd --architecture $(PBUILDER_ARCH) --debbuildopts -b + # RPM build parameters RPMSPECDIR= packaging/rpm RPMSPEC = $(RPMSPECDIR)/ansible.spec @@ -230,7 +236,23 @@ debian: sdist sed -ie "s|%VERSION%|$(VERSION)|g;s|%RELEASE%|$(DEB_RELEASE)|;s|%DIST%|$${DIST}|g;s|%DATE%|$(DEB_DATE)|g" deb-build/$${DIST}/$(NAME)-$(VERSION)/debian/changelog ; \ done -deb: debian +deb: deb-src + @for DIST in $(DEB_DIST) ; do \ + PBUILDER_OPTS="$(PBUILDER_OPTS) --distribution $${DIST} --basetgz $(PBUILDER_CACHE_DIR)/$${DIST}-$(PBUILDER_ARCH)-base.tgz --buildresult $(CURDIR)/deb-build/$${DIST}" ; \ + $(PBUILDER_BIN) create $${PBUILDER_OPTS} --othermirror "deb http://archive.ubuntu.com/ubuntu $${DIST} universe" ; \ + $(PBUILDER_BIN) update $${PBUILDER_OPTS} ; \ + $(PBUILDER_BIN) build $${PBUILDER_OPTS} deb-build/$${DIST}/$(NAME)_$(VERSION)-$(DEB_RELEASE)~$${DIST}.dsc ; \ + done + @echo "#############################################" + @echo "Ansible DEB artifacts:" + @for DIST in $(DEB_DIST) ; do \ + echo deb-build/$${DIST}/$(NAME)_$(VERSION)-$(DEB_RELEASE)~$${DIST}_amd64.changes ; \ + done + @echo "#############################################" + +# Build package outside of pbuilder, with locally installed dependencies. +# Install BuildRequires as noted in packaging/debian/control. +local_deb: debian @for DIST in $(DEB_DIST) ; do \ (cd deb-build/$${DIST}/$(NAME)-$(VERSION)/ && $(DEBUILD) -b) ; \ done diff --git a/packaging/debian/Dockerfile b/packaging/debian/Dockerfile new file mode 100644 index 00000000000..6ff10f65850 --- /dev/null +++ b/packaging/debian/Dockerfile @@ -0,0 +1,16 @@ +FROM ubuntu:xenial + +RUN apt-get update && apt-get install -y \ + asciidoc \ + cdbs \ + debootstrap \ + devscripts \ + make \ + pbuilder \ + python-setuptools + +VOLUME /ansible +WORKDIR /ansible + +ENTRYPOINT ["/bin/bash", "-c"] +CMD ["make deb"] diff --git a/packaging/debian/README.md b/packaging/debian/README.md index d894fd1c0cc..cf2a689fc7e 100644 --- a/packaging/debian/README.md +++ b/packaging/debian/README.md @@ -3,26 +3,39 @@ Ansible Debian Package To create an Ansible DEB package: - sudo apt-get install python-paramiko python-yaml python-jinja2 python-httplib2 python-setuptools python-six sshpass - sudo apt-get install cdbs debhelper git-core reprepro fakeroot asciidoc devscripts docbook-xml xsltproc libxml2-utils - sudo apt-get install dh-python build-essential - git clone git://github.com/ansible/ansible.git - cd ansible - make deb +__Note__: You must run this target as root or set `PBUILDER_BIN='sudo pbuilder'` -On older releases that do not have `dh-python` (like Ubuntu 12.04), install `python-support` instead: +``` +apt-get install asciidoc cdbs debootstrap devscripts make pbuilder python-setuptools +git clone git://github.com/ansible/ansible.git +cd ansible +git submodule update --init +DEB_DIST='xenial trusty precise' make deb +``` - sudo apt-get install python-support +Building in Docker: -The debian package file will be placed in the `../` directory. This can then be added to an APT repository or installed with `dpkg -i `. +``` +git clone git://github.com/ansible/ansible.git +cd ansible +git submodule update --init +docker build -t ansible-deb-builder -f packaging/debian/Dockerfile . +docker run --privileged -e DEB_DIST='trusty' -v $(pwd):/ansible ansible-deb-builder +``` + +The debian package file will be placed in the `deb-build` directory. This can then be added to an APT repository or installed with `dpkg -i `. Note that `dpkg -i` does not resolve dependencies. To install the Ansible DEB package and resolve dependencies: - sudo dpkg -i - sudo apt-get -fy install +``` +dpkg -i +apt-get -fy install +``` Or, if you are running Debian Stretch (or later) or Ubuntu Xenial (or later): - sudo apt install +``` +apt install /path/to/ +``` diff --git a/packaging/debian/rules b/packaging/debian/rules index 3ebffe5c838..f5894b7a43b 100755 --- a/packaging/debian/rules +++ b/packaging/debian/rules @@ -2,9 +2,6 @@ # -- makefile -- DEB_PYTHON2_MODULE_PACKAGES=ansible -ifneq ($(shell dpkg-query -f '$${Version}' -W python-support 2>/dev/null),) -DEB_PYTHON_SYSTEM=pysupport -endif include /usr/share/cdbs/1/rules/debhelper.mk include /usr/share/cdbs/1/class/python-distutils.mk