unique task def per job

pull/218/head
Frostebite 2021-02-07 00:37:34 +00:00
parent eb1d5c995d
commit b64816eed9
5 changed files with 52 additions and 37 deletions

File diff suppressed because one or more lines are too long

View File

@ -17,6 +17,9 @@ Parameters:
Default: nginx Default: nginx
Description: The url of a docker image that contains the application process that Description: The url of a docker image that contains the application process that
will handle the traffic for this service will handle the traffic for this service
Entrypoint:
Type: CommaDelimitedList
ContainerPort: ContainerPort:
Type: Number Type: Number
Default: 80 Default: 80
@ -70,9 +73,14 @@ Mappings:
# A log group for storing the stdout logs from this service's containers # A log group for storing the stdout logs from this service's containers
Conditions: Conditions:
HasCustomRole: !Not [ !Equals [!Ref 'Role', ''] ] HasCustomRole: !Not [ !Equals [!Ref 'Role', ''] ]
Resources: Resources:
KinesisStream:
Type: AWS::Kinesis::Stream
Properties:
Name: !Ref 'ServiceName'
ShardCount: 1
# The task definition. This is a simple metadata description of what # The task definition. This is a simple metadata description of what
# container to run, and what resource requirements it has. # container to run, and what resource requirements it has.
TaskDefinition: TaskDefinition:
@ -85,12 +93,12 @@ Resources:
Volumes: Volumes:
- Name: efs-data - Name: efs-data
EFSVolumeConfiguration: EFSVolumeConfiguration:
FilesystemId: FilesystemId:
Fn::ImportValue: !Sub ${EnvironmentName}:EfsFileStorageId Fn::ImportValue: !Sub ${EnvironmentName}:EfsFileStorageId
TransitEncryption: ENABLED TransitEncryption: ENABLED
RequiresCompatibilities: RequiresCompatibilities:
- FARGATE - FARGATE
ExecutionRoleArn: ExecutionRoleArn:
Fn::ImportValue: !Sub ${EnvironmentName}:ECSTaskExecutionRole Fn::ImportValue: !Sub ${EnvironmentName}:ECSTaskExecutionRole
TaskRoleArn: TaskRoleArn:
Fn::If: Fn::If:
@ -98,25 +106,28 @@ Resources:
- !Ref 'Role' - !Ref 'Role'
- !Ref "AWS::NoValue" - !Ref "AWS::NoValue"
ContainerDefinitions: ContainerDefinitions:
- Name: !Ref 'ServiceName' - Name: 'LoggingSidecar'
Cpu: !Ref 'ContainerCpu' Cpu: '!Ref LoggingCpu'
Memory: !Ref 'ContainerMemory' Memory: !Ref 'ContainerMemory'
Image: !Ref 'ImageUrl' Image: !Ref 'ImageUrl'
PortMappings: PortMappings:
- ContainerPort: !Ref ContainerPort - ContainerPort: !Ref ContainerPort
HostPort: !Ref ContainerPort HostPort: !Ref ContainerPort
Environment: - Name: !Ref 'ServiceName'
Cpu: !Ref 'ContainerCpu'
Memory: !Ref 'ContainerMemory'
Image: !Ref 'ImageUrl'
Entrypoint: !Ref 'Entrypoint'
Environment:
- Name: ALLOW_EMPTY_PASSWORD - Name: ALLOW_EMPTY_PASSWORD
Value: 'yes' Value: 'yes'
MountPoints: MountPoints:
- SourceVolume: efs-data - SourceVolume: efs-data
ContainerPath: !Ref EFSMountPath ContainerPath: !Ref EFSMountPath
ReadOnly: false ReadOnly: false
LogConfiguration: LogConfiguration:
LogDriver: 'awslogs' LogDriver: 'awslogs'
Options: Options:
awslogs-group: !Ref 'ServiceName' awslogs-group: !Ref 'ServiceName'
awslogs-region: !Ref 'AWS::Region' awslogs-region: !Ref 'AWS::Region'
awslogs-stream-prefix: !Ref 'ServiceName' awslogs-stream-prefix: !Ref 'ServiceName'

View File

@ -21,7 +21,9 @@
"base-64": "^0.1.0", "base-64": "^0.1.0",
"cloudwatch-logs-hose": "0.0.2", "cloudwatch-logs-hose": "0.0.2",
"kubernetes-client": "^9.0.0", "kubernetes-client": "^9.0.0",
"semver": "^7.3.2" "selfsigned": "1.10.8",
"semver": "^7.3.2",
"shortid": "2.2.16"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "7.8.4", "@babel/cli": "7.8.4",

View File

@ -1,10 +1,11 @@
/* eslint-disable no-plusplus */ /* eslint-disable no-plusplus */
/* eslint-disable no-await-in-loop */ /* eslint-disable no-await-in-loop */
import * as SDK from 'aws-sdk'; import * as SDK from 'aws-sdk';
import { CloudWatch, CloudWatchLogs } from 'aws-sdk';
const fs = require('fs'); const fs = require('fs');
const core = require('@actions/core'); const core = require('@actions/core');
const hose = require('cloudwatch-logs-hose'); const Shortid = require('shortid');
class AWS { class AWS {
static async runBuildJob(buildParameters, baseImage) { static async runBuildJob(buildParameters, baseImage) {
@ -23,12 +24,7 @@ class AWS {
buildParameters.awsStackName, buildParameters.awsStackName,
baseImage.toString(), baseImage.toString(),
['bin/bash', '-c', 'echo "test"'], ['bin/bash', '-c', 'echo "test"'],
[ [],
{
name: '',
value: '',
},
],
); );
} }
@ -37,7 +33,7 @@ class AWS {
const CF = new SDK.CloudFormation(); const CF = new SDK.CloudFormation();
const alphanumericImageName = image.toString().replace(/[^\da-z]/gi, ''); const alphanumericImageName = image.toString().replace(/[^\da-z]/gi, '');
const taskDefStackName = `${stackName}-taskDef-${alphanumericImageName}`; const taskDefStackName = `${stackName}-taskDef-${alphanumericImageName}-${new Shortid()}`;
const stackExists = const stackExists =
(await CF.listStacks().promise()).StackSummaries.find( (await CF.listStacks().promise()).StackSummaries.find(
(x) => x.StackName === taskDefStackName, (x) => x.StackName === taskDefStackName,
@ -54,6 +50,10 @@ class AWS {
ParameterKey: 'ImageUrl', ParameterKey: 'ImageUrl',
ParameterValue: image, ParameterValue: image,
}, },
{
ParameterKey: 'Entrypoint',
ParameterValue: commands,
},
], ],
}).promise(); }).promise();
await CF.waitFor('stackCreateComplete', { StackName: taskDefStackName }).promise(); await CF.waitFor('stackCreateComplete', { StackName: taskDefStackName }).promise();
@ -81,7 +81,6 @@ class AWS {
containerOverrides: [ containerOverrides: [
{ {
name: 'example', name: 'example',
command: commands,
environment, environment,
}, },
], ],
@ -113,23 +112,6 @@ class AWS {
// watching logs // watching logs
try {
const source = new hose.Source({
LogGroup: baseResources.StackResources.find((x) => x.LogicalResourceId === 'LogGroup'),
aws: SDK.config,
});
source.on('logs', AWS.onlog);
source.on('error', (error) => {
core.info('Error: ', error);
});
source.open();
} catch (error) {
core.info(error);
}
await ECS.waitFor('tasksStopped', { await ECS.waitFor('tasksStopped', {
cluster: clusterName, cluster: clusterName,
tasks: [task.tasks[0].taskArn], tasks: [task.tasks[0].taskArn],

View File

@ -3939,6 +3939,10 @@ nan@^2.12.1:
version "2.14.1" version "2.14.1"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.1.tgz#d7be34dfa3105b91494c3147089315eff8874b01" resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.1.tgz#d7be34dfa3105b91494c3147089315eff8874b01"
nanoid@^2.1.0:
version "2.1.11"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-2.1.11.tgz#ec24b8a758d591561531b4176a01e3ab4f0f0280"
nanomatch@^1.2.9: nanomatch@^1.2.9:
version "1.2.13" version "1.2.13"
resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119" resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119"
@ -3967,6 +3971,10 @@ node-fetch@^2.3.0:
version "2.6.1" version "2.6.1"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
node-forge@^0.10.0:
version "0.10.0"
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.10.0.tgz#32dea2afb3e9926f02ee5ce8794902691a676bf3"
node-int64@^0.4.0: node-int64@^0.4.0:
version "0.4.0" version "0.4.0"
resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b" resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b"
@ -4764,6 +4772,12 @@ saxes@^3.1.9:
dependencies: dependencies:
xmlchars "^2.1.1" xmlchars "^2.1.1"
selfsigned@1.10.8:
version "1.10.8"
resolved "https://registry.yarnpkg.com/selfsigned/-/selfsigned-1.10.8.tgz#0d17208b7d12c33f8eac85c41835f27fc3d81a30"
dependencies:
node-forge "^0.10.0"
semver-compare@^1.0.0: semver-compare@^1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://registry.yarnpkg.com/semver-compare/-/semver-compare-1.0.0.tgz#0dee216a1c941ab37e9efb1788f6afc5ff5537fc" resolved "https://registry.yarnpkg.com/semver-compare/-/semver-compare-1.0.0.tgz#0dee216a1c941ab37e9efb1788f6afc5ff5537fc"
@ -4833,6 +4847,12 @@ shellwords@^0.1.1:
version "0.1.1" version "0.1.1"
resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b" resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b"
shortid@2.2.16:
version "2.2.16"
resolved "https://registry.yarnpkg.com/shortid/-/shortid-2.2.16.tgz#b742b8f0cb96406fd391c76bfc18a67a57fe5608"
dependencies:
nanoid "^2.1.0"
side-channel@^1.0.2: side-channel@^1.0.2:
version "1.0.2" version "1.0.2"
resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.2.tgz#df5d1abadb4e4bf4af1cd8852bf132d2f7876947" resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.2.tgz#df5d1abadb4e4bf4af1cd8852bf132d2f7876947"