This commit is contained in:
Jay 2019-03-07 14:25:32 +08:00
commit 8802df86a7
5 changed files with 182 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules/

5
Dockerfile Normal file
View File

@ -0,0 +1,5 @@
FROM node:10-alpine
WORKDIR /data
COPY . .
RUN npm install
CMD ["npm", "start"]

58
index.js Normal file
View File

@ -0,0 +1,58 @@
/* eslint-disable no-unused-expressions */
const AWS = require('aws-sdk')
let definitionName = process.env.TASK_NAME || ''
let serviceName = process.env.SERVICE_NAME || ''
let clusterName = process.env.CLUSTER_NAME || ''
let accessKeyId = process.env.AWS_KEY || ''
let secretAccessKey = process.env.AWS_SECRET || ''
let region = process.env.AWS_REGION || 'us-east-1'
if (!definitionName || !serviceName || !clusterName || !accessKeyId || !secretAccessKey || !region) {
console.log('env not found')
process.exit(1)
}
AWS.config.update({
accessKeyId,
secretAccessKey,
region
})
const ecs = new AWS.ECS({
apiVersion: '2014-11-13'
})
;!(async function () {
let log = console.log
log('Get TaskDefinition last version')
let taskDefinition = await ecs.describeTaskDefinition({
taskDefinition: definitionName
}).promise()
log('Old Version : ', taskDefinition.taskDefinition.taskDefinitionArn)
log('Update TaskDefinition')
let updateStatus = await ecs.registerTaskDefinition({
containerDefinitions: taskDefinition.taskDefinition.containerDefinitions,
volumes: taskDefinition.taskDefinition.volumes,
family: taskDefinition.taskDefinition.family,
cpu: taskDefinition.taskDefinition.cpu,
memory: taskDefinition.taskDefinition.memory
}).promise()
log('New Version : ', updateStatus.taskDefinition.taskDefinitionArn)
log('Update Service TaskDifinition version')
await ecs.updateService({
cluster: clusterName,
service: serviceName,
taskDefinition: updateStatus.taskDefinition.taskDefinitionArn
}).promise()
})().then(() => {
console.log('deploy finish')
process.exit(0)
}).catch(err => {
console.log(err)
process.exit(1)
})

102
package-lock.json generated Normal file
View File

@ -0,0 +1,102 @@
{
"name": "deploy-container",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"aws-sdk": {
"version": "2.382.0",
"resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.382.0.tgz",
"integrity": "sha512-wGjZLYo2ZxGTlj2cHy/0zOfYJKUVBQYG1vpW4Cnbgo3HTtOu906a6tqkiD8QuN0EyEkn7i+wyjSiUFOCh3T/2g==",
"requires": {
"buffer": "4.9.1",
"events": "1.1.1",
"ieee754": "1.1.8",
"jmespath": "0.15.0",
"querystring": "0.2.0",
"sax": "1.2.1",
"url": "0.10.3",
"uuid": "3.1.0",
"xml2js": "0.4.19"
}
},
"base64-js": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.0.tgz",
"integrity": "sha512-ccav/yGvoa80BQDljCxsmmQ3Xvx60/UpBIij5QN21W3wBi/hhIC9OoO+KLpu9IJTS9j4DRVJ3aDDF9cMSoa2lw=="
},
"buffer": {
"version": "4.9.1",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz",
"integrity": "sha1-bRu2AbB6TvztlwlBMgkwJ8lbwpg=",
"requires": {
"base64-js": "^1.0.2",
"ieee754": "^1.1.4",
"isarray": "^1.0.0"
}
},
"events": {
"version": "1.1.1",
"resolved": "http://registry.npmjs.org/events/-/events-1.1.1.tgz",
"integrity": "sha1-nr23Y1rQmccNzEwqH1AEKI6L2SQ="
},
"ieee754": {
"version": "1.1.8",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.8.tgz",
"integrity": "sha1-vjPUCsEO8ZJnAfbwii2G+/0a0+Q="
},
"isarray": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
},
"jmespath": {
"version": "0.15.0",
"resolved": "https://registry.npmjs.org/jmespath/-/jmespath-0.15.0.tgz",
"integrity": "sha1-o/Iiqarp+Wb10nx5ZRDigJF2Qhc="
},
"punycode": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz",
"integrity": "sha1-llOgNvt8HuQjQvIyXM7v6jkmxI0="
},
"querystring": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz",
"integrity": "sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA="
},
"sax": {
"version": "1.2.1",
"resolved": "http://registry.npmjs.org/sax/-/sax-1.2.1.tgz",
"integrity": "sha1-e45lYZCyKOgaZq6nSEgNgozS03o="
},
"url": {
"version": "0.10.3",
"resolved": "https://registry.npmjs.org/url/-/url-0.10.3.tgz",
"integrity": "sha1-Ah5NnHcF8hu/N9A861h2dAJ3TGQ=",
"requires": {
"punycode": "1.3.2",
"querystring": "0.2.0"
}
},
"uuid": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz",
"integrity": "sha512-DIWtzUkw04M4k3bf1IcpS2tngXEL26YUD2M0tMDUpnUrz2hgzUBlD55a4FjdLGPvfHxS6uluGWvaVEqgBcVa+g=="
},
"xml2js": {
"version": "0.4.19",
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.19.tgz",
"integrity": "sha512-esZnJZJOiJR9wWKMyuvSE1y6Dq5LCuJanqhxslH2bxM6duahNZ+HMpCLhBQGZkbX6xRf8x1Y2eJlgt2q3qo49Q==",
"requires": {
"sax": ">=0.6.0",
"xmlbuilder": "~9.0.1"
}
},
"xmlbuilder": {
"version": "9.0.7",
"resolved": "http://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz",
"integrity": "sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0="
}
}
}

16
package.json Normal file
View File

@ -0,0 +1,16 @@
{
"name": "deploy-container",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"aws-sdk": "^2.382.0"
}
}