Comparing version 0.0.23 to 0.0.24
@@ -12,2 +12,3 @@ const { program } = require("commander"); | ||
.option("--ecr-ecs-push-new-revision", "tags image, pushes, and creates a new revision") | ||
.option("--ecr-ecs-set-revision", "sets revision for a task") | ||
.option("--ecs-run-on-fargate", "run ecs task on fargate") | ||
@@ -47,3 +48,4 @@ .option("--ecs-task-logs", "read task logs") | ||
.option("--api-gateway-sub-path <sub path>", "api gateway sub path") | ||
.option("--ephemeral-id <ephemeral-id>", "ephemeral id"); | ||
.option("--ephemeral-id <ephemeral-id>", "ephemeral id") | ||
.option("--revision-string <revision-string>", "revision-string"); | ||
@@ -79,2 +81,5 @@ // TODO: deploy lambda function directly without s3 | ||
if (options["ecrEcsSetRevision"]) | ||
Lib.ecrEcsSetRevision(options["taskDefinition"], options["containerName"], options["revisionString"], resultFunc); | ||
if (options["ecsRunOnFargate"]) | ||
@@ -81,0 +86,0 @@ Lib.ecsRunOnFargate(options["taskDefinition"], options["clusterName"], options["environmentVariable"], resultFunc); |
{ | ||
"name": "awsass", | ||
"description": "AWSASS is an assistant to AWS, mostly for running better scripts.", | ||
"version": "0.0.23", | ||
"version": "0.0.24", | ||
"author": "Jsonize", | ||
@@ -6,0 +6,0 @@ "repository": "https://github.com/jsonize/awsass", |
@@ -52,2 +52,72 @@ const AWS = require("aws-sdk"); | ||
ecrEcsSetRevision: function (taskDefinition, containerName, revisionString, callback) { | ||
let findImageIndex = function (images, searchString) { | ||
return images.findIndex(function (image) { | ||
return image.imageDigest === searchString || image.imageTags && image.imageTags.includes(searchString) | ||
}); | ||
}; | ||
const ecs = new AWS.ECS({apiVersion: '2014-11-13'}); | ||
const ecr = new AWS.ECR({apiVersion: '2015-09-21'}); | ||
ecs.describeTaskDefinition({taskDefinition: taskDefinition}, function (err, describeTaskDefinition) { | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
const containerDefinitions = describeTaskDefinition.taskDefinition.containerDefinitions; | ||
let containerDefinition = containerName ? containerDefinitions.find(containerDefinition => containerDefinition.name === containerName) : containerDefinitions[0]; | ||
if (!containerDefinition) { | ||
callback(`Could not find container definition.`); | ||
return; | ||
} | ||
containerName = containerName || containerDefinition.name; | ||
let splt = containerDefinition.image.split(containerDefinition.image.indexOf("@") < 0 ? ":" : "@"); | ||
const imageName = splt[0]; | ||
const imageRevision = splt[1]; | ||
splt = imageName.split("/"); | ||
const repositoryBase = splt[0]; | ||
const repositoryName = splt[1]; | ||
ecr.describeImages({repositoryName: repositoryName}, function (err, describeImages) { | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
const images = describeImages.imageDetails.sort(function (x, y) { | ||
return x.imagePushedAt > y.imagePushedAt ? 1 : (x.imagePushedAt < y.imagePushedAt ? -1 : 0); | ||
}); | ||
const oldImageIndex = findImageIndex(images, imageRevision); | ||
if (oldImageIndex < 0) { | ||
callback(`Could not find current image.`); | ||
return; | ||
} | ||
revisionString = revisionString || "latest"; | ||
let newImageIndex = -1; | ||
switch (revisionString) { | ||
case "-1": | ||
newImageIndex = oldImageIndex - 1; | ||
break; | ||
case "+1": | ||
newImageIndex = oldImageIndex + 1; | ||
break; | ||
case "latest": | ||
newImageIndex = images.length - 1; | ||
break; | ||
case "first": | ||
newImageIndex = 0; | ||
break; | ||
default: | ||
newImageIndex = findImageIndex(images, revisionString); | ||
break; | ||
} | ||
if (newImageIndex < 0 || newImageIndex >= images.length) { | ||
callback(`Could not find new image.`); | ||
return; | ||
} | ||
const newImage = images[newImageIndex]; | ||
const newImageRevision = newImage.imageTags && newImage.imageTags.length > 0 ? newImage.imageTags[0] : newImage.imageDigest; | ||
const newUrl = repositoryBase + "/" + repositoryName + (newImageRevision.indexOf(":") < 0 ? ":" : "@") + newImageRevision; | ||
Module.ecsCreateNewRevisionForContainer(taskDefinition, containerName, newUrl, callback); | ||
}); | ||
}); | ||
}, | ||
ecrLoginDetails: function (callback) { | ||
@@ -54,0 +124,0 @@ const ecr = new AWS.ECR({apiVersion: '2015-09-21'}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37555
731