@@ -28,19 +28,17 @@ export class Keroku {
28
28
public config : IKuberoConfig ;
29
29
30
30
constructor ( io : Server ) {
31
- console . log ( "keroku" ) ;
32
31
this . kubectl = new Kubectl ( ) ;
33
32
this . _io = io ;
34
33
35
34
this . githubApi = new GithubApi ( process . env . GITHUB_PERSONAL_ACCESS_TOKEN as string ) ;
36
35
this . config = this . loadConfig ( process . env . KUBERO_CONFIG_PATH as string || './config.yaml' ) ;
37
- console . log ( this . config ) ;
36
+ debug . debug ( 'Kubero Config: ' + JSON . stringify ( this . config ) ) ;
38
37
}
39
38
40
39
public init ( ) {
41
40
this . listPipelines ( ) . then ( pl => {
42
41
for ( const pipeline of pl . items as IPipeline [ ] ) {
43
- //console.log(pipeline)
44
42
this . pipelineStateList . push ( pipeline ) ;
45
43
46
44
for ( const phase of pipeline . phases ) {
@@ -58,10 +56,9 @@ export class Keroku {
58
56
}
59
57
}
60
58
}
61
- //this.emitLogs('popo', 'production', 'ppppp', 'ppppp-kuberoapp-web-6ccb6795bb-48qtt', 'kuberoapp-web')
62
59
}
63
60
) . catch ( error => {
64
- console . log ( error ) ;
61
+ debug . log ( error ) ;
65
62
} ) ;
66
63
}
67
64
@@ -115,12 +112,9 @@ export class Keroku {
115
112
public async newPipeline ( pipeline : IPipeline ) {
116
113
debug . debug ( 'create newPipeline: ' + pipeline . name ) ;
117
114
118
- //console.log(pipeline.phases);
119
-
120
115
// Create the Pipeline CRD
121
116
await this . kubectl . createPipeline ( pipeline ) ;
122
117
123
- //console.log(pipeline.phases);
124
118
// create namespace for each phase
125
119
let secretData = {
126
120
'github.pub' : Buffer . from ( process . env . GIT_DEPLOYMENTKEY_PUBLIC as string ) . toString ( 'base64' ) ,
@@ -317,13 +311,13 @@ export class Keroku {
317
311
}
318
312
319
313
public async handleGithubWebhook ( event : string , delivery : string , signature : string , body : any ) {
320
- console . log ( 'handleGithubWebhook' ) ;
314
+ debug . log ( 'handleGithubWebhook' ) ;
321
315
322
316
//https://docs.github.com/en/developers/webhooks-and-events/webhooks/securing-your-webhooks
323
317
let secret = process . env . GITHUB_WEBHOOK_SECRET as string ;
324
318
let hash = 'sha256=' + crypto . createHmac ( 'sha256' , secret ) . update ( JSON . stringify ( body ) ) . digest ( 'hex' )
325
319
if ( hash === signature ) {
326
- console . log ( 'Github webhook signature is valid for event: ' + delivery ) ;
320
+ debug . debug ( 'Github webhook signature is valid for event: ' + delivery ) ;
327
321
328
322
switch ( event ) {
329
323
case 'push' :
@@ -333,19 +327,18 @@ export class Keroku {
333
327
this . handleGithubPullRequest ( body ) ;
334
328
break ;
335
329
default :
336
- console . log ( 'Github webhook event not handled: ' + event ) ;
330
+ debug . log ( 'Github webhook event not handled: ' + event ) ;
337
331
break ;
338
332
}
339
- //console.log(body);
340
333
} else {
341
334
debug . log ( 'ERROR: invalid signature for event: ' + delivery ) ;
342
- console . log ( hash ) ;
343
- console . log ( signature ) ;
335
+ debug . log ( hash ) ;
336
+ debug . log ( signature ) ;
344
337
}
345
338
}
346
339
347
340
private async handleGithubPush ( body : any ) {
348
- console . log ( 'handleGithubPush' ) ;
341
+ debug . log ( 'handleGithubPush' ) ;
349
342
let ref = body . ref
350
343
let refs = ref . split ( '/' )
351
344
let branch = refs [ refs . length - 1 ]
@@ -357,7 +350,7 @@ export class Keroku {
357
350
}
358
351
359
352
private async getAppsByBranch ( branch : string ) {
360
- console . log ( 'getAppsByBranch: ' + branch ) ;
353
+ debug . log ( 'getAppsByBranch: ' + branch ) ;
361
354
let apps : IApp [ ] = [ ] ;
362
355
for ( const app of this . appStateList ) {
363
356
if ( app . branch === branch ) {
@@ -368,9 +361,9 @@ export class Keroku {
368
361
}
369
362
370
363
private async handleGithubPullRequest ( body : any ) {
371
- console . log ( 'handleGithubPullRequest' ) ;
364
+ debug . log ( 'handleGithubPullRequest' ) ;
372
365
let pullRequest = body . pull_request ;
373
- console . log ( body . action ) ;
366
+ debug . debug ( body . action ) ;
374
367
375
368
switch ( body . action ) {
376
369
case 'opened' :
@@ -388,15 +381,14 @@ export class Keroku {
388
381
// creates a PR App in all Pipelines that have review apps enabled and the same ssh_url
389
382
private async createPRApp ( branch : string , title : string , ssh_url : string ) {
390
383
let pipelines = await this . listPipelines ( ) as IKubectlPipelineList ;
391
- //console.log(pipelines.items);
392
384
393
385
for ( const pipeline of pipelines . items ) {
394
386
395
387
if ( pipeline . spec . reviewapps &&
396
388
pipeline . spec . github . repository &&
397
389
pipeline . spec . github . repository . ssh_url === ssh_url ) {
398
390
399
- console . log ( 'found pipeline: ' + pipeline . spec . name ) ;
391
+ debug . debug ( 'found pipeline: ' + pipeline . spec . name ) ;
400
392
let pipelaneName = pipeline . spec . name
401
393
let phaseName = 'review' ;
402
394
let websaveTitle = title . toLowerCase ( ) . replace ( / [ ^ a - z 0 - 9 - ] / g, '-' ) ; //TODO improve websave title
@@ -444,7 +436,7 @@ export class Keroku {
444
436
445
437
// delete a pr app in all pipelines that have review apps enabled and the same ssh_url
446
438
private async deletePRApp ( branch : string , title : string , ssh_url : string ) {
447
- console . log ( 'destroyPRApp' ) ;
439
+ debug . log ( 'destroyPRApp' ) ;
448
440
let websaveTitle = title . toLowerCase ( ) . replace ( / [ ^ a - z 0 - 9 - ] / g, '-' ) ; //TODO improve websave title
449
441
450
442
for ( const app of this . appStateList ) {
@@ -461,11 +453,7 @@ export class Keroku {
461
453
462
454
private async createAddons ( addons : IAddon [ ] , namespace : string , context : string ) {
463
455
for ( const addon of addons ) {
464
- //console.log(addon);
465
- //console.log('createAddon: '+addon.name);
466
456
for ( const field in addon . formfields ) {
467
- console . log ( addon . formfields [ field ] ) ;
468
-
469
457
let val = addon . formfields [ field ] . default ;
470
458
471
459
if ( addon . formfields [ field ] . type === 'number' ) {
@@ -475,29 +463,27 @@ export class Keroku {
475
463
set ( addon . crd , field , val ) ;
476
464
}
477
465
478
- console . log ( addon . crd ) ;
479
466
this . kubectl . createAddon ( addon , namespace , context ) ;
480
467
}
481
468
}
482
469
483
470
// delete a addon in a namespace
484
471
public async deleteAddon ( addon : IAddonMinimal ) : Promise < void > {
485
- console . log ( `Deleting addon ${ addon . id } ` )
472
+ debug . log ( `Deleting addon ${ addon . id } ` )
486
473
const contextName = this . getContext ( addon . pipeline , addon . phase ) ;
487
474
if ( contextName ) {
488
475
this . kubectl . deleteAddon ( addon , contextName ) ;
489
476
}
490
477
}
491
478
479
+ // Loads the app config from the config file
492
480
private loadConfig ( path :string ) : IKuberoConfig {
493
481
try {
494
- //let config = JSON.parse(fs.readFileSync(path, 'utf8'));
495
- //let config: IKuberoConfig = require(path);
496
482
let config = YAML . parse ( fs . readFileSync ( path , 'utf8' ) ) as IKuberoConfig ;
497
483
return config ;
498
484
} catch ( error ) {
499
485
debug . log ( 'FATAL ERROR: could not load config file: ' + path ) ;
500
- console . log ( error ) ;
486
+ debug . log ( error ) ;
501
487
process . exit ( 1 ) ;
502
488
}
503
489
}
@@ -532,23 +518,20 @@ export class Keroku {
532
518
533
519
if ( contextName ) {
534
520
this . kubectl . setCurrentContext ( contextName ) ;
535
- console . log ( 'logs: ' + podName + ' ' + container ) ;
536
521
537
522
if ( ! this . podLogStreams . includes ( podName ) ) {
538
523
539
524
this . kubectl . log . log ( namespace , podName , container , logStream , { follow : true , tailLines : 50 , pretty : false , timestamps : false } )
540
525
. then ( res => {
541
- console . log ( 'logs done' ) ;
526
+ debug . log ( 'logs started for ' + podName + ' ' + container ) ;
542
527
this . podLogStreams . push ( podName ) ;
543
528
} )
544
529
. catch ( err => {
545
- console . log ( err ) ;
530
+ debug . log ( err ) ;
546
531
} ) ;
547
532
} else {
548
- console . log ( 'logs already running ' + podName + ' ' + container ) ;
533
+ debug . debug ( 'logs already running ' + podName + ' ' + container ) ;
549
534
}
550
- } else {
551
- console . log ( 'no context found for: ' + pipelineName + ' ' + phaseName ) ;
552
535
}
553
536
}
554
537
@@ -559,7 +542,6 @@ export class Keroku {
559
542
if ( contextName ) {
560
543
this . kubectl . getPods ( namespace , contextName ) . then ( ( pods : any [ ] ) => {
561
544
for ( const pod of pods ) {
562
- //console.log(pod)
563
545
564
546
if ( pod . metadata . name . startsWith ( appName ) ) {
565
547
for ( const container of pod . spec . containers ) {
@@ -568,8 +550,6 @@ export class Keroku {
568
550
}
569
551
}
570
552
} ) ;
571
- } else {
572
- console . log ( 'no context found for: ' + pipelineName + ' ' + phaseName ) ;
573
553
}
574
554
}
575
555
}
0 commit comments