pull/235/head
mdugdale 2021-03-29 00:57:35 +01:00
parent 916cd0d9cf
commit ef6594f59f
3 changed files with 57 additions and 64 deletions

29
dist/index.js vendored
View File

@ -217,8 +217,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
/* eslint-disable no-plusplus */
/* eslint-disable no-await-in-loop */
const SDK = __importStar(__webpack_require__(71786));
const nanoid_1 = __webpack_require__(39140);
const fs = __importStar(__webpack_require__(35747));
@ -228,7 +226,7 @@ class AWS {
static runBuildJob(buildParameters, baseImage) {
return __awaiter(this, void 0, void 0, function* () {
try {
let buildUid = nanoid_1.nanoid();
const buildUid = nanoid_1.nanoid();
yield this.run(buildUid, buildParameters.awsStackName, 'alpine/git', ['/bin/sh'], [
'-c',
`apk update;
@ -438,10 +436,11 @@ class AWS {
ParameterKey: 'BUILDID',
ParameterValue: buildUid,
},
].concat(secrets),
...secrets
],
}).promise();
core.info('Creating build cluster...');
const taskDefStackNameTTL = taskDefStackName + '-ttl';
const taskDefStackNameTTL = `${taskDefStackName}-ttl`;
const ttlCloudFormation = fs.readFileSync(`${__dirname}/cloudformation-stack-ttl.yml`, 'utf8');
yield CF.createStack({
StackName: taskDefStackNameTTL,
@ -484,7 +483,7 @@ class AWS {
containerOverrides: [
{
name: taskDefStackName,
environment: environment.concat([{ name: 'BUILDID', value: buildUid }]),
environment: [...environment, { name: 'BUILDID', value: buildUid }],
},
],
},
@ -492,8 +491,10 @@ class AWS {
networkConfiguration: {
awsvpcConfiguration: {
subnets: [
((_f = (_e = baseResources.StackResources) === null || _e === void 0 ? void 0 : _e.find((x) => x.LogicalResourceId === 'PublicSubnetOne')) === null || _f === void 0 ? void 0 : _f.PhysicalResourceId) || '',
((_h = (_g = baseResources.StackResources) === null || _g === void 0 ? void 0 : _g.find((x) => x.LogicalResourceId === 'PublicSubnetTwo')) === null || _h === void 0 ? void 0 : _h.PhysicalResourceId) || '',
((_f = (_e = baseResources.StackResources) === null || _e === void 0 ? void 0 : _e.find((x) => x.LogicalResourceId === 'PublicSubnetOne')) === null || _f === void 0 ? void 0 : _f.PhysicalResourceId) ||
'',
((_h = (_g = baseResources.StackResources) === null || _g === void 0 ? void 0 : _g.find((x) => x.LogicalResourceId === 'PublicSubnetTwo')) === null || _h === void 0 ? void 0 : _h.PhysicalResourceId) ||
'',
],
assignPublicIp: 'ENABLED',
securityGroups: [
@ -501,14 +502,14 @@ class AWS {
],
},
},
}, undefined).promise();
}).promise();
core.info('Build job is starting');
try {
yield ECS.waitFor('tasksRunning', { tasks: [((_l = task.tasks) === null || _l === void 0 ? void 0 : _l[0].taskArn) || ''], cluster: clusterName }).promise();
}
catch (error) {
yield new Promise((resolve) => setTimeout(resolve, 3000));
let describeTasks = yield ECS.describeTasks({
const describeTasks = yield ECS.describeTasks({
tasks: [((_m = task.tasks) === null || _m === void 0 ? void 0 : _m[0].taskArn) || ''],
cluster: clusterName,
}).promise();
@ -531,7 +532,7 @@ class AWS {
.describeStream({
StreamName: ((_r = (_q = taskDefResources.StackResources) === null || _q === void 0 ? void 0 : _q.find((x) => x.LogicalResourceId === 'KinesisStream')) === null || _r === void 0 ? void 0 : _r.PhysicalResourceId) ||
'',
}, undefined)
})
.promise();
let iterator = (yield kinesis
.getShardIterator({
@ -573,7 +574,7 @@ class AWS {
tasks: [((_t = task.tasks) === null || _t === void 0 ? void 0 : _t[0].taskArn) || ''],
cluster: clusterName,
}).promise()).tasks) === null || _u === void 0 ? void 0 : _u[0].containers) === null || _v === void 0 ? void 0 : _v[0].exitCode;
if (exitCode != 0) {
if (exitCode !== 0) {
core.error(`job finished with exit code ${exitCode}`);
}
else {
@ -595,9 +596,9 @@ class AWS {
});
}
static onlog(batch) {
batch.forEach((log) => {
for (const log of batch) {
core.info(`log: ${log}`);
});
}
}
}
exports.default = AWS;

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -1,16 +1,13 @@
/* eslint-disable no-plusplus */
/* eslint-disable no-await-in-loop */
import * as SDK from 'aws-sdk';
import { nanoid } from 'nanoid';
import * as fs from 'fs';
import * as core from '@actions/core';
import * as zlib from 'zlib';
import BuildParameters from './build-parameters';
class AWS {
static async runBuildJob(buildParameters, baseImage) {
try {
let buildUid = nanoid();
const buildUid = nanoid();
await this.run(
buildUid,
buildParameters.awsStackName,
@ -268,11 +265,12 @@ class AWS {
ParameterKey: 'BUILDID',
ParameterValue: buildUid,
},
].concat(secrets),
...secrets
],
}).promise();
core.info('Creating build cluster...');
const taskDefStackNameTTL = taskDefStackName + '-ttl';
const taskDefStackNameTTL = `${taskDefStackName}-ttl`;
const ttlCloudFormation = fs.readFileSync(`${__dirname}/cloudformation-stack-ttl.yml`, 'utf8');
await CF.createStack({
StackName: taskDefStackNameTTL,
@ -310,40 +308,37 @@ class AWS {
const clusterName =
baseResources.StackResources?.find((x) => x.LogicalResourceId === 'ECSCluster')?.PhysicalResourceId || '';
const task = await ECS.runTask(
{
cluster: clusterName,
taskDefinition:
taskDefResources.StackResources?.find((x) => x.LogicalResourceId === 'TaskDefinition')?.PhysicalResourceId ||
'',
platformVersion: '1.4.0',
overrides: {
containerOverrides: [
{
name: taskDefStackName,
environment: environment.concat([{ name: 'BUILDID', value: buildUid }]),
},
const task = await ECS.runTask({
cluster: clusterName,
taskDefinition:
taskDefResources.StackResources?.find((x) => x.LogicalResourceId === 'TaskDefinition')?.PhysicalResourceId ||
'',
platformVersion: '1.4.0',
overrides: {
containerOverrides: [
{
name: taskDefStackName,
environment: [...environment, { name: 'BUILDID', value: buildUid }],
},
],
},
launchType: 'FARGATE',
networkConfiguration: {
awsvpcConfiguration: {
subnets: [
baseResources.StackResources?.find((x) => x.LogicalResourceId === 'PublicSubnetOne')?.PhysicalResourceId ||
'',
baseResources.StackResources?.find((x) => x.LogicalResourceId === 'PublicSubnetTwo')?.PhysicalResourceId ||
'',
],
assignPublicIp: 'ENABLED',
securityGroups: [
baseResources.StackResources?.find((x) => x.LogicalResourceId === 'ContainerSecurityGroup')
?.PhysicalResourceId || '',
],
},
launchType: 'FARGATE',
networkConfiguration: {
awsvpcConfiguration: {
subnets: [
baseResources.StackResources?.find((x) => x.LogicalResourceId === 'PublicSubnetOne')
?.PhysicalResourceId || '',
baseResources.StackResources?.find((x) => x.LogicalResourceId === 'PublicSubnetTwo')
?.PhysicalResourceId || '',
],
assignPublicIp: 'ENABLED',
securityGroups: [
baseResources.StackResources?.find((x) => x.LogicalResourceId === 'ContainerSecurityGroup')
?.PhysicalResourceId || '',
],
},
},
},
undefined,
).promise();
}).promise();
core.info('Build job is starting');
@ -351,7 +346,7 @@ class AWS {
await ECS.waitFor('tasksRunning', { tasks: [task.tasks?.[0].taskArn || ''], cluster: clusterName }).promise();
} catch (error) {
await new Promise((resolve) => setTimeout(resolve, 3000));
let describeTasks = await ECS.describeTasks({
const describeTasks = await ECS.describeTasks({
tasks: [task.tasks?.[0].taskArn || ''],
cluster: clusterName,
}).promise();
@ -374,14 +369,11 @@ class AWS {
};
const stream = await kinesis
.describeStream(
{
StreamName:
taskDefResources.StackResources?.find((x) => x.LogicalResourceId === 'KinesisStream')?.PhysicalResourceId ||
'',
},
undefined,
)
.describeStream({
StreamName:
taskDefResources.StackResources?.find((x) => x.LogicalResourceId === 'KinesisStream')?.PhysicalResourceId ||
'',
})
.promise();
let iterator =
@ -438,7 +430,7 @@ class AWS {
}).promise()
).tasks?.[0].containers?.[0].exitCode;
if (exitCode != 0) {
if (exitCode !== 0) {
core.error(`job finished with exit code ${exitCode}`);
} else {
core.info(`Build job has finished with exit code 0`);
@ -464,9 +456,9 @@ class AWS {
}
static onlog(batch) {
batch.forEach((log) => {
for (const log of batch) {
core.info(`log: ${log}`);
});
}
}
}
export default AWS;