69 lines
2.0 KiB
JavaScript
69 lines
2.0 KiB
JavaScript
/* 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
|
|
|
|
let gitHash = (process.env.GIT_HASH || '').trim()
|
|
|
|
log('Get TaskDefinition last version')
|
|
let taskDefinition = await ecs.describeTaskDefinition({
|
|
taskDefinition: definitionName
|
|
}).promise()
|
|
log('Old Version : ', taskDefinition.taskDefinition.taskDefinitionArn)
|
|
|
|
let image = taskDefinition.taskDefinition.containerDefinitions[0].image
|
|
console.log('show image :: ', image)
|
|
if (typeof gitHash === 'string' && gitHash.length > 0) {
|
|
image = image.split(':')[0] + ':' + gitHash
|
|
taskDefinition.taskDefinition.containerDefinitions[0].image = image
|
|
}
|
|
console.log('show new image :: ', image)
|
|
|
|
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)
|
|
})
|