fargate-helper
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -9,2 +9,5 @@ #!/usr/bin/env node | ||
console.log("DONE"); | ||
}).catch((e) => { | ||
console.error(e); | ||
process.exit(1); | ||
}); | ||
@@ -11,0 +14,0 @@ |
@@ -35,6 +35,6 @@ const SecretsManager = require("./SecretsManager"); | ||
} | ||
static str(key, defaultValue) { | ||
if (Config.options[key]) { | ||
console.log("OPT " + key + ":" + Config.options[key]); | ||
// console.log("OPT " + key + ":" + Config.options[key]); | ||
return Config.options[key]; | ||
@@ -44,3 +44,3 @@ } | ||
if (Config.defaults[key]) { | ||
console.log("SECRETS " + key + ":" + Config.defaults[key]); | ||
// console.log("SECRETS " + key + ":" + Config.defaults[key]); | ||
return Config.defaults[key]; | ||
@@ -50,3 +50,3 @@ } | ||
if (process.env[key]) { | ||
console.log("ENV " + key + ":" + process.env[key]); | ||
// console.log("ENV " + key + ":" + process.env[key]); | ||
return process.env[key]; | ||
@@ -53,0 +53,0 @@ } |
@@ -59,3 +59,2 @@ const AWS = require("aws-sdk"); | ||
console.log("SERVICE: " + JSON.stringify(servicesResponse, null, 2)); | ||
if (servicesResponse.services.length === 0) { | ||
@@ -62,0 +61,0 @@ return undefined; |
@@ -8,3 +8,2 @@ const AWS = require("aws-sdk"); | ||
class FargateHelper { | ||
// Turns process arguments into JSON | ||
static async run() { | ||
@@ -44,6 +43,5 @@ AWS.config.update({ region: process.env.AWS_DEFAULT_REGION }); | ||
return FargateHelper._service(); | ||
}else if (action === "update") { | ||
} else if (action === "update") { | ||
return FargateHelper._update(); | ||
} | ||
} | ||
} | ||
@@ -57,3 +55,3 @@ | ||
let service = await ECSManager.describeService(serviceName); | ||
if (service) { | ||
if (service && !service.status === "INACTIVE") { | ||
throw new Error("Service already exists: " + serviceName + ". Delete or update instead."); | ||
@@ -63,2 +61,3 @@ } | ||
// Register the task definition first | ||
console.log("CREATE 1) Register Task Definition"); | ||
const taskDefinition = await ECSManager.registerTaskDefinition(); | ||
@@ -69,2 +68,3 @@ const taskDefinitionArn = taskDefinition.taskDefinition.taskDefinitionArn; | ||
// We create a target group to associate this service with an Elastic Load Balancer | ||
console.log("CREATE 2) Create Target Group"); | ||
const targetGroupResponse = await ELBManager.createTargetGroup(); | ||
@@ -77,2 +77,3 @@ console.log("TargetGroupResponse: " + JSON.stringify(targetGroupResponse, null, 2)); | ||
// This can be changed online in the ECS console | ||
console.log("CREATE 3) Create Rule"); | ||
const rules = await ELBManager.createRule(targetGroupArn); | ||
@@ -82,2 +83,3 @@ console.log("Rules: " + JSON.stringify(rules, null, 2)); | ||
// Create the service | ||
console.log("CREATE 4) Create Service"); | ||
service = await ECSManager.createService(targetGroupArn, taskDefinitionArn); | ||
@@ -144,6 +146,7 @@ return service; | ||
let service = await ECSManager.describeService(serviceName); | ||
if (service) { | ||
FargateHelper._update(); | ||
// If the service exists, and it is not inactive, then update | ||
if (service && !service.status === "INACTIVE") { | ||
return FargateHelper._update(); | ||
} else { | ||
FargateHelper._create(); | ||
return FargateHelper._create(); | ||
} | ||
@@ -156,12 +159,20 @@ } | ||
let service = await ECSManager.describeService(serviceName); | ||
if (!service) { | ||
throw new Error("Service does not exist: " + serviceName + ". Create instead."); | ||
} else if (service.status === "DRAINING") { | ||
throw new Error("Service is still draining. Cannot update."); | ||
} else if (service.status === "INACTIVE") { | ||
throw new Error("Service has been deleted. Try creating it again instead."); | ||
} | ||
console.log("UPDATE Status: " + service.status); | ||
// Register the task definition first | ||
console.log("UPDATE 1) Register Task Definition"); | ||
const taskDefinition = await ECSManager.registerTaskDefinition(); | ||
const taskDefinitionArn = taskDefinition.taskDefinition.taskDefinitionArn; | ||
let service = await ECSManager.describeService(serviceName); | ||
if (!service) { | ||
throw new Error("Service does not exist: " + serviceName + ". Create instead."); | ||
} | ||
// We need to call update service to use a new task definition | ||
console.log("UPDATE 2) Update Service"); | ||
service = await ECSManager.updateService(taskDefinitionArn); | ||
@@ -168,0 +179,0 @@ return service; |
@@ -10,3 +10,3 @@ const AWS = require("aws-sdk"); | ||
const secret = await client.getSecretValue({SecretId: secretName}).promise(); | ||
console.log("Secret: " + secret.SecretString); | ||
// console.log("Secret: " + secret.SecretString); | ||
return secret.SecretString; | ||
@@ -13,0 +13,0 @@ } |
{ | ||
"name": "fargate-helper", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Helper scripts for deploying to Fargate", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
26453
517
14