This should fix #2744.
from common_code import *
from db_add import *
from lib import dput
-from lib import git_buildpackage
from lib import git_helper
+from lib import gitpkg
+from lib import pbuilder
# from common_code
logger.info(' ' + line)
#
- # ACT IV: preparations are done, let's build
+ # ACT IV: preparations are done, let's build the source
#
- gbp = git_buildpackage.GitBuildPackage(
- upstream_branch=local_branch,
- debian_branch=local_branch,
+ logger.info('Start building the source package with gitpkg...\n')
+ source_builder = gitpkg.GitPkg(gitrepo, 'HEAD')
+ ret = source_builder.build()
+
+ #
+ # ACT V: build the binary with pbuilder from the created source tarball
+ #
+ builder = pbuilder.Pbuilder(
+ dsc_file=source_builder.dsc_file,
dist=curr_dist,
arch='amd64',
pb_suite=pb_suite,
git_commit_id=curr_commit_id[0:7],
)
- logger.info('Current environment:\n\n{env}\n'.format(env=gbp.env))
- logger.info('Start building ...\n')
- ret = gbp.build()
+ logger.info('Current environment:\n\n{env}\n'.format(env=builder.env))
+ logger.info('Start building the binary package with pbuilder...\n')
+ ret = builder.build()
# .. remove last commit (the one where we added the changelog entry)
# FIXME: when 'merge': reset only on original branch?
###
cd {jenkins_workspace}
-export {gbp_env} FORCE_SHELL=TRUE
+export {builder_env} FORCE_SHELL=TRUE
{command}
###
hostname=socket.gethostname(),
jenkins_user=ENV['USER'],
jenkins_workspace=ENV['WORKSPACE'],
- gbp_env=' '.join(['{k}="{v}"'.format(k=key, v=gbp.env[key],)
- for key in gbp.env.keys()
+ builder_env=' '.join(['{k}="{v}"'.format(k=key, v=builder.env[key],)
+ for key in builder.env.keys()
]),
- command=' '.join(gbp.command),
+ command=' '.join(builder.command),
orig_branch=ENV['GIT_BRANCH'],
))
figlet('Build OK')
#
- # ACT V: post-build actions
+ # ACT VI: post-build actions
#
# .. make test results available in jenkins:
--- /dev/null
+#!/bin/sh
+set -e
+
+echo $DEB_DSC > $REPO_DIR/../debian_dsc
--- /dev/null
+# -*- coding: utf-8 -*-
+"""
+Created on Thu Dec 12 13:41:03 2013
+
+@author: Benjamin Drung <benjamin.drung@profitbricks.com>
+"""
+
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import os
+import sys
+import logging
+import subprocess
+
+logger = logging.getLogger(__file__)
+
+BIN_GITPKG = '/usr/bin/gitpkg'
+
+class GitPkg(object):
+ def __init__(self, gitrepo, debian_branch=None, upstream_branch=None):
+ '''
+ TODO
+ '''
+ self.gitrepo = gitrepo
+ self.debian_branch = debian_branch
+ self.upstream_branch = upstream_branch
+
+ @property
+ def env(self):
+ '''
+ TODO
+ '''
+ result = os.environ
+ return result
+
+ @property
+ def command(self):
+ '''
+ TODO
+ '''
+ result = [
+ BIN_GITPKG,
+ self.debian_branch,
+ ]
+ if self.upstream_branch:
+ result.append(self.upstream_branch)
+ return result
+
+ def build(self):
+ '''
+ TODO
+ '''
+
+ # gitpkg-exit-hook is stored in the same directory than the
+ # debian_build.py script.
+ base_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
+ config_writer = self.gitrepo.config_writer()
+ config_writer.set_value('gitpkg', 'create-fake-orig', 'true')
+ config_writer.set_value('gitpkg', 'gitpkg.exit-hook',
+ os.path.join(base_dir, 'gitpkg-exit-hook'))
+
+ cmdobj = subprocess.Popen(
+ self.command,
+ shell=False,
+ close_fds=True,
+ #stdout=subprocess.PIPE,
+ #stderr=subprocess.PIPE,
+ stdout=sys.stdout,
+ stderr=sys.stderr,
+ env=self.env,
+ cwd=os.getcwd(),
+ )
+
+ ret = cmdobj.wait()
+ return ret
+
+ @property
+ def dsc_file(self):
+ dsc_file = None
+ debian_dsc = os.path.join(os.getcwd(), "../debian_dsc")
+ if os.path.isfile(debian_dsc):
+ dsc_file = open(debian_dsc).read()
+ if not os.path.isfile(dsc_file):
+ logger.error("Generated source package " + dsc_file +
+ " not found.")
+ return dsc_file
\ No newline at end of file
--- /dev/null
+# -*- coding: utf-8 -*-
+"""
+Created on Thu Dec 12 16:12:51 2013
+
+@author: Benjamin Drung <benjamin.drung@profitbricks.com>
+"""
+
+import os
+import sys
+import subprocess
+
+BIN_PBUILDER = '/usr/bin/pbuilder'
+BIN_SUDO = '/usr/bin/sudo'
+
+class Pbuilder(object):
+ def __init__(self,
+ dsc_file=None,
+ dist=None,
+ arch=None,
+ pb_suite=None,
+ git_commit_id=None,
+ ):
+ '''
+ TODO
+ '''
+ self.dsc_file = dsc_file
+ self.dist = dist
+ self.arch = arch
+ self.pb_suite = pb_suite
+ self.git_commit_id = git_commit_id
+
+ @property
+ def env(self):
+ '''
+ TODO
+ '''
+ result = os.environ
+ result['DIST'] = self.dist
+ result['ARCH'] = self.arch
+ result['PB_SUITE'] = self.pb_suite
+ result['GIT_COMMIT_ID'] = self.git_commit_id
+ return result
+
+ @property
+ def command(self):
+ '''
+ TODO
+ '''
+ result = [
+ BIN_SUDO,
+ BIN_PBUILDER,
+ '--build',
+ '--buildresult=../build-area/result/',
+ '--debbuildopts', '-b', # don't build source packages...
+ # see directly below
+ self.dsc_file,
+ ]
+ return result
+
+ def build(self):
+ '''
+ TODO
+ '''
+ # if we would build orig.tar.gz we would need to be able to access
+ # them later, which we probably could achieve with using pristine-tar
+ # and storing that in the git repo - but this has the downside that
+ # the jenkins build job would need to push this back into the git repo
+ # (so this makes things complicated) and then still, we could not
+ # gurantee that this orig.tar.gz actually reflects the git repo at
+ # that point.
+ # So in summary, it would be expensive and buys as nothing, as we
+ # can always generate the source from said git repos...
+
+ cmdobj = subprocess.Popen(
+ self.command,
+ shell=False,
+ close_fds=True,
+ #stdout=subprocess.PIPE,
+ #stderr=subprocess.PIPE,
+ stdout=sys.stdout,
+ stderr=sys.stderr,
+ env=self.env,
+ cwd=os.getcwd(),
+ )
+
+ ret = cmdobj.wait()
+ return ret
\ No newline at end of file