Use base stack name as the environment within aws cloud formations
parent
52ef99fb78
commit
29442b7508
|
|
@ -400,25 +400,25 @@ class AWSBuildEnvironment {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
getParameterTemplate(p1) {
|
getParameterTemplate(p1) {
|
||||||
return `
|
return `
|
||||||
${p1}:
|
${p1}:
|
||||||
Type: String
|
Type: String
|
||||||
Default: ''
|
Default: ''
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
getSecretTemplate(p1) {
|
getSecretTemplate(p1) {
|
||||||
return `
|
return `
|
||||||
${p1}Secret:
|
${p1}Secret:
|
||||||
Type: AWS::SecretsManager::Secret
|
Type: AWS::SecretsManager::Secret
|
||||||
Properties:
|
Properties:
|
||||||
Name: !Join [ "", [ '${p1}', !Ref BUILDID ] ]
|
Name: !Join [ "", [ '${p1}', !Ref BUILDID ] ]
|
||||||
SecretString: !Ref ${p1}
|
SecretString: !Ref ${p1}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
getSecretDefinitionTemplate(p1, p2) {
|
getSecretDefinitionTemplate(p1, p2) {
|
||||||
return `
|
return `
|
||||||
- Name: '${p1}'
|
- Name: '${p1}'
|
||||||
ValueFrom: !Ref ${p2}Secret
|
ValueFrom: !Ref ${p2}Secret
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
insertAtTemplate(template, insertionKey, insertion) {
|
insertAtTemplate(template, insertionKey, insertion) {
|
||||||
|
|
@ -429,8 +429,8 @@ class AWSBuildEnvironment {
|
||||||
setupCloudFormations(CF, buildGuid, image, entrypoint, commands, mountdir, workingdir, secrets) {
|
setupCloudFormations(CF, buildGuid, image, entrypoint, commands, mountdir, workingdir, secrets) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const logGuid = nanoid_1.customAlphabet(cloud_runner_constants_1.default.alphabet, 9)();
|
const logGuid = nanoid_1.customAlphabet(cloud_runner_constants_1.default.alphabet, 9)();
|
||||||
commands[1] += `
|
commands[1] += `
|
||||||
echo "${logGuid}"
|
echo "${logGuid}"
|
||||||
`;
|
`;
|
||||||
yield this.setupBaseStack(CF);
|
yield this.setupBaseStack(CF);
|
||||||
const taskDefStackName = `${this.baseStackName}-${buildGuid}`;
|
const taskDefStackName = `${this.baseStackName}-${buildGuid}`;
|
||||||
|
|
@ -450,7 +450,7 @@ class AWSBuildEnvironment {
|
||||||
taskDefCloudFormation = this.insertAtTemplate(taskDefCloudFormation, 'p2 - secret', this.getSecretTemplate(secret.ParameterKey.replace(/[^\dA-Za-z]/g, '')));
|
taskDefCloudFormation = this.insertAtTemplate(taskDefCloudFormation, 'p2 - secret', this.getSecretTemplate(secret.ParameterKey.replace(/[^\dA-Za-z]/g, '')));
|
||||||
taskDefCloudFormation = this.insertAtTemplate(taskDefCloudFormation, 'p3 - container def', this.getSecretDefinitionTemplate(secret.EnvironmentVariable, secret.ParameterKey.replace(/[^\dA-Za-z]/g, '')));
|
taskDefCloudFormation = this.insertAtTemplate(taskDefCloudFormation, 'p3 - container def', this.getSecretDefinitionTemplate(secret.EnvironmentVariable, secret.ParameterKey.replace(/[^\dA-Za-z]/g, '')));
|
||||||
}
|
}
|
||||||
const mappedSecrets = secrets.map((x) => {
|
const secretsMappedToCloudFormationParameters = secrets.map((x) => {
|
||||||
return { ParameterKey: x.ParameterKey.replace(/[^\dA-Za-z]/g, ''), ParameterValue: x.ParameterValue };
|
return { ParameterKey: x.ParameterKey.replace(/[^\dA-Za-z]/g, ''), ParameterValue: x.ParameterValue };
|
||||||
});
|
});
|
||||||
yield CF.createStack({
|
yield CF.createStack({
|
||||||
|
|
@ -458,6 +458,10 @@ class AWSBuildEnvironment {
|
||||||
TemplateBody: taskDefCloudFormation,
|
TemplateBody: taskDefCloudFormation,
|
||||||
Capabilities: ['CAPABILITY_IAM'],
|
Capabilities: ['CAPABILITY_IAM'],
|
||||||
Parameters: [
|
Parameters: [
|
||||||
|
{
|
||||||
|
ParameterKey: 'Environment',
|
||||||
|
ParameterValue: this.baseStackName,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
ParameterKey: 'ImageUrl',
|
ParameterKey: 'ImageUrl',
|
||||||
ParameterValue: image,
|
ParameterValue: image,
|
||||||
|
|
@ -486,7 +490,7 @@ class AWSBuildEnvironment {
|
||||||
ParameterKey: 'BUILDID',
|
ParameterKey: 'BUILDID',
|
||||||
ParameterValue: buildGuid,
|
ParameterValue: buildGuid,
|
||||||
},
|
},
|
||||||
...mappedSecrets,
|
...secretsMappedToCloudFormationParameters,
|
||||||
],
|
],
|
||||||
}).promise();
|
}).promise();
|
||||||
core.info('Creating cloud runner job');
|
core.info('Creating cloud runner job');
|
||||||
|
|
@ -547,7 +551,7 @@ class AWSBuildEnvironment {
|
||||||
StackName: baseStackName,
|
StackName: baseStackName,
|
||||||
};
|
};
|
||||||
const parameters = [
|
const parameters = [
|
||||||
{ ParameterKey: 'EnvironmentName', ParameterValue: 'development' },
|
{ ParameterKey: 'EnvironmentName', ParameterValue: baseStackName },
|
||||||
{ ParameterKey: 'Storage', ParameterValue: `${baseStackName}-storage` },
|
{ ParameterKey: 'Storage', ParameterValue: `${baseStackName}-storage` },
|
||||||
{ ParameterKey: 'Version', ParameterValue: hash },
|
{ ParameterKey: 'Version', ParameterValue: hash },
|
||||||
];
|
];
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -152,7 +152,7 @@ class AWSBuildEnvironment implements CloudRunnerProviderInterface {
|
||||||
this.getSecretDefinitionTemplate(secret.EnvironmentVariable, secret.ParameterKey.replace(/[^\dA-Za-z]/g, '')),
|
this.getSecretDefinitionTemplate(secret.EnvironmentVariable, secret.ParameterKey.replace(/[^\dA-Za-z]/g, '')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const mappedSecrets = secrets.map((x) => {
|
const secretsMappedToCloudFormationParameters = secrets.map((x) => {
|
||||||
return { ParameterKey: x.ParameterKey.replace(/[^\dA-Za-z]/g, ''), ParameterValue: x.ParameterValue };
|
return { ParameterKey: x.ParameterKey.replace(/[^\dA-Za-z]/g, ''), ParameterValue: x.ParameterValue };
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -161,6 +161,10 @@ class AWSBuildEnvironment implements CloudRunnerProviderInterface {
|
||||||
TemplateBody: taskDefCloudFormation,
|
TemplateBody: taskDefCloudFormation,
|
||||||
Capabilities: ['CAPABILITY_IAM'],
|
Capabilities: ['CAPABILITY_IAM'],
|
||||||
Parameters: [
|
Parameters: [
|
||||||
|
{
|
||||||
|
ParameterKey: 'Environment',
|
||||||
|
ParameterValue: this.baseStackName,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
ParameterKey: 'ImageUrl',
|
ParameterKey: 'ImageUrl',
|
||||||
ParameterValue: image,
|
ParameterValue: image,
|
||||||
|
|
@ -189,7 +193,7 @@ class AWSBuildEnvironment implements CloudRunnerProviderInterface {
|
||||||
ParameterKey: 'BUILDID',
|
ParameterKey: 'BUILDID',
|
||||||
ParameterValue: buildGuid,
|
ParameterValue: buildGuid,
|
||||||
},
|
},
|
||||||
...mappedSecrets,
|
...secretsMappedToCloudFormationParameters,
|
||||||
],
|
],
|
||||||
}).promise();
|
}).promise();
|
||||||
core.info('Creating cloud runner job');
|
core.info('Creating cloud runner job');
|
||||||
|
|
@ -256,7 +260,7 @@ class AWSBuildEnvironment implements CloudRunnerProviderInterface {
|
||||||
StackName: baseStackName,
|
StackName: baseStackName,
|
||||||
};
|
};
|
||||||
const parameters: SDK.CloudFormation.Parameter[] = [
|
const parameters: SDK.CloudFormation.Parameter[] = [
|
||||||
{ ParameterKey: 'EnvironmentName', ParameterValue: 'development' },
|
{ ParameterKey: 'EnvironmentName', ParameterValue: baseStackName },
|
||||||
{ ParameterKey: 'Storage', ParameterValue: `${baseStackName}-storage` },
|
{ ParameterKey: 'Storage', ParameterValue: `${baseStackName}-storage` },
|
||||||
{ ParameterKey: 'Version', ParameterValue: hash },
|
{ ParameterKey: 'Version', ParameterValue: hash },
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue