@@ -542,7 +542,7 @@ def kube_delete_job(self, job_id):
542542 except :
543543 pass
544544
545- def kube_job (self , job_id , cpu , mem , private_key , services = None ):
545+ def kube_job (self , job_id , cpu , mem , services = None ):
546546 h = {'Authorization' : 'Bearer %s' % self .args .token }
547547
548548 job_token = encode_job_token (job_id ).decode ()
@@ -561,7 +561,33 @@ def kube_job(self, job_id, cpu, mem, private_key, services=None):
561561 'value' : str (cpu )
562562 }]
563563
564- if private_key :
564+ # Get ssh key for private repos
565+ cursor = self .conn .cursor ()
566+ cursor .execute ('''
567+ SELECT p.type, p.id
568+ FROM project p
569+ JOIN job j
570+ ON j.project_id = p.id
571+ WHERE j.id = %s
572+ ''' , [job_id ])
573+ result = cursor .fetchone ()
574+ cursor .close ()
575+
576+ project_type = result [0 ]
577+ project_id = result [1 ]
578+
579+ private_key = None
580+ if project_type == 'github' :
581+ cursor = self .conn .cursor ()
582+ cursor .execute ('''
583+ SELECT r.private_key
584+ FROM repository r
585+ WHERE r.project_id = %s
586+ ''' , [project_id ])
587+ result = cursor .fetchone ()
588+ cursor .close ()
589+ private_key = result [0 ]
590+
565591 env += [{
566592 'name' : 'INFRABOX_GIT_PORT' ,
567593 'value' : '443'
@@ -572,6 +598,18 @@ def kube_job(self, job_id, cpu, mem, private_key, services=None):
572598 'name' : 'INFRABOX_GIT_PRIVATE_KEY' ,
573599 'value' : private_key
574600 }]
601+ elif project_type == 'gerrit' :
602+ with open (os .environ ['INFRABOX_GERRIT_KEY_FILENAME' ]) as key :
603+ env += [{
604+ 'name' : 'INFRABOX_GIT_PORT' ,
605+ 'value' : os .environ ['INFRABOX_GERRIT_PORT' ]
606+ }, {
607+ 'name' : 'INFRABOX_GIT_HOSTNAME' ,
608+ 'value' : os .environ ['INFRABOX_GERRIT_HOSTNAME' ]
609+ }, {
610+ 'name' : 'INFRABOX_GIT_PRIVATE_KEY' ,
611+ 'value' : key .read ()
612+ }]
575613
576614 root_url = os .environ ['INFRABOX_ROOT_URL' ]
577615
@@ -634,34 +672,7 @@ def schedule_job(self, job_id, cpu, memory):
634672 if definition and 'services' in definition :
635673 services = definition ['services' ]
636674
637- # Get ssh key for private repos
638- cursor = self .conn .cursor ()
639- cursor .execute ('''
640- SELECT p.type, p.id
641- FROM project p
642- JOIN job j
643- ON j.project_id = p.id
644- WHERE j.id = %s
645- ''' , [job_id ])
646- result = cursor .fetchone ()
647- cursor .close ()
648-
649- project_type = result [0 ]
650- project_id = result [1 ]
651-
652- private_key = None
653- if project_type == 'github' :
654- cursor = self .conn .cursor ()
655- cursor .execute ('''
656- SELECT r.private_key
657- FROM repository r
658- WHERE r.project_id = %s
659- ''' , [project_id ])
660- result = cursor .fetchone ()
661- cursor .close ()
662- private_key = result [0 ]
663-
664- if not self .kube_job (job_id , cpu , memory , private_key , services = services ):
675+ if not self .kube_job (job_id , cpu , memory , services = services ):
665676 return
666677
667678 cursor = self .conn .cursor ()
0 commit comments