setup base stack automatically
							parent
							
								
									ba2931a765
								
							
						
					
					
						commit
						7d7846249a
					
				|  | @ -9,8 +9,11 @@ Parameters: | |||
|     Description: "Your deployment environment: DEV, QA , PROD" | ||||
|   Storage: | ||||
|     Type: String | ||||
|     Default: development | ||||
|     Description: "Your deployment environment: DEV, QA , PROD" | ||||
|     Default: game-ci-storage | ||||
|     Description: "Your s3 storage bucket" | ||||
|   Version: | ||||
|     Type: String | ||||
|     Description: "hash of template" | ||||
| 
 | ||||
|   # ContainerPort: | ||||
|   #   Type: Number | ||||
|  |  | |||
|  | @ -856,6 +856,7 @@ const fs = __importStar(__webpack_require__(35747)); | |||
| const core = __importStar(__webpack_require__(42186)); | ||||
| const remote_builder_constants_1 = __importDefault(__webpack_require__(92560)); | ||||
| const aws_build_runner_1 = __importDefault(__webpack_require__(11201)); | ||||
| const crypto = __webpack_require__(33373); | ||||
| class AWSBuildEnvironment { | ||||
|     constructor(buildParameters) { | ||||
|         this.stackName = buildParameters.awsStackName; | ||||
|  | @ -1022,10 +1023,11 @@ class AWSBuildEnvironment { | |||
|         }); | ||||
|     } | ||||
|     setupBaseStack(CF) { | ||||
|         var _a, _b, _c; | ||||
|         var _a, _b, _c, _d, _e, _f; | ||||
|         return __awaiter(this, void 0, void 0, function* () { | ||||
|             const baseStackName = process.env.baseStackName || 'game-ci-base-stack-01'; | ||||
|             const baseStack = fs.readFileSync(`${__dirname}/cloud-formations/base-setup.yml`, 'utf8'); | ||||
|             const hash = crypto.createHash('md5').update(baseStack).digest('hex'); | ||||
|             const describeStackInput = { | ||||
|                 StackName: baseStackName, | ||||
|             }; | ||||
|  | @ -1038,6 +1040,7 @@ class AWSBuildEnvironment { | |||
|                     Parameters: [ | ||||
|                         { ParameterKey: 'EnvironmentName', ParameterValue: 'development' }, | ||||
|                         { ParameterKey: 'Storage', ParameterValue: `${baseStackName}-storage` }, | ||||
|                         { ParameterKey: 'Version', ParameterValue: `hash` }, | ||||
|                     ], | ||||
|                 }); | ||||
|                 CFState = yield CF.describeStacks(describeStackInput).promise(); | ||||
|  | @ -1047,18 +1050,22 @@ class AWSBuildEnvironment { | |||
|                 if (!stack) { | ||||
|                     throw new Error('expected base stack to exist'); | ||||
|                 } | ||||
|                 if (stack.StackName === baseStackName) { | ||||
|                 if (stack.StackName === baseStackName && | ||||
|                     hash !== ((_c = (_b = stack.Parameters) === null || _b === void 0 ? void 0 : _b.find((x) => x.ParameterKey === 'Version')) === null || _c === void 0 ? void 0 : _c.ParameterValue)) { | ||||
|                     const updateInput = { | ||||
|                         StackName: baseStackName, | ||||
|                         TemplateBody: baseStack, | ||||
|                     }; | ||||
|                     yield CF.updateStack(updateInput).promise(); | ||||
|                 } | ||||
|                 else { | ||||
|                     core.info(`Skipping any update for base stack ${stack.StackName} ${(_d = stack.Parameters) === null || _d === void 0 ? void 0 : _d.find((x) => x.ParameterKey === 'Version')}`); | ||||
|                 } | ||||
|             } | ||||
|             if (((_b = CFState.Stacks) === null || _b === void 0 ? void 0 : _b[0].StackStatus) === 'CREATE_IN_PROGRESS') { | ||||
|             if (((_e = CFState.Stacks) === null || _e === void 0 ? void 0 : _e[0].StackStatus) === 'CREATE_IN_PROGRESS') { | ||||
|                 yield CF.waitFor('stackCreateComplete', describeStackInput).promise(); | ||||
|             } | ||||
|             else if (((_c = CFState.Stacks) === null || _c === void 0 ? void 0 : _c[0].StackStatus) === 'UPDATE_IN_PROGRESS') { | ||||
|             else if (((_f = CFState.Stacks) === null || _f === void 0 ? void 0 : _f[0].StackStatus) === 'UPDATE_IN_PROGRESS') { | ||||
|                 yield CF.waitFor('stackUpdateComplete', describeStackInput).promise(); | ||||
|             } | ||||
|         }); | ||||
|  |  | |||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							|  | @ -9,6 +9,7 @@ import RemoteBuilderConstants from './remote-builder-constants'; | |||
| import AWSBuildRunner from './aws-build-runner'; | ||||
| import { RemoteBuilderProviderInterface } from './remote-builder-provider-interface'; | ||||
| import BuildParameters from '../build-parameters'; | ||||
| const crypto = require('crypto'); | ||||
| 
 | ||||
| class AWSBuildEnvironment implements RemoteBuilderProviderInterface { | ||||
|   private stackName: string; | ||||
|  | @ -232,6 +233,7 @@ class AWSBuildEnvironment implements RemoteBuilderProviderInterface { | |||
|   async setupBaseStack(CF: SDK.CloudFormation) { | ||||
|     const baseStackName = process.env.baseStackName || 'game-ci-base-stack-01'; | ||||
|     const baseStack = fs.readFileSync(`${__dirname}/cloud-formations/base-setup.yml`, 'utf8'); | ||||
|     const hash = crypto.createHash('md5').update(baseStack).digest('hex'); | ||||
|     const describeStackInput: SDK.CloudFormation.DescribeStacksInput = { | ||||
|       StackName: baseStackName, | ||||
|     }; | ||||
|  | @ -244,6 +246,7 @@ class AWSBuildEnvironment implements RemoteBuilderProviderInterface { | |||
|         Parameters: [ | ||||
|           { ParameterKey: 'EnvironmentName', ParameterValue: 'development' }, | ||||
|           { ParameterKey: 'Storage', ParameterValue: `${baseStackName}-storage` }, | ||||
|           { ParameterKey: 'Version', ParameterValue: `hash` }, | ||||
|         ], | ||||
|       }); | ||||
|       CFState = await CF.describeStacks(describeStackInput).promise(); | ||||
|  | @ -252,12 +255,21 @@ class AWSBuildEnvironment implements RemoteBuilderProviderInterface { | |||
|       if (!stack) { | ||||
|         throw new Error('expected base stack to exist'); | ||||
|       } | ||||
|       if (stack.StackName === baseStackName) { | ||||
|       if ( | ||||
|         stack.StackName === baseStackName && | ||||
|         hash !== stack.Parameters?.find((x) => x.ParameterKey === 'Version')?.ParameterValue | ||||
|       ) { | ||||
|         const updateInput: SDK.CloudFormation.UpdateStackInput = { | ||||
|           StackName: baseStackName, | ||||
|           TemplateBody: baseStack, | ||||
|         }; | ||||
|         await CF.updateStack(updateInput).promise(); | ||||
|       } else { | ||||
|         core.info( | ||||
|           `Skipping any update for base stack ${stack.StackName} ${stack.Parameters?.find( | ||||
|             (x) => x.ParameterKey === 'Version', | ||||
|           )}`,
 | ||||
|         ); | ||||
|       } | ||||
|     } | ||||
|     if (CFState.Stacks?.[0].StackStatus === 'CREATE_IN_PROGRESS') { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue