Skip to content

Commit

Permalink
dom ecs imageTagVersionRetrieval (#59)
Browse files Browse the repository at this point in the history
* update eslint config
* Added image name retrieval
  • Loading branch information
martdo02 authored Oct 24, 2023
1 parent 54d9bba commit a53b6c8
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 22 deletions.
13 changes: 0 additions & 13 deletions .eslintrc.js

This file was deleted.

22 changes: 22 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true
},
"extends": ["standard"],
"parserOptions": {
"ecmaVersion": "latest"
},
"rules": {
"indent": ["error", 4],
"space-before-function-paren": [
"error",
{
"anonymous": "always",
"named": "never",
"asyncArrow": "always"
}
]
}
}
5 changes: 4 additions & 1 deletion packages/aws/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,10 @@ If a queue name is used, a regex search will be done to find the queue.

### `When at least one task is running for service {string} in cluster {string}`

Checks if the service in a cluster has at least one task running on ecs
Checks if the service in an AWS cluster has at least one task running on ECS. Returns the number of running tasks to `lastRun`

### `When image name for service {string} in cluster {string} is retrieved`
Retrieves the task definition image name / version of the running service in the cluster and set it to `lastRun`. Fails if the service is not running, or if there are no tasks running

### `When ecs taskDefinition {string} exists`
### `When ecs taskDefinition {string} does not exist`
Expand Down
8 changes: 6 additions & 2 deletions packages/aws/features/ecs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@
# When ecs taskDefinition "telematics-us-qa-fcra-vei-fgs-000000" exists
# And ecs taskDefinition "telematics-us-qa-fcra-vei-fgs-000003" does not exist

# Scenario:
# When information from ecs cluster "telematics-us-qa-fcra-ecs-cluster" is retrieved
# Scenario: Get ECS infomation
# When information from ecs cluster "telematics-us-qa-fcra-ecs-cluster" is retrieved

# Scenario: Get image name for service
# Given set "servicePrefix" to "telematics-us-qa"
# When image name for service '${servicePrefix}-kia-tno-fgs-0' in cluster '${servicePrefix}-kia-ecs-cluster' is retrieved
4 changes: 2 additions & 2 deletions packages/aws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publishConfig": {
"access": "public"
},
"version": "2.2.1",
"version": "2.2.2",
"description": "AWS steps for MAF. This contains S3, DynamoDB, SQS, ECS, Cloudwatch, and Lambda stepDefinitions",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -39,5 +39,5 @@
"multiple-cucumber-html-reporter": "^3.5.0",
"nyc": "^15.1.0"
},
"gitHead": "9c565ac48ddb32311b115a463c45625de3ff29e4"
"gitHead": "c1cb2220ce18a8e3ceee4b375950a0beec4f3a6f"
}
34 changes: 30 additions & 4 deletions packages/aws/stepDefinitions/ecs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { setDefaultTimeout } = require('@cucumber/cucumber')
const { MAFWhen, performJSONObjectTransform, filltemplate } = require('@ln-maf/core')
const { ECSClient, ListTaskDefinitionsCommand, ListClustersCommand, RunTaskCommand, DescribeClustersCommand, DescribeServicesCommand } = require('@aws-sdk/client-ecs')
const { ECSClient, ListTaskDefinitionsCommand, ListClustersCommand, RunTaskCommand, DescribeClustersCommand, DescribeServicesCommand, DescribeTaskDefinitionCommand } = require('@aws-sdk/client-ecs')

setDefaultTimeout(15 * 60 * 1000)

Expand Down Expand Up @@ -198,19 +198,45 @@ MAFWhen('ecs run-task is performed', async function () {

/**
* Check that at least one task for a service is running
* Returns the number of running tasks
* @param {String} serviceName the name of the service
* @param {String} clusterName the name of the cluster
*/
MAFWhen('at least one task is running for service {string} in cluster {string}', async function (serviceName, clusterName) {
serviceName = filltemplate(serviceName, this.results)
clusterName = filltemplate(clusterName, this.results)
const ecsClient = new ECSClient({ maxAttempts: 2 })
const res = await ecsClient.send(new DescribeServicesCommand({
const serviceDetails = await ecsClient.send(new DescribeServicesCommand({
cluster: clusterName,
services: [serviceName]
}))
if (res.services.length === 0) {
if (serviceDetails.services.length === 0) {
throw new Error('Can\'t find service ' + serviceName + ' in cluster ' + clusterName)
}
if (res.services[0].runningCount < 1) {
const runningCount = serviceDetails.services[0].runningCount
if (runningCount < 1) {
throw new Error('Service ' + serviceName + ' is not currently running in cluster ' + clusterName)
}
return runningCount
})

/**
* Retrieves the image name / version of the running task in the service
* Fails if the service is not running, or if there are no tasks running
* @param {String} serviceName the name of the service
* @param {String} clusterName the name of the cluster
*/
MAFWhen('image name for service {string} in cluster {string} is retrieved', async function (serviceName, clusterName) {
serviceName = filltemplate(serviceName, this.results)
clusterName = filltemplate(clusterName, this.results)
const serviceDetails = await ecsClient.send(new DescribeServicesCommand({
cluster: clusterName,
services: [serviceName]
}))
if (serviceDetails.services[0].runningCount <= 0) {
throw new Error('Service ' + serviceName + ' is not currently running in cluster ' + clusterName)
}
const taskDefinitionDetails = await ecsClient.send(new DescribeTaskDefinitionCommand({ taskDefinition: serviceDetails.services[0].taskDefinition }))
const containerImageName = taskDefinitionDetails.taskDefinition.containerDefinitions[0].image
return containerImageName
})

0 comments on commit a53b6c8

Please sign in to comment.