github.com/hugh712/snapd@v0.0.0-20200910133618-1a99902bd583/release-tools/debian-package-builder (about) 1 #!/usr/bin/make -f 2 # This program allows one to, relatively easily, iterate on Debian packaging in 3 # a way that is extremely close to that occurring in the real Debian archive. 4 # 5 # The key aspect is that packaging is done on a machine running Debian (either 6 # 9 or 10), with the real Debian kernel, with real build-packages (that is, 7 # devoid of any patches potentially present only in Ubuntu), with correct 8 # pristine build environment, unspoiled by convenience packages often present on 9 # workstation environments. 10 # 11 # The system is "portable", being able to execute on anything capable of 12 # running Multipass and apt-cacher-ng. The workflow is as follows: 13 # 14 # - prepare host environment: 15 # $ snap install multipass --classic --edge 16 # $ apt install apt-cacher-ng 17 # On Debian/Ubuntu: 18 # - apt install apt-cacher-ng 19 # On openSUSE: 20 # - zypper install apt-cacher-ng 21 # - echo "Remap-debrep: deb.debian.org/debian ; http://deb.debian.org/debian" >> /etc/apt-cacher-ng/acng.conf 22 # - systemctl enable --now apt-cacher-ng.service 23 # 24 # - prepare scratch build machine: 25 # $ ./debian-package-builder create-debian-10 26 # $ ./debian-package-builder prepare-debian-10 27 # - prepare the source package: 28 # On appropriate branch of the git tree compatible with 29 # building the debian package, e.g. https://salsa.debian.org/zyga-guest/snapd 30 # on the "debian" branch, issue the command 31 # $ apt-get build-dep ./ 32 # $ dpkg-buildpackage -S 33 # TIP: you can iterate on the packing and repeat this step! 34 # If you need to make patches to upstream snapd parts use the "debian-patches" 35 # branch from the same repository, where history is broken down. Then use 36 # $ git format-patches 2.37..HEAD (where 2.37 is the release you are working on) 37 # ...to export any changes made and place the generated patches as files in the 38 # "debian" branch, inside the directory ./debian/patches. Make sure each 39 # patch is listed in the file ./debian/patches/series. Then re-run 40 # $ dpkg-buildpackage -S 41 # The resulting package will be placed in the parent directory of the root of 42 # the project, e.g. in $HOME/packaging/src/github.com/snapcore, assuming a 43 # setup where the GOPATH was set to $HOME/packaging 44 # - build the binary package 45 # While being in the directory $HOME/packaging/src/github.com/snapcore issue 46 # ./debian-packaging-builder build-on-debian-10 47 # This step will copy the source package to an appropriate multipass virtual 48 # machine and build it there using sbuild. Any build dependencies obtained in 49 # this step are automatically cached and are quick to reuse on subsequent 50 # runs. 51 # 52 # In case the build fails an interactive shell will be spawned by sbuild, still 53 # running inside the virtual machine. The package is unpacked twice, you 54 # really only care about the files in the _build directory. You can set 55 # GOPATH manually to 56 # GOPATH=/path/to/directory/called/_build:/usr/share/gocode and run tests and 57 # iterate as usual. The source tree alongside the _build directory is useful 58 # for comparison and for generating patches.. 59 60 # Multipass uses a bridge to communicate with virtual machines it manages. 61 # The query below picks that bridge and prints the associated IP address. 62 vm_bridge_ip=$(shell ip --json addr show dev mpqemubr0 | jq --raw-output '.[]|select(.addr_info | length > 0).addr_info[] | select(.scope=="global").local') 63 64 # There must be an apt-cacher-ng installation on the host. 65 proxy_url=http://$(vm_bridge_ip):3142 66 67 # Packages that are not required for building snapd but are useful for interactive development. 68 packages=git sbuild mc devscripts avahi-daemon ssh emacs-nox vim-nox rsync 69 70 # Helpful function for running a command on the remote machine. 71 # Assumes that the target name ends with machine name, like below. 72 remote=multipass exec $* -- 73 74 # URLs of openstack cloud images for our virtual machines. 75 debian-9-url=https://cdimage.debian.org/mirror/cdimage/openstack/current-9/debian-9-openstack-amd64.qcow2 76 debian-10-url=https://cdimage.debian.org/mirror/cdimage/openstack/testing/debian-testing-openstack-amd64.qcow2 77 78 PHONY: help 79 help: 80 @echo "Availale targets" 81 @echo " create-NAME: create a multipass virtual machine" 82 @echo " prepare-NAME: prepare a virtual machine for building packages" 83 @echo " destroy-NAME: destroy a multipass virtual machine" 84 @echo " build-on-NAME: copy a source package and build it on a virtual machine" 85 @echo 86 @echo "Available names are: debian-9 debian-10" 87 @echo "NOTE: You must provide the source package yourself" 88 @echo "Please read the script for additional instructions." 89 90 .PHONY: create-debian-9 91 create-debian-9: 92 multipass launch -n debian-9 -c 8 -m 4G $(debian-9-url) 93 94 .PHONY: create-debian-10 95 create-debian-10: 96 multipass launch -n debian-10 -c 8 -m 4G $(debian-10-url) 97 98 .PHONY: prepare-debian-9 prepare-debian-10 99 prepare-debian-9 prepare-debian-10: prepare-%: 100 $(remote) sudo mkdir -p /etc/apt/apt.conf.d/ 101 $(remote) sudo sh -c 'echo "Acquire::http::Proxy \"$(proxy_url)\";" > /etc/apt/apt.conf.d/00proxy' 102 -$(remote) sudo apt-get update 103 $(remote) sudo apt-get dist-upgrade -y 104 $(remote) sudo apt-get install -y eatmydata $(packages) 105 $(remote) sudo apt-get autoremove -y 106 $(remote) sudo sbuild-adduser $(shell $(remote) whoami) 107 $(remote) cp /usr/share/doc/sbuild/examples/example.sbuildrc /home/multipass/.sbuildrc 108 # XXX: cloud images come with pre-made chroot? 109 $(remote) sudo rm -f /etc/schroot/chroot.d/sid-amd64-sbuild-* 110 $(remote) sudo rm -rf /srv/chroot/sid-amd64-sbuild 111 # NOTE: the chroot is always for sid, this is mainly to test the impact of the kernel. 112 $(remote) sudo http_proxy=$(proxy_url) eatmydata sbuild-createchroot --include=eatmydata,ccache,gnupg sid /srv/chroot/sid-amd64-sbuild http://deb.debian.org/debian 113 114 .PHONY: destroy-debian-9 destroy-debian-10 115 destroy-debian-9 destroy-debian-10: destroy-%: 116 multipass delete -p $* 117 118 build-on-debian-9 build-on-debian-10: build-on-%: 119 multipass copy-files snapd_*.debian.tar.xz snapd_*.dsc snapd_*.orig.tar.xz snapd-*.tar.gz $*:/home/multipass/ 120 # NOTE: %s expands to a command that starts an interactive shell for debugging. 121 $(remote) sbuild -d sid \ 122 --chroot-setup-commands='echo "Acquire::http::Proxy \"$(proxy_url)\";" > /etc/apt/apt.conf.d/00proxy'\ 123 --build-failed-commands=%s \ 124 --run-autopkgtest \ 125 $(shell ls snapd_*.dsc | sort -r -n | head -n 1)