]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
debian_build: compatibility mode and error for job building from wrong branch
authorMathias Klette <mathias.klette@profitbricks.com>
Mon, 27 May 2013 19:18:25 +0000 (21:18 +0200)
committerMathias Klette <mathias.klette@profitbricks.com>
Mon, 27 May 2013 19:18:25 +0000 (21:18 +0200)
debian_build.py

index 44d65f06fa908815244ccec2e11803fef0c7c438..114ba16f7a4975427d5bb29a273c46d0a12d6a0c 100755 (executable)
@@ -79,7 +79,11 @@ def getopts():
     parser.add_option(
         '--distribution',
         dest='distribution',
-        default='unstable',
+        choices = [
+            'squeeze',
+            'wheezy',
+        ],
+        default='squeeze',
         help='The pkg distribution. Default: %default'
     )
     parser.add_option(
@@ -140,24 +144,17 @@ if __name__ == '__main__':
     # id attribute used in python-git 0.1.6-1 found in squeeze
     elif hasattr(curr_commit, 'id'):
         curr_commit_id = curr_commit.id
-        
-
-    # .. dput related (some overrides happening below, though)
-    dput_obj = dput.Dput(
-        config = os.path.join(ENV['WORKSPACE'], '..', 'dput.cf'),
-        section = 'profitbricks',
-        contents = {
-            'fqdn': 'alexandria.pb.local',
-            'method': 'scp',
-            'login': 'reprepro',
-            'incoming': '/srv/profitbricks-repository/incoming/profitbricks',
-            'allow_unsigned_uploads': 1,
-            'post_upload_command': 'ssh reprepro@alexandria.pb.local /srv/profitbricks-repository/bin/pb_processincoming',
-            }
-        )
 
 
     # Act II: make decissions
+    # compatibility until call_jenkins was replaced
+    if ENV['DISTRIBUTION'] not in ('squeeze','wheezy'):
+        logger.warn('Compatbility Mode: Change distribution {old} => {new}.'.format(
+            old = ENV['DISTRIBUTION'],
+            new = 'squeeze'
+            ))
+        ENV['DISTRIBUTION'] = 'squeeze'
+
     if re.match(COMMIT_TRIGGER_BRANCHES_RE, ENV['GIT_BRANCH']):
         do_triggers = True
 
@@ -169,7 +166,9 @@ if __name__ == '__main__':
             exit_error()
         new_dist = 'stable'
         new_version = '{version}'.format(version = curr_version)
-        pb_suite = 'master-' + ENV['DISTRIBUTION']
+        pb_suite = 'master-' + curr_dist
+        reprepro_base = '/srv/pb-' + curr_dist
+
         # replace valid debian version chars that are invalid for git tagging
         new_tag = curr_version.replace('~','_')
         new_tag = new_tag.replace(':',',')
@@ -177,7 +176,7 @@ if __name__ == '__main__':
         if ENV['GIT_BRANCH'] in AUTO_CHANGELOG_REPONAMES:
             do_autoincrement = True
         # reset actions
-        if ENV['DISTRIBUTION'] == 'squeeze':
+        if curr_dist == 'squeeze':
             # .. always include successful build packages into CIDB
             do_cidb = True
             do_liveboot_request = True
@@ -193,12 +192,6 @@ if __name__ == '__main__':
                     exit_error()
             else:
                 do_tagging = True
-        else:
-            # FIXME: tagging, cidb and liveboot makes no sense yet for other dists
-            # FIXME: align reprepro to also use naming scheme for squeeze
-            dput_obj.contents.update({
-                'incoming': '/srv/profitbricks-repository/incoming/profitbricks-wheezy',
-                })
 
     elif re.match(UNSTABLE_BRANCHES_RE, ENV['GIT_BRANCH']):
         if not re.match('^ps_.*$', ENV['JOB_NAME']):
@@ -213,15 +206,12 @@ if __name__ == '__main__':
             build = ENV['BUILD_NUMBER'],
             commit = curr_commit_id[0:7],
             )
-        pb_suite = 'develop-' + ENV['DISTRIBUTION']
+        pb_suite = 'develop-' + curr_dist
+        reprepro_base = '/srv/pb-' + curr_dist
         # reset actions
         # .. always include successful build packages into CIDB
         if ENV['DISTRIBUTION'] == 'squeeze':
             do_cidb = True
-        else:
-            dput_obj.contents.update({
-                'incoming': '/srv/profitbricks-repository/incoming/profitbricks-wheezy',
-                })
 
     elif re.match(EXPERIMENTAL_BRANCHES_RE, ENV['GIT_BRANCH']):
         if not re.match('^dev_.*$', ENV['JOB_NAME']):
@@ -229,6 +219,7 @@ if __name__ == '__main__':
                 ENV['GIT_BRANCH']
                 ))
             exit_error()
+
         new_dist = 'dev-' + ENV['GIT_BRANCH'].replace("/","-")
         new_version = '{version}~experimental{date}+{build}+{commit}'.format(
             version = curr_version,
@@ -236,26 +227,8 @@ if __name__ == '__main__':
             build = ENV['BUILD_NUMBER'],
             commit = curr_commit_id[0:7],
             )
-        pb_suite = 'experimental-' + ENV['DISTRIBUTION']
-        dput_obj.contents.update({
-            'post_upload_command': 'ssh reprepro@alexandria.pb.local /srv/dev-repository/bin/pb_processincoming',
-            })
-
-        if ENV['DISTRIBUTION'] == 'squeeze':
-            dput_obj.contents.update({
-                'incoming': '/srv/dev-repository/incoming/',
-                })
-        else:
-            # reprepro uses dynamic distributions based on the distribution
-            # value given in the package. to not interferre with experimental
-            # squeeze package, we need to include the distribution here.
-            new_dist = 'dev-{branch}-{dist}'.format(
-                branch = ENV['GIT_BRANCH'].replace("/","-"),
-                dist = ENV['DISTRIBUTION'],
-                )
-            dput_obj.contents.update({
-                'incoming': '/srv/dev-repository/incoming/wheezy',
-                })
+        pb_suite = 'experimental-' + curr_dist
+        reprepro_base = '/srv/dev-' + curr_dist
 
     else:
         logger.error('Don\'t know how to handle branch "{branch}".'.format(
@@ -276,8 +249,23 @@ if __name__ == '__main__':
     #        version = '%s~alpha%s+%s+%s' %(version, daily_date, BUILD_NUMBER, curr_commit_id[0:7])
     #        changelog_distro = 'unstable'
 
-    logger.debug('Distribution: "%s" => "%s"' %(curr_dist,new_dist))
-    logger.debug('Version: "%s" => "%s"' %(curr_version,new_version))
+    # create dput object with data gathered from reprepro_base defined above
+    dput_obj = dput.Dput(
+        config = os.path.join(ENV['WORKSPACE'], '..', 'dput.cf'),
+        section = 'profitbricks',
+        contents = {
+            'fqdn': 'alexandria.pb.local',
+            'method': 'scp',
+            'login': 'reprepro',
+            'incoming': reprepro_base + '/incoming/profitbricks',
+            'allow_unsigned_uploads': 1,
+            'post_upload_command': 'ssh reprepro@alexandria.pb.local ' + reprepro_base + '/bin/pb_processincoming',
+            }
+        )
+
+    # show what we got so far
+    logger.debug('Distribution: "%s" => "%s"' %(curr_dist, new_dist))
+    logger.debug('Version: "%s" => "%s"' %(curr_version, new_version))
     logger.debug('PB_SUITE: ' + pb_suite)
     if do_triggers:
         logger.debug('Triggers found: ' + commit_triggers)
@@ -317,9 +305,9 @@ if __name__ == '__main__':
                 logger.info('Delete previous upstream tarball(s)')
                 cmd = [BIN_SUDO, BIN_RM, '-v'] + files
                 if subprocess.check_call(cmd):
-                    logger.info(cmd + ' succeeded.')
+                    logger.info('%s succeeded.' % cmd)
                 else:
-                    logger.warn(cmd + ' failed.')
+                    logger.warn('%s failed.' % cmd)
 
         figlet('Cleanup OK')
 
@@ -347,7 +335,7 @@ if __name__ == '__main__':
             # FIXME: ensure this environment variable is available in chroot
             #        (i.e. sudo)
             ENV.update({'DEB_NOTEST':'TRUE'})
-        
+
 
     # .. NOW we can verify debian/control contents
     for line in fileinput.input('debian/control'):
@@ -428,7 +416,7 @@ if __name__ == '__main__':
     ret = gbp.build()
 
     # .. remove last commit (the one where we added the changelog entry)
-    # FIXME: when 'merge': reset only on original branch? 
+    # FIXME: when 'merge': reset only on original branch?
     #                      change checkout back to original branch?
     gitrepo.git.reset('--soft', 'HEAD~1')
 
@@ -492,8 +480,6 @@ if __name__ == '__main__':
         figlet('Upload skipped')
     else:
         try:
-            dput_obj.configure()
-
             # strip epoch
             if ":" in new_version:
                 new_version = new_version.split(":", 1)[1]
@@ -514,6 +500,7 @@ if __name__ == '__main__':
             fh.close()
 
             # upload changes file
+            dput_obj.configure()
             dput_obj.upload(changes_file)
 
             figlet('Upload OK')