@@ -10,6 +10,7 @@ import { IJobRepoLogger } from '../services/logger';
1010import { IRepoConnector } from '../services/repo' ;
1111import { JobHandler } from './jobHandler' ;
1212import { IJobValidator } from './jobValidator' ;
13+ import { joinUrlAndPrefix } from './manifestJobHandler' ;
1314
1415export class ProductionJobHandler extends JobHandler {
1516 constructor (
@@ -48,18 +49,82 @@ export class ProductionJobHandler extends JobHandler {
4849
4950 // TODO: Reduce confusion between job.manifestPrefix and job.payload.manifestPrefix
5051 if ( this . currJob . payload . isNextGen ) {
51- const manifestPrefix = this . currJob . payload . manifestPrefix ;
52+ this . currJob . manifestPrefix = this . currJob . manifestPrefix ?? this . constructManifestPrefix ( ) ;
5253 this . currJob . deployCommands [
5354 this . currJob . deployCommands . length - 1
5455 ] = `make next-gen-deploy MUT_PREFIX=${ this . currJob . payload . mutPrefix } ` ;
5556 // TODO: Remove when satisfied with new manifestJobHandler infrastructure
56- if ( manifestPrefix ) {
57+ if ( this . currJob . manifestPrefix ) {
5758 const searchFlag = this . currJob . payload . stable ? '-g' : '' ;
5859 this . currJob . deployCommands [
5960 this . currJob . deployCommands . length - 1
60- ] += ` MANIFEST_PREFIX=${ manifestPrefix } GLOBAL_SEARCH_FLAG=${ searchFlag } ` ;
61+ ] += ` MANIFEST_PREFIX=${ this . currJob . manifestPrefix } GLOBAL_SEARCH_FLAG=${ searchFlag } ` ;
6162 }
6263 }
64+ // have to combine search deploy commands
65+ // manifestJobHandler.prepDeployCommands
66+
67+ this . currJob . shouldGenerateSearchManifest = this . shouldGenerateSearchManifest ( ) ;
68+ this . logger . save (
69+ this . currJob . _id ,
70+ `this.currJob.shouldGenerateSearchManifest ${ this . currJob . shouldGenerateSearchManifest } `
71+ ) ;
72+ if ( this . currJob . shouldGenerateSearchManifest ) {
73+ this . prepSearchDeploy ( ) ;
74+ }
75+ }
76+
77+ prepSearchDeploy ( ) : void {
78+ const b = this . _config . get < string > ( 'searchIndexBucket' ) ?? 'docs-search-indexes-test' ;
79+ // /deploy -> send to /prd folder. /test-deploy -> send to /preprd folder
80+ const env = this . _config . get < string > ( 'env' ) ;
81+ // Note: mut-index automatically prepends 'search-indexes/' to the folder.
82+ const f = this . _config . get < string > ( 'searchIndexFolder' ) ?. [ env ] ?? 'fallback-folder' ;
83+ this . logger . save ( this . currJob . _id , `Manifest attempt to upload to bucket: ${ b } , folder: ${ f } ` ) ;
84+ // Due to the dual existence of prefixes, check for both for redundancy
85+ const maP = this . currJob . manifestPrefix ?? this . currJob . payload . manifestPrefix ;
86+ const muP = this . currJob . mutPrefix ?? this . currJob . payload . mutPrefix ;
87+ const url = this . currJob . payload ?. repoBranches ?. url ?. [ env ] ;
88+ const jUaP = joinUrlAndPrefix ;
89+ const globalSearch = this . currJob . payload . stable ? '-g' : '' ;
90+
91+ // Rudimentary error logging
92+ if ( ! b ) {
93+ this . logger . save ( this . currJob . _id , `searchIndexBucket not found` ) ;
94+ }
95+ if ( ! f ) {
96+ this . logger . save ( this . currJob . _id , `searchIndexFolder not found` ) ;
97+ }
98+
99+ if ( ! url ) {
100+ this . logger . error (
101+ this . currJob . _id ,
102+ `repoBranches.url entry for this environment (${ env } ) not found for ${ this . currJob . _id } `
103+ ) ;
104+ return ;
105+ }
106+
107+ if ( ! this . currJob . manifestPrefix ) {
108+ this . logger . error ( this . currJob . _id , `Manifest prefix not found for ${ this . currJob . _id } ` ) ;
109+ return ;
110+ }
111+ const searchCommands = [
112+ '. /venv/bin/activate' ,
113+ `cd repos/${ this . currJob . payload . repoName } ` ,
114+ 'echo IGNORE: testing manifest generation deploy commands' ,
115+ 'ls -al' ,
116+ // For mut-index usage info, see: https://github.com/mongodb/mut/blob/master/mut/index/main.py#L2
117+ `mut-index upload bundle.zip -b ${ b } -o ${ f } /${ maP } .json -u ${ jUaP ( url , muP || '' ) } ${ globalSearch } ` ,
118+ ] ;
119+ for ( const command of searchCommands ) {
120+ if ( this . currJob . deployCommands . indexOf ( command ) === - 1 ) {
121+ this . currJob . deployCommands . push ( command ) ;
122+ }
123+ }
124+ this . logger . save (
125+ this . currJob . _id ,
126+ `deploy commands: ${ this . currJob . deployCommands . map ( ( command ) => command + '\n' ) } `
127+ ) ;
63128 }
64129
65130 prepStageSpecificNextGenCommands ( ) : void {
@@ -126,10 +191,6 @@ export class ProductionJobHandler extends JobHandler {
126191 await this . logger . save ( this . currJob . _id , `${ '(prod)' . padEnd ( 15 ) } Deploy details:\n\n${ resp . output } ` ) ;
127192 }
128193
129- this . currJob . shouldGenerateSearchManifest = this . shouldGenerateSearchManifest ( ) ;
130- if ( this . currJob . shouldGenerateSearchManifest ) {
131- this . queueManifestJob ( ) ;
132- }
133194 return resp ;
134195 } catch ( errResult ) {
135196 await this . logger . save ( this . currJob . _id , `${ '(prod)' . padEnd ( 15 ) } stdErr: ${ errResult . stderr } ` ) ;
0 commit comments