]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
Replace git-buildpackage by gitpkg and pbuilder.
authorBenjamin Drung <benjamin.drung@profitbricks.com>
Thu, 12 Dec 2013 16:27:23 +0000 (17:27 +0100)
committerBenjamin Drung <benjamin.drung@profitbricks.com>
Thu, 12 Dec 2013 16:28:01 +0000 (17:28 +0100)
This should fix #2744.

debian_build.py
gitpkg-exit-hook [new file with mode: 0644]
lib/gitpkg.py [new file with mode: 0644]
lib/pbuilder.py [new file with mode: 0644]

index 12df0c2327a2ec8e8768c13b2f12d500b1b2d171..4c1e2a51e0fdb603315bae70289d21a2b9e85909 100755 (executable)
@@ -25,8 +25,9 @@ from cidb import *
 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
@@ -470,19 +471,25 @@ if __name__ == '__main__':
             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?
@@ -500,7 +507,7 @@ if __name__ == '__main__':
 ###
 
 cd {jenkins_workspace}
-export {gbp_env} FORCE_SHELL=TRUE
+export {builder_env} FORCE_SHELL=TRUE
 {command}
 
 ###
@@ -511,10 +518,10 @@ export {gbp_env} FORCE_SHELL=TRUE
             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'],
         ))
 
@@ -535,7 +542,7 @@ export {gbp_env} FORCE_SHELL=TRUE
         figlet('Build OK')
 
     #
-    # ACT V: post-build actions
+    # ACT VI: post-build actions
     #
 
     # .. make test results available in jenkins:
diff --git a/gitpkg-exit-hook b/gitpkg-exit-hook
new file mode 100644 (file)
index 0000000..8b41dec
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/sh
+set -e
+
+echo $DEB_DSC > $REPO_DIR/../debian_dsc
diff --git a/lib/gitpkg.py b/lib/gitpkg.py
new file mode 100644 (file)
index 0000000..8ef6c58
--- /dev/null
@@ -0,0 +1,87 @@
+# -*- 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
diff --git a/lib/pbuilder.py b/lib/pbuilder.py
new file mode 100644 (file)
index 0000000..a65d9c3
--- /dev/null
@@ -0,0 +1,87 @@
+# -*- 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