format
parent
916cd0d9cf
commit
ef6594f59f
|
|
@ -217,8 +217,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
/* eslint-disable no-plusplus */
|
|
||||||
/* eslint-disable no-await-in-loop */
|
|
||||||
const SDK = __importStar(__webpack_require__(71786));
|
const SDK = __importStar(__webpack_require__(71786));
|
||||||
const nanoid_1 = __webpack_require__(39140);
|
const nanoid_1 = __webpack_require__(39140);
|
||||||
const fs = __importStar(__webpack_require__(35747));
|
const fs = __importStar(__webpack_require__(35747));
|
||||||
|
|
@ -228,7 +226,7 @@ class AWS {
|
||||||
static runBuildJob(buildParameters, baseImage) {
|
static runBuildJob(buildParameters, baseImage) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
let buildUid = nanoid_1.nanoid();
|
const buildUid = nanoid_1.nanoid();
|
||||||
yield this.run(buildUid, buildParameters.awsStackName, 'alpine/git', ['/bin/sh'], [
|
yield this.run(buildUid, buildParameters.awsStackName, 'alpine/git', ['/bin/sh'], [
|
||||||
'-c',
|
'-c',
|
||||||
`apk update;
|
`apk update;
|
||||||
|
|
@ -438,10 +436,11 @@ class AWS {
|
||||||
ParameterKey: 'BUILDID',
|
ParameterKey: 'BUILDID',
|
||||||
ParameterValue: buildUid,
|
ParameterValue: buildUid,
|
||||||
},
|
},
|
||||||
].concat(secrets),
|
...secrets
|
||||||
|
],
|
||||||
}).promise();
|
}).promise();
|
||||||
core.info('Creating build cluster...');
|
core.info('Creating build cluster...');
|
||||||
const taskDefStackNameTTL = taskDefStackName + '-ttl';
|
const taskDefStackNameTTL = `${taskDefStackName}-ttl`;
|
||||||
const ttlCloudFormation = fs.readFileSync(`${__dirname}/cloudformation-stack-ttl.yml`, 'utf8');
|
const ttlCloudFormation = fs.readFileSync(`${__dirname}/cloudformation-stack-ttl.yml`, 'utf8');
|
||||||
yield CF.createStack({
|
yield CF.createStack({
|
||||||
StackName: taskDefStackNameTTL,
|
StackName: taskDefStackNameTTL,
|
||||||
|
|
@ -484,7 +483,7 @@ class AWS {
|
||||||
containerOverrides: [
|
containerOverrides: [
|
||||||
{
|
{
|
||||||
name: taskDefStackName,
|
name: taskDefStackName,
|
||||||
environment: environment.concat([{ name: 'BUILDID', value: buildUid }]),
|
environment: [...environment, { name: 'BUILDID', value: buildUid }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
@ -492,8 +491,10 @@ class AWS {
|
||||||
networkConfiguration: {
|
networkConfiguration: {
|
||||||
awsvpcConfiguration: {
|
awsvpcConfiguration: {
|
||||||
subnets: [
|
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) || '',
|
((_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) || '',
|
'',
|
||||||
|
((_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',
|
assignPublicIp: 'ENABLED',
|
||||||
securityGroups: [
|
securityGroups: [
|
||||||
|
|
@ -501,14 +502,14 @@ class AWS {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, undefined).promise();
|
}).promise();
|
||||||
core.info('Build job is starting');
|
core.info('Build job is starting');
|
||||||
try {
|
try {
|
||||||
yield ECS.waitFor('tasksRunning', { tasks: [((_l = task.tasks) === null || _l === void 0 ? void 0 : _l[0].taskArn) || ''], cluster: clusterName }).promise();
|
yield ECS.waitFor('tasksRunning', { tasks: [((_l = task.tasks) === null || _l === void 0 ? void 0 : _l[0].taskArn) || ''], cluster: clusterName }).promise();
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
yield new Promise((resolve) => setTimeout(resolve, 3000));
|
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) || ''],
|
tasks: [((_m = task.tasks) === null || _m === void 0 ? void 0 : _m[0].taskArn) || ''],
|
||||||
cluster: clusterName,
|
cluster: clusterName,
|
||||||
}).promise();
|
}).promise();
|
||||||
|
|
@ -531,7 +532,7 @@ class AWS {
|
||||||
.describeStream({
|
.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) ||
|
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();
|
.promise();
|
||||||
let iterator = (yield kinesis
|
let iterator = (yield kinesis
|
||||||
.getShardIterator({
|
.getShardIterator({
|
||||||
|
|
@ -573,7 +574,7 @@ class AWS {
|
||||||
tasks: [((_t = task.tasks) === null || _t === void 0 ? void 0 : _t[0].taskArn) || ''],
|
tasks: [((_t = task.tasks) === null || _t === void 0 ? void 0 : _t[0].taskArn) || ''],
|
||||||
cluster: clusterName,
|
cluster: clusterName,
|
||||||
}).promise()).tasks) === null || _u === void 0 ? void 0 : _u[0].containers) === null || _v === void 0 ? void 0 : _v[0].exitCode;
|
}).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}`);
|
core.error(`job finished with exit code ${exitCode}`);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -595,9 +596,9 @@ class AWS {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
static onlog(batch) {
|
static onlog(batch) {
|
||||||
batch.forEach((log) => {
|
for (const log of batch) {
|
||||||
core.info(`log: ${log}`);
|
core.info(`log: ${log}`);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.default = AWS;
|
exports.default = AWS;
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1,16 +1,13 @@
|
||||||
/* eslint-disable no-plusplus */
|
|
||||||
/* eslint-disable no-await-in-loop */
|
|
||||||
import * as SDK from 'aws-sdk';
|
import * as SDK from 'aws-sdk';
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as zlib from 'zlib';
|
import * as zlib from 'zlib';
|
||||||
import BuildParameters from './build-parameters';
|
|
||||||
|
|
||||||
class AWS {
|
class AWS {
|
||||||
static async runBuildJob(buildParameters, baseImage) {
|
static async runBuildJob(buildParameters, baseImage) {
|
||||||
try {
|
try {
|
||||||
let buildUid = nanoid();
|
const buildUid = nanoid();
|
||||||
await this.run(
|
await this.run(
|
||||||
buildUid,
|
buildUid,
|
||||||
buildParameters.awsStackName,
|
buildParameters.awsStackName,
|
||||||
|
|
@ -268,11 +265,12 @@ class AWS {
|
||||||
ParameterKey: 'BUILDID',
|
ParameterKey: 'BUILDID',
|
||||||
ParameterValue: buildUid,
|
ParameterValue: buildUid,
|
||||||
},
|
},
|
||||||
].concat(secrets),
|
...secrets
|
||||||
|
],
|
||||||
}).promise();
|
}).promise();
|
||||||
core.info('Creating build cluster...');
|
core.info('Creating build cluster...');
|
||||||
|
|
||||||
const taskDefStackNameTTL = taskDefStackName + '-ttl';
|
const taskDefStackNameTTL = `${taskDefStackName}-ttl`;
|
||||||
const ttlCloudFormation = fs.readFileSync(`${__dirname}/cloudformation-stack-ttl.yml`, 'utf8');
|
const ttlCloudFormation = fs.readFileSync(`${__dirname}/cloudformation-stack-ttl.yml`, 'utf8');
|
||||||
await CF.createStack({
|
await CF.createStack({
|
||||||
StackName: taskDefStackNameTTL,
|
StackName: taskDefStackNameTTL,
|
||||||
|
|
@ -310,40 +308,37 @@ class AWS {
|
||||||
|
|
||||||
const clusterName =
|
const clusterName =
|
||||||
baseResources.StackResources?.find((x) => x.LogicalResourceId === 'ECSCluster')?.PhysicalResourceId || '';
|
baseResources.StackResources?.find((x) => x.LogicalResourceId === 'ECSCluster')?.PhysicalResourceId || '';
|
||||||
const task = await ECS.runTask(
|
const task = await ECS.runTask({
|
||||||
{
|
cluster: clusterName,
|
||||||
cluster: clusterName,
|
taskDefinition:
|
||||||
taskDefinition:
|
taskDefResources.StackResources?.find((x) => x.LogicalResourceId === 'TaskDefinition')?.PhysicalResourceId ||
|
||||||
taskDefResources.StackResources?.find((x) => x.LogicalResourceId === 'TaskDefinition')?.PhysicalResourceId ||
|
'',
|
||||||
'',
|
platformVersion: '1.4.0',
|
||||||
platformVersion: '1.4.0',
|
overrides: {
|
||||||
overrides: {
|
containerOverrides: [
|
||||||
containerOverrides: [
|
{
|
||||||
{
|
name: taskDefStackName,
|
||||||
name: taskDefStackName,
|
environment: [...environment, { name: 'BUILDID', value: buildUid }],
|
||||||
environment: environment.concat([{ 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');
|
core.info('Build job is starting');
|
||||||
|
|
||||||
|
|
@ -351,7 +346,7 @@ class AWS {
|
||||||
await ECS.waitFor('tasksRunning', { tasks: [task.tasks?.[0].taskArn || ''], cluster: clusterName }).promise();
|
await ECS.waitFor('tasksRunning', { tasks: [task.tasks?.[0].taskArn || ''], cluster: clusterName }).promise();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await new Promise((resolve) => setTimeout(resolve, 3000));
|
await new Promise((resolve) => setTimeout(resolve, 3000));
|
||||||
let describeTasks = await ECS.describeTasks({
|
const describeTasks = await ECS.describeTasks({
|
||||||
tasks: [task.tasks?.[0].taskArn || ''],
|
tasks: [task.tasks?.[0].taskArn || ''],
|
||||||
cluster: clusterName,
|
cluster: clusterName,
|
||||||
}).promise();
|
}).promise();
|
||||||
|
|
@ -374,14 +369,11 @@ class AWS {
|
||||||
};
|
};
|
||||||
|
|
||||||
const stream = await kinesis
|
const stream = await kinesis
|
||||||
.describeStream(
|
.describeStream({
|
||||||
{
|
StreamName:
|
||||||
StreamName:
|
taskDefResources.StackResources?.find((x) => x.LogicalResourceId === 'KinesisStream')?.PhysicalResourceId ||
|
||||||
taskDefResources.StackResources?.find((x) => x.LogicalResourceId === 'KinesisStream')?.PhysicalResourceId ||
|
'',
|
||||||
'',
|
})
|
||||||
},
|
|
||||||
undefined,
|
|
||||||
)
|
|
||||||
.promise();
|
.promise();
|
||||||
|
|
||||||
let iterator =
|
let iterator =
|
||||||
|
|
@ -438,7 +430,7 @@ class AWS {
|
||||||
}).promise()
|
}).promise()
|
||||||
).tasks?.[0].containers?.[0].exitCode;
|
).tasks?.[0].containers?.[0].exitCode;
|
||||||
|
|
||||||
if (exitCode != 0) {
|
if (exitCode !== 0) {
|
||||||
core.error(`job finished with exit code ${exitCode}`);
|
core.error(`job finished with exit code ${exitCode}`);
|
||||||
} else {
|
} else {
|
||||||
core.info(`Build job has finished with exit code 0`);
|
core.info(`Build job has finished with exit code 0`);
|
||||||
|
|
@ -464,9 +456,9 @@ class AWS {
|
||||||
}
|
}
|
||||||
|
|
||||||
static onlog(batch) {
|
static onlog(batch) {
|
||||||
batch.forEach((log) => {
|
for (const log of batch) {
|
||||||
core.info(`log: ${log}`);
|
core.info(`log: ${log}`);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export default AWS;
|
export default AWS;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue