pull/235/head
mdugdale 2021-04-03 01:43:03 +01:00
parent a3cf12c7c4
commit c857c1af84
3 changed files with 25 additions and 24 deletions

22
dist/index.js vendored
View File

@ -362,14 +362,14 @@ class AWS {
ParameterValue: buildParameters.androidKeyaliasPass ? buildParameters.androidKeyaliasPass : '0', ParameterValue: buildParameters.androidKeyaliasPass ? buildParameters.androidKeyaliasPass : '0',
}, },
]); ]);
core.info('starting part 3/4 (zip and publish latest Library to cache)'); core.info('starting part 3/4 (zip build and latest Library for caching)');
// Cleanup // Cleanup
yield this.run(buildUid, buildParameters.awsStackName, 'alpine', ['/bin/sh'], [ yield this.run(buildUid, buildParameters.awsStackName, 'alpine', ['/bin/sh'], [
'-c', '-c',
` `
apk update; apk update;
apk add zip apk add zip
zip -r ./${buildUid}/Library/. ./cache/lib-${buildUid}.zip zip -r ./${buildUid}/Library/* ./cache/lib-${buildUid}.zip
zip -r ./${buildUid}/output.zip ./${buildUid}/repo/build zip -r ./${buildUid}/output.zip ./${buildUid}/repo/build
ls ls
`, `,
@ -508,7 +508,7 @@ class AWS {
StackName: taskDefStackName, StackName: taskDefStackName,
}).promise(); }).promise();
const baseResources = yield CF.describeStackResources({ StackName: stackName }).promise(); const baseResources = yield CF.describeStackResources({ StackName: stackName }).promise();
core.info('Build cluster created successfully (skipping waiting for cleanup cluster to start)'); core.info('Build cluster created successfully (skipping wait for cleanup cluster to create)');
return { return {
taskDefStackName, taskDefStackName,
taskDefCloudFormation, taskDefCloudFormation,
@ -522,14 +522,14 @@ class AWS {
static runTask(taskDef, ECS, CF, environment, buildUid) { static runTask(taskDef, ECS, CF, environment, buildUid) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s; var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const clusterName = ((_b = (_a = taskDef.baseResources.StackResources) === null || _a === void 0 ? void 0 : _a.find((x) => x.LogicalResourceId === 'ECSCluster')) === null || _b === void 0 ? void 0 : _b.PhysicalResourceId) || ''; const cluster = ((_b = (_a = taskDef.baseResources.StackResources) === null || _a === void 0 ? void 0 : _a.find((x) => x.LogicalResourceId === 'ECSCluster')) === null || _b === void 0 ? void 0 : _b.PhysicalResourceId) || '';
const taskDefinition = ((_d = (_c = taskDef.taskDefResources.StackResources) === null || _c === void 0 ? void 0 : _c.find((x) => x.LogicalResourceId === 'TaskDefinition')) === null || _d === void 0 ? void 0 : _d.PhysicalResourceId) || ''; const taskDefinition = ((_d = (_c = taskDef.taskDefResources.StackResources) === null || _c === void 0 ? void 0 : _c.find((x) => x.LogicalResourceId === 'TaskDefinition')) === null || _d === void 0 ? void 0 : _d.PhysicalResourceId) || '';
const SubnetOne = ((_f = (_e = taskDef.baseResources.StackResources) === null || _e === void 0 ? void 0 : _e.find((x) => x.LogicalResourceId === 'PublicSubnetOne')) === null || _f === void 0 ? void 0 : _f.PhysicalResourceId) || ''; const SubnetOne = ((_f = (_e = taskDef.baseResources.StackResources) === null || _e === void 0 ? void 0 : _e.find((x) => x.LogicalResourceId === 'PublicSubnetOne')) === null || _f === void 0 ? void 0 : _f.PhysicalResourceId) || '';
const SubnetTwo = ((_h = (_g = taskDef.baseResources.StackResources) === null || _g === void 0 ? void 0 : _g.find((x) => x.LogicalResourceId === 'PublicSubnetTwo')) === null || _h === void 0 ? void 0 : _h.PhysicalResourceId) || ''; const SubnetTwo = ((_h = (_g = taskDef.baseResources.StackResources) === null || _g === void 0 ? void 0 : _g.find((x) => x.LogicalResourceId === 'PublicSubnetTwo')) === null || _h === void 0 ? void 0 : _h.PhysicalResourceId) || '';
const ContainerSecurityGroup = ((_k = (_j = taskDef.baseResources.StackResources) === null || _j === void 0 ? void 0 : _j.find((x) => x.LogicalResourceId === 'ContainerSecurityGroup')) === null || _k === void 0 ? void 0 : _k.PhysicalResourceId) || ''; const ContainerSecurityGroup = ((_k = (_j = taskDef.baseResources.StackResources) === null || _j === void 0 ? void 0 : _j.find((x) => x.LogicalResourceId === 'ContainerSecurityGroup')) === null || _k === void 0 ? void 0 : _k.PhysicalResourceId) || '';
const streamName = ((_m = (_l = taskDef.taskDefResources.StackResources) === null || _l === void 0 ? void 0 : _l.find((x) => x.LogicalResourceId === 'KinesisStream')) === null || _m === void 0 ? void 0 : _m.PhysicalResourceId) || ''; const streamName = ((_m = (_l = taskDef.taskDefResources.StackResources) === null || _l === void 0 ? void 0 : _l.find((x) => x.LogicalResourceId === 'KinesisStream')) === null || _m === void 0 ? void 0 : _m.PhysicalResourceId) || '';
const task = yield ECS.runTask({ const task = yield ECS.runTask({
cluster: clusterName, cluster,
taskDefinition, taskDefinition,
platformVersion: '1.4.0', platformVersion: '1.4.0',
overrides: { overrides: {
@ -552,24 +552,24 @@ class AWS {
core.info('Build job is starting'); core.info('Build job is starting');
const taskArn = ((_o = task.tasks) === null || _o === void 0 ? void 0 : _o[0].taskArn) || ''; const taskArn = ((_o = task.tasks) === null || _o === void 0 ? void 0 : _o[0].taskArn) || '';
try { try {
yield ECS.waitFor('tasksRunning', { tasks: [taskArn], cluster: clusterName }).promise(); yield ECS.waitFor('tasksRunning', { tasks: [taskArn], cluster }).promise();
} }
catch (error) { catch (error) {
yield new Promise((resolve) => setTimeout(resolve, 3000)); yield new Promise((resolve) => setTimeout(resolve, 3000));
const describeTasks = yield ECS.describeTasks({ const describeTasks = yield ECS.describeTasks({
tasks: [taskArn], tasks: [taskArn],
cluster: clusterName, cluster,
}).promise(); }).promise();
core.info(`Build job has ended ${(_q = (_p = describeTasks.tasks) === null || _p === void 0 ? void 0 : _p[0].containers) === null || _q === void 0 ? void 0 : _q[0].lastStatus}`); core.info(`Build job has ended ${(_q = (_p = describeTasks.tasks) === null || _p === void 0 ? void 0 : _p[0].containers) === null || _q === void 0 ? void 0 : _q[0].lastStatus}`);
core.setFailed(error); core.setFailed(error);
core.error(error); core.error(error);
} }
core.info(`Build job is running`); core.info(`Build job is running`);
yield this.streamLogsUntilTaskStops(ECS, CF, taskDef, clusterName, taskArn, streamName); yield this.streamLogsUntilTaskStops(ECS, CF, taskDef, cluster, taskArn, streamName);
yield ECS.waitFor('tasksStopped', { cluster: clusterName, tasks: [taskArn] }).promise(); yield ECS.waitFor('tasksStopped', { cluster, tasks: [taskArn] }).promise();
const exitCode = (_s = (_r = (yield ECS.describeTasks({ const exitCode = (_s = (_r = (yield ECS.describeTasks({
tasks: [taskArn], tasks: [taskArn],
cluster: clusterName, cluster,
}).promise()).tasks) === null || _r === void 0 ? void 0 : _r[0].containers) === null || _s === void 0 ? void 0 : _s[0].exitCode; }).promise()).tasks) === null || _r === void 0 ? void 0 : _r[0].containers) === null || _s === void 0 ? void 0 : _s[0].exitCode;
if (exitCode !== 0) { if (exitCode !== 0) {
core.error(`job failed with exit code ${exitCode}`); core.error(`job failed with exit code ${exitCode}`);
@ -606,7 +606,7 @@ class AWS {
yield CF.waitFor('stackCreateComplete', { StackName: taskDef.taskDefStackNameTTL }).promise(); yield CF.waitFor('stackCreateComplete', { StackName: taskDef.taskDefStackNameTTL }).promise();
core.info(`Task status is ${yield getTaskStatus()}`); core.info(`Task status is ${yield getTaskStatus()}`);
const logBaseUrl = `https://console.aws.amazon.com/cloudwatch/home?region=${SDK.config.region}#logsV2:log-groups/${taskDef.taskDefStackName}`; const logBaseUrl = `https://console.aws.amazon.com/cloudwatch/home?region=${SDK.config.region}#logsV2:log-groups/${taskDef.taskDefStackName}`;
core.info(`You can also watch the logs at AWS Cloud Watch: ${logBaseUrl}`); core.info(`You can also see the logs at AWS Cloud Watch: ${logBaseUrl}`);
let readingLogs = true; let readingLogs = true;
while (readingLogs) { while (readingLogs) {
yield new Promise((resolve) => setTimeout(resolve, 1500)); yield new Promise((resolve) => setTimeout(resolve, 1500));

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -167,7 +167,7 @@ class AWS {
}, },
], ],
); );
core.info('starting part 3/4 (zip and publish latest Library to cache)'); core.info('starting part 3/4 (zip build and latest Library for caching)');
// Cleanup // Cleanup
await this.run( await this.run(
buildUid, buildUid,
@ -179,7 +179,7 @@ class AWS {
` `
apk update; apk update;
apk add zip apk add zip
zip -r ./${buildUid}/Library/. ./cache/lib-${buildUid}.zip zip -r ./${buildUid}/Library/* ./cache/lib-${buildUid}.zip
zip -r ./${buildUid}/output.zip ./${buildUid}/repo/build zip -r ./${buildUid}/output.zip ./${buildUid}/repo/build
ls ls
`, `,
@ -367,7 +367,7 @@ class AWS {
const baseResources = await CF.describeStackResources({ StackName: stackName }).promise(); const baseResources = await CF.describeStackResources({ StackName: stackName }).promise();
core.info('Build cluster created successfully (skipping waiting for cleanup cluster to start)'); core.info('Build cluster created successfully (skipping wait for cleanup cluster to create)');
return { return {
taskDefStackName, taskDefStackName,
@ -380,8 +380,9 @@ class AWS {
} }
static async runTask(taskDef, ECS, CF, environment, buildUid) { static async runTask(taskDef, ECS, CF, environment, buildUid) {
const clusterName = const cluster =
taskDef.baseResources.StackResources?.find((x) => x.LogicalResourceId === 'ECSCluster')?.PhysicalResourceId || ''; taskDef.baseResources.StackResources?.find((x) => x.LogicalResourceId === 'ECSCluster')
?.PhysicalResourceId || '';
const taskDefinition = const taskDefinition =
taskDef.taskDefResources.StackResources?.find((x) => x.LogicalResourceId === 'TaskDefinition') taskDef.taskDefResources.StackResources?.find((x) => x.LogicalResourceId === 'TaskDefinition')
?.PhysicalResourceId || ''; ?.PhysicalResourceId || '';
@ -399,7 +400,7 @@ class AWS {
?.PhysicalResourceId || ''; ?.PhysicalResourceId || '';
const task = await ECS.runTask({ const task = await ECS.runTask({
cluster: clusterName, cluster,
taskDefinition, taskDefinition,
platformVersion: '1.4.0', platformVersion: '1.4.0',
overrides: { overrides: {
@ -424,24 +425,24 @@ class AWS {
const taskArn = task.tasks?.[0].taskArn || ''; const taskArn = task.tasks?.[0].taskArn || '';
try { try {
await ECS.waitFor('tasksRunning', { tasks: [taskArn], cluster: clusterName }).promise(); await ECS.waitFor('tasksRunning', { tasks: [taskArn], cluster }).promise();
} catch (error) { } catch (error) {
await new Promise((resolve) => setTimeout(resolve, 3000)); await new Promise((resolve) => setTimeout(resolve, 3000));
const describeTasks = await ECS.describeTasks({ const describeTasks = await ECS.describeTasks({
tasks: [taskArn], tasks: [taskArn],
cluster: clusterName, cluster,
}).promise(); }).promise();
core.info(`Build job has ended ${describeTasks.tasks?.[0].containers?.[0].lastStatus}`); core.info(`Build job has ended ${describeTasks.tasks?.[0].containers?.[0].lastStatus}`);
core.setFailed(error); core.setFailed(error);
core.error(error); core.error(error);
} }
core.info(`Build job is running`); core.info(`Build job is running`);
await this.streamLogsUntilTaskStops(ECS, CF, taskDef, clusterName, taskArn, streamName); await this.streamLogsUntilTaskStops(ECS, CF, taskDef, cluster, taskArn, streamName);
await ECS.waitFor('tasksStopped', { cluster: clusterName, tasks: [taskArn] }).promise(); await ECS.waitFor('tasksStopped', { cluster, tasks: [taskArn] }).promise();
const exitCode = ( const exitCode = (
await ECS.describeTasks({ await ECS.describeTasks({
tasks: [taskArn], tasks: [taskArn],
cluster: clusterName, cluster,
}).promise() }).promise()
).tasks?.[0].containers?.[0].exitCode; ).tasks?.[0].containers?.[0].exitCode;
if (exitCode !== 0) { if (exitCode !== 0) {
@ -485,7 +486,7 @@ class AWS {
core.info(`Task status is ${await getTaskStatus()}`); core.info(`Task status is ${await getTaskStatus()}`);
const logBaseUrl = `https://console.aws.amazon.com/cloudwatch/home?region=${SDK.config.region}#logsV2:log-groups/${taskDef.taskDefStackName}`; const logBaseUrl = `https://console.aws.amazon.com/cloudwatch/home?region=${SDK.config.region}#logsV2:log-groups/${taskDef.taskDefStackName}`;
core.info(`You can also watch the logs at AWS Cloud Watch: ${logBaseUrl}`); core.info(`You can also see the logs at AWS Cloud Watch: ${logBaseUrl}`);
let readingLogs = true; let readingLogs = true;
while (readingLogs) { while (readingLogs) {