summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorParide Legovini <paride.legovini@canonical.com>2020-10-19 22:59:16 +0200
committerGitHub <noreply@github.com>2020-10-19 14:59:16 -0600
commit5a7f6818083118b45828fa0b334309449881f80a (patch)
treed0a0ca04fd8cfc2aebc5ca667f854619c7452429
parentb94962b558e929a365bcfad1ca9a9445eee575e8 (diff)
downloadvyos-cloud-init-5a7f6818083118b45828fa0b334309449881f80a.tar.gz
vyos-cloud-init-5a7f6818083118b45828fa0b334309449881f80a.zip
bddeb: new --packaging-branch argument to pull packaging from branch (#576)
bddeb builds a .deb package using the template packaging files in packages/debian/. The new --packaging-branch flag allows to specify a git branch where to pull the packaging (i.e. the debian/ directory) from. This is useful to build a .deb package from master with the very same packaging which is used for the uploads.
-rw-r--r--cloudinit/subp.py6
-rw-r--r--doc/rtd/topics/cloud_tests.rst13
-rwxr-xr-xpackages/bddeb80
3 files changed, 91 insertions, 8 deletions
diff --git a/cloudinit/subp.py b/cloudinit/subp.py
index 3e4efa42..024e1a98 100644
--- a/cloudinit/subp.py
+++ b/cloudinit/subp.py
@@ -144,7 +144,7 @@ class ProcessExecutionError(IOError):
def subp(args, data=None, rcs=None, env=None, capture=True,
combine_capture=False, shell=False,
logstring=False, decode="replace", target=None, update_env=None,
- status_cb=None):
+ status_cb=None, cwd=None):
"""Run a subprocess.
:param args: command to run in a list. [cmd, arg1, arg2...]
@@ -181,6 +181,8 @@ def subp(args, data=None, rcs=None, env=None, capture=True,
:param status_cb:
call this fuction with a single string argument before starting
and after finishing.
+ :param cwd:
+ change the working directory to cwd before executing the command.
:return
if not capturing, return is (None, None)
@@ -254,7 +256,7 @@ def subp(args, data=None, rcs=None, env=None, capture=True,
try:
sp = subprocess.Popen(bytes_args, stdout=stdout,
stderr=stderr, stdin=stdin,
- env=env, shell=shell)
+ env=env, shell=shell, cwd=cwd)
(out, err) = sp.communicate(data)
except OSError as e:
if status_cb:
diff --git a/doc/rtd/topics/cloud_tests.rst b/doc/rtd/topics/cloud_tests.rst
index e4e893d2..0fbb1301 100644
--- a/doc/rtd/topics/cloud_tests.rst
+++ b/doc/rtd/topics/cloud_tests.rst
@@ -151,17 +151,20 @@ cloud-init located in a different directory, use the option ``--cloud-init
Bddeb
-----
-The ``bddeb`` command can be used to generate a deb file. This is used by
-the tree_run and tree_collect commands to build a deb of the current
-working tree. It can also be used a user to generate a deb for use in other
-situations and avoid needing to have all the build and test dependencies
-installed locally.
+The ``bddeb`` command can be used to generate a deb file. This is used by the
+tree_run and tree_collect commands to build a deb of the current working tree
+using the packaging template contained in the ``packages/debian/`` directory.
+It can also be used to generate a deb for use in other situations and avoid
+needing to have all the build and test dependencies installed locally.
* ``--bddeb-args``: arguments to pass through to bddeb
* ``--build-os``: distribution to use as build system (default is xenial)
* ``--build-platform``: platform to use for build system (default is lxd)
* ``--cloud-init``: path to base of cloud-init tree (default is '.')
* ``--deb``: path to write output deb to (default is '.')
+* ``--packaging-branch``: import the ``debian/`` packaging directory
+ from the specified branch (default: ``ubuntu/devel``) instead of using
+ the packaging template.
Setup Image
-----------
diff --git a/packages/bddeb b/packages/bddeb
index b0f219b6..a3fb8848 100755
--- a/packages/bddeb
+++ b/packages/bddeb
@@ -5,6 +5,7 @@ import csv
import json
import os
import shutil
+import subprocess
import sys
UNRELEASED = "UNRELEASED"
@@ -99,6 +100,36 @@ def write_debian_folder(root, templ_data, cloud_util_deps):
params={'build_depends': ','.join(requires)})
+def write_debian_folder_from_branch(root, templ_data, branch):
+ """Import a debian package directory from a branch."""
+ print("Importing debian/ from branch %s to %s" % (branch, root))
+
+ p_dumpdeb = subprocess.Popen(
+ ["git", "archive", branch, "debian"], stdout=subprocess.PIPE
+ )
+ subprocess.check_call(
+ ["tar", "-v", "-C", root, "-x"],
+ stdin=p_dumpdeb.stdout
+ )
+
+ print("Adding new entry to debian/changelog")
+ full_deb_version = (
+ templ_data["version_long"] + "-1~bddeb" + templ_data["release_suffix"]
+ )
+ subp.subp(
+ [
+ "dch",
+ "--distribution",
+ templ_data["debian_release"],
+ "--newversion",
+ full_deb_version,
+ "--controlmaint",
+ "Snapshot build.",
+ ],
+ cwd=root
+ )
+
+
def read_version():
return json.loads(run_helper('read-version', ['--json']))
@@ -140,6 +171,15 @@ def get_parser():
parser.add_argument("--signuser", default=False, action='store',
help="user to sign, see man dpkg-genchanges")
+
+ parser.add_argument("--packaging-branch", nargs="?", metavar="BRANCH",
+ const="ubuntu/devel", type=str,
+ help=(
+ "Import packaging from %(metavar)s instead of"
+ " using the packages/debian/* templates"
+ " (default: %(const)s)"
+ ))
+
return parser
@@ -147,6 +187,37 @@ def main():
parser = get_parser()
args = parser.parse_args()
+ if args.packaging_branch:
+ try:
+ subp.subp(
+ [
+ "git",
+ "show-ref",
+ "--quiet",
+ "--verify",
+ "refs/heads/" + args.packaging_branch,
+ ]
+ )
+ except subp.ProcessExecutionError:
+ print("Couldn't find branch '%s'." % args.packaging_branch)
+ print("You may need to checkout the branch from the git remote.")
+ return 1
+ try:
+ subp.subp(
+ [
+ "git",
+ "cat-file",
+ "-e",
+ args.packaging_branch + ":debian/control",
+ ]
+ )
+ except subp.ProcessExecutionError:
+ print(
+ "Couldn't find debian/control in branch '%s'."
+ " Is it a packaging branch?" % args.packaging_branch
+ )
+ return 1
+
if not args.sign:
args.debuild_args.extend(['-us', '-uc'])
@@ -198,7 +269,14 @@ def main():
xdir = util.abs_join(tdir, "cloud-init-%s" % ver_data['version_long'])
templ_data.update(ver_data)
- write_debian_folder(xdir, templ_data, cloud_util_deps=args.cloud_utils)
+ if args.packaging_branch:
+ write_debian_folder_from_branch(
+ xdir, templ_data, args.packaging_branch
+ )
+ else:
+ write_debian_folder(
+ xdir, templ_data, cloud_util_deps=args.cloud_utils
+ )
print("Running 'debuild %s' in %r" % (' '.join(args.debuild_args),
xdir))