├── .babelrc ├── .eslintrc ├── .gitignore ├── LICENSE ├── README.md ├── bin └── index.js ├── package.json └── src ├── deploy.js └── index.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015", "stage-0"] 3 | } 4 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "airbnb-base", 3 | "parser": "babel-eslint", 4 | "env": { 5 | "node": true, 6 | "es6": true 7 | }, 8 | "rules": { 9 | "indent": [2, 4], 10 | "comma-dangle": [2, 'never'], 11 | "global-require": 0 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | coverage/ 3 | dist/ 4 | .nyc_output/ 5 | npm-debug.log 6 | .tmp 7 | .idea 8 | .DS_Store 9 | #vim 10 | *.swp 11 | *.swo 12 | .environment 13 | dist.zip 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Kristoffer K Larsen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ecs-deploy-cli 2 | 3 | `ecs-deploy-cli` is a simple and easy way to deploy tasks and update services in AWS ECS. 4 | 5 | Just write your task definition in `task.json` and upload them straight to AWS using `ecs-deploy-cli`. 6 | 7 | ## Install 8 | 9 | ```sh 10 | $ npm install -g ecs-deploy-cli 11 | ``` 12 | 13 | To be able to deploy to AWS you need to have installed the `aws-cli` and configured it to use the the account you wish to upload the function to. 14 | 15 | ## Configuration 16 | 17 | To upload automatically to AWS you need to configure your task functions in the file `task.json`. 18 | 19 | ### Example task 20 | 21 | ```json 22 | { 23 | "family": "node-task", 24 | "containerDefinitions": [ 25 | { 26 | "memory": 300, 27 | "essential": true, 28 | "name": "node", 29 | "image": "node", 30 | "logConfiguration": { 31 | "logDriver": "awslogs", 32 | "options": { 33 | "awslogs-group": "node-task", 34 | "awslogs-region": "eu-west-1" 35 | } 36 | }, 37 | "cpu": 200 38 | } 39 | ], 40 | } 41 | ``` 42 | 43 | For a more detailed task definition see the DOCS for the [AWS CLI](http://docs.aws.amazon.com/cli/latest/reference/ecs/register-task-definition.html). 44 | 45 | ## Examples 46 | 47 | 48 | ### Create a new task 49 | 50 | ```sh 51 | $ ecs-deploy-cli 52 | ``` 53 | 54 | or 55 | 56 | ```sh 57 | $ ecs-deploy-cli production.task.json 58 | ``` 59 | 60 | 61 | ### Create a new task and update an existing service 62 | 63 | ```sh 64 | $ ecs-deploy-cli --service node-service --cluster ecs-cluster 65 | ``` 66 | 67 | 68 | ## License 69 | 70 | (The MIT License) 71 | 72 | Copyright (c) 2015 Kristoffer K Larsen 73 | 74 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 75 | 76 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 77 | 78 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 79 | -------------------------------------------------------------------------------- /bin/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('../src')(); 3 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ecs-deploy-cli", 3 | "version": "0.0.5", 4 | "description": "Simple and easy way to deploy tasks and update services in AWS ECS.", 5 | "main": "src/index.js", 6 | "bin": "./bin/index.js", 7 | "author": "Kristoffer K Larsen ", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/larseen/ecs-deploy-cli" 11 | }, 12 | "bugs": { 13 | "url": "https://github.com/larseen/ecs-deploy-cli/issues" 14 | }, 15 | "ava": { 16 | "require": "babel-core/register", 17 | "files": [ 18 | "test/**/*.test.js" 19 | ] 20 | }, 21 | "keywords": [ 22 | "aws", 23 | "ecs", 24 | "docker", 25 | "amazon", 26 | "deploy", 27 | "cli" 28 | ], 29 | "license": "MIT", 30 | "scripts": { 31 | "start": "node bin", 32 | "lint": "eslint --ignore-path .gitignore .", 33 | "build": "babel src --out-dir lib", 34 | "clean": "rm -fr lib", 35 | "test": "npm run lint && nyc --reporter=text ava", 36 | "test:watch": "ava --watch" 37 | }, 38 | "devDependencies": { 39 | "ava": "^0.16.0", 40 | "babel-cli": "^6.14.0", 41 | "babel-core": "^6.14.0", 42 | "babel-eslint": "^6.1.2", 43 | "babel-preset-es2015": "^6.14.0", 44 | "babel-preset-stage-0": "^6.5.0", 45 | "eslint": "^3.5.0", 46 | "eslint-config-airbnb-base": "^7.1.0", 47 | "eslint-plugin-async-await": "0.0.0", 48 | "eslint-plugin-import": "^1.15.0", 49 | "nyc": "^8.3.0" 50 | }, 51 | "dependencies": { 52 | "aws-sdk": "^2.6.5", 53 | "bluebird": "^3.4.6", 54 | "chalk": "^1.1.3", 55 | "yargs": "^5.0.0" 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/deploy.js: -------------------------------------------------------------------------------- 1 | const chalk = require('chalk'); 2 | const path = require('path'); 3 | const Promise = require('bluebird'); 4 | const AWS = require('aws-sdk'); 5 | 6 | const ECS = new Promise.promisifyAll(new AWS.ECS({ region: 'eu-west-1' })); 7 | 8 | const load = (source) => { 9 | try { 10 | return require(path.resolve(source)); 11 | } catch (e) { 12 | return e; 13 | } 14 | }; 15 | 16 | module.exports = function deploy(argv) { 17 | const source = argv._[0] || 'task.json'; 18 | const task = load(source); 19 | 20 | if (task instanceof Error) { 21 | console.log(chalk.red(task.message)); 22 | return; 23 | } 24 | 25 | console.log(chalk.cyan(`Registrating new task definition from: 26 | File: ${path.resolve(source)}`)); 27 | 28 | ECS.registerTaskDefinitionAsync(task) 29 | .then((response) => { 30 | const taskDefinition = response.taskDefinition; 31 | console.log(chalk.cyan(`Registrated new task definition: 32 | Task: ${taskDefinition.taskDefinitionArn} 33 | Family: ${taskDefinition.family} 34 | Revision: ${taskDefinition.revision}`)); 35 | return taskDefinition; 36 | }) 37 | .then((taskDefinition) => { 38 | if (!argv.service) { 39 | Promise.resovle('No service to update'); 40 | } 41 | 42 | if (!argv.cluster) { 43 | throw new Error('Missing cluster to update'); 44 | } 45 | 46 | console.log(chalk.cyan(`Updating: 47 | Task: ${taskDefinition.taskDefinitionArn} 48 | Service: ${argv.service} 49 | Cluster: ${argv.cluster}`)); 50 | return ECS.updateServiceAsync({ 51 | service: argv.service, 52 | cluster: argv.cluster, 53 | taskDefinition: taskDefinition.taskDefinitionArn 54 | }); 55 | }) 56 | .then(() => { 57 | console.log(chalk.cyan('ALL DONE!')); 58 | }) 59 | .catch((error) => { 60 | console.log(chalk.red(error.message || error.cause)); 61 | }); 62 | }; 63 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | const yargs = require('yargs'); 2 | const pkg = require('../package.json'); 3 | const deploy = require('./deploy'); 4 | 5 | module.exports = function configuration() { 6 | const argv = yargs 7 | .usage('$0 [options] ') 8 | .options({ 9 | service: { 10 | alias: 's', 11 | description: 'Name of service to deploy task to' 12 | }, 13 | family: { 14 | alias: 'f', 15 | description: 'Name of task family to add the revision to' 16 | }, 17 | cluster: { 18 | alias: 'c', 19 | description: 'Name of cluster where service is located' 20 | } 21 | }) 22 | .help('help') 23 | .alias('help', 'h') 24 | .version(pkg.version) 25 | .alias('version', 'v') 26 | .example('$0 production.task.json', '') 27 | .example('$0 -s ecs-service -c ecs-cluster', '') 28 | .epilog('https://github.com/larseen/deploy-ecs') 29 | .argv; 30 | 31 | deploy(argv); 32 | }; 33 | --------------------------------------------------------------------------------