]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
debian_build: frist steps to enable multiple distribution builds
authorMathias Klette <mathias.klette@profitbricks.com>
Tue, 7 May 2013 19:30:24 +0000 (21:30 +0200)
committerMathias Klette <mathias.klette@profitbricks.com>
Tue, 7 May 2013 19:30:24 +0000 (21:30 +0200)
debian_build.py

index 47f6ebc85382d97c1415b30273e4f2a0d4206adb..50b037ab9da8f65229afde513bbafb94aedb5831 100755 (executable)
@@ -43,6 +43,7 @@ logger = logger_init(__file__)
 
 # jenkins environment - parameters
 ENV.setdefault('NO_UPLOAD','')
+ENV.setdefault('DISTRIBUTION','squeeze')
 GIT_REPO_PATH = ENV['GIT_REPO_PATH']
 
 # local constants
@@ -159,7 +160,7 @@ if __name__ == '__main__':
 
 
     # Act II: make decissions
-    if re.match(STABLE_BRANCHES_RE,ENV['GIT_BRANCH']):
+    if re.match(STABLE_BRANCHES_RE, ENV['GIT_BRANCH']):
         new_dist = 'production-proposed-updates'
         new_version = '{version}'.format(
             version = curr_version, 
@@ -167,27 +168,37 @@ if __name__ == '__main__':
         # replace valid debian version chars that are invalid for git tagging
         new_tag = curr_version.replace('~','_')
         new_tag = new_tag.replace(':',',')
-        # reset actions
-        # .. always include successful build packages into CIDB
-        do_cidb = True
-        do_liveboot_request = True
         # .. only take care of changelog automation if we want it to
         if ENV['GIT_BRANCH'] in AUTO_CHANGELOG_REPONAMES:
             do_autoincrement = True
-        # .. fail if we already found the tag we would create upon a successfull build,
-        #    except, the existing tag uses the same commit as we were triggered with
-        remote_tag = [tag for tag in gitrepo.tags if tag.name == new_tag]
-        if len(remote_tag) > 0: 
-            if remote_tag[0].commit.id == curr_commit:
-                logger.info('Tag was already created for this commit.')
-                do_tagging = False
+        # reset actions
+        if ENV['DISTRIBUTION'] == 'squeeze':
+            # .. always include successful build packages into CIDB
+            do_cidb = True
+            do_liveboot_request = True
+            # .. fail if we already found the tag we would create upon a successfull build,
+            #    except, the existing tag uses the same commit as we were triggered with
+            remote_tag = [tag for tag in gitrepo.tags if tag.name == new_tag]
+            if len(remote_tag) > 0: 
+                if remote_tag[0].commit.id == curr_commit:
+                    logger.info('Tag was already created for this commit.')
+                    do_tagging = False
+                else:
+                    logger.error('Tag was already created for another commit.')
+                    exit_error()
             else:
-                logger.error('Tag was already created for another commit.')
-                exit_error()
+                do_tagging = True
+            # .. just used for GitBuildPackage()
+            pb_suite = new_dist
         else:
-            do_tagging = True
-
-    elif re.match(DEVELOP_BRANCHES_RE,ENV['GIT_BRANCH']):
+            # TODO: tagging, cidb and liveboot makes no sense yet for other dists
+            # TODO: align reprepro to also use naming scheme for squeeze
+            pb_suite = 'master-' + ENV['DISTRIBUTION']
+            dput_obj.contents.update({
+                'incoming': '/srv/profitbricks-repository/incoming/profitbricks-wheezy',
+                })
+           
+    elif re.match(DEVELOP_BRANCHES_RE, ENV['GIT_BRANCH']):
         new_dist = 'pre-staging'
         new_version = '{version}~develop{date}+{build}+{commit}'.format(
             version = curr_version, 
@@ -197,11 +208,13 @@ if __name__ == '__main__':
             )
         # reset actions
         # .. always include successful build packages into CIDB
-        do_cidb = True
-        # .. never tag in-development builds
-        do_tagging = False
+        if ENV['DISTRIBUTION'] == 'squeeze':
+            do_cidb = True
+            pb_suite = new_dist
+        else:
+            pb_suite = 'develop-' + ENV['DISTRIBUTION']
 
-    elif re.match(EXPERIMENTAL_BRANCHES_RE,ENV['GIT_BRANCH']):
+    elif re.match(EXPERIMENTAL_BRANCHES_RE, ENV['GIT_BRANCH']):
         new_dist ='dev-'+ ENV['GIT_BRANCH'].replace("/","-")
         new_version = '{version}~experimental{date}+{build}+{commit}'.format(
             version = curr_version, 
@@ -213,8 +226,18 @@ if __name__ == '__main__':
             'incoming': '/srv/dev-repository/incoming/',
             'post_upload_command': 'ssh reprepro@alexandria.pb.local /srv/dev-repository/bin/pb_processincoming',
             })
+            pb_suite = new_dist
+        else:
+            pb_suite = 'experimental-' + ENV['DISTRIBUTION']
+
+    else:
+        logger.error('Don\'t know how to handle branch "{branch}".'.format(
+            branch = ENV['GIT_BRANCH'],
+            )
+        exit_error()
 
     #FIXME: enable this once Florian acks.
+    #FIXME: get rid of jenkins parameter, instead use git remote
     #if GIT_REPO_PATH.startswith('/srv/git/dev/'):
     #    if ENV['GIT_BRANCH_NAME'] == 'pre-staging':
     #        version = '%s~develop%s+%s+%s' %(version, daily_date, BUILD_NUMBER, curr_commit[0:7])
@@ -225,9 +248,6 @@ if __name__ == '__main__':
     #        version = '%s~alpha%s+%s+%s' %(version, daily_date, BUILD_NUMBER, curr_commit[0:7])
     #        changelog_distro = 'unstable'
 
-    # .. just used for GitBuildPackage()
-    pb_suite = new_dist
-
 
     # ACT III: do something actually
     # .. do some housekeeping first
@@ -338,17 +358,18 @@ if __name__ == '__main__':
             ''.join([block.__str__() for block in cl._blocks[0:2]])))
 
 
-    # ACT IV: preparations are set, let's build
+    # ACT IV: preparations are done, let's build
+    logger.info('Building ...')
     gbp = git_buildpackage.GitBuildPackage(
         upstream_branch = ENV['GIT_BRANCH'],
         debian_branch = ENV['GIT_BRANCH'],
-        dist = 'squeeze',
+        dist = ENV['DISTRIBUTION'],
         arch = 'amd64',
         pb_suite = pb_suite,
         git_commit_id = curr_commit[0:7]
         )
-    logger.info('Building ...')
     ret = gbp.build()
+
     # .. remove last commit (the one where we added the changelog entry)
     gitrepo.git.reset('--soft', 'HEAD~1')
 
@@ -388,12 +409,14 @@ if __name__ == '__main__':
             gitrepo.git.tag(version_tag)
         except Exception as error:
             logger.error('Could not create tag: ', exc_info=error)
+            figlet('Tagging failed')
             exit_error()
 
         try:
             gitrepo.git.push('origin', version_tag)
         except Exception as error:
             logger.error('Could not push tag: ', exc_info=error)
+            figlet('Tagging failed')
             exit_error()
 
         logger.info('Tagged as "%s".' % version_tag)
@@ -431,8 +454,8 @@ if __name__ == '__main__':
             figlet('Upload OK')
 
         except Exception as error:
-            figlet('Upload failed')
             logger.error('Upload failed. See above for details.')
+            figlet('Upload failed')
             exit_error()
 
 
@@ -455,9 +478,10 @@ if __name__ == '__main__':
                 BUILD_END,
                 )
             figlet('CIDB OK')
+
         except Exception as error:
-            figlet('CIDB failed')
             logger.error("package instance not added to DB: ", exc_info=error)
+            figlet('CIDB failed')
             exit_error()
 
     # .. finally trigger the next liveboot automatically if we succeed with CIDB
@@ -470,6 +494,8 @@ if __name__ == '__main__':
                 figlet('Liveboot OK')
             except:
                 logger.debug("liveboot request failed")
+                figlet('Liveboot failed')
+                exit_error()
 
     # finally, finished!
     logger.info('---------------------------------------------------------------------------------------------------------')