Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Esya committed Jul 12, 2016
0 parents commit 389e2ce
Show file tree
Hide file tree
Showing 21 changed files with 2,681 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/*
596 changes: 596 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

107 changes: 107 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# OpsWorks CLI
[![CircleCI](https://circleci.com/gh/plivo/opsworks.svg?style=shield)](https://circleci.com/gh/plivo/opsworks)

The missing OpsWorks CLI, run commands across stacks (and across regions), check your instances, apps, deployments, ELBs, with a smart filtering system.

[![asciicast](https://asciinema.org/a/1fvxew0u6684jhvkj53ekkduc.png)](https://asciinema.org/a/1fvxew0u6684jhvkj53ekkduc)

## Installation

`npm install -g opsworks`

## Usage

```
opsworks <command> [args]
```

The OpsWorks CLI has multiple commands, similar to `git`, `apt-get` or `brew`. When you run `opsworks` with no arguments, you get an interactive prompt.

### GUI / Prompt

For simple tasks, just use `opsworks` without a command and you'll get an interactive prompt.

![Prompt](https://raw.githubusercontent.com/plivo/opsworks/master/img/prompt.png)

### Configuration

`opsworks` needs to access the AWS API using your credentials. Just like the AWS SDK or CLI, it will look for credentials in two places :

* From the shared credentials file (`~/.aws/credentials`)
* From environment variables

To use the credentials file, create a `~/.aws/credentials` file based on the template below :

```
[default]
aws_access_key_id=your_access_key
aws_secret_access_key=your_secret_key
```

### Commands

| command | description |
|-------------|-----------------------------|
| stacks | list OpsWorks stacks |
| deployments | list OpsWorks deployments |
| instances | list instances |
| apps | list apps |
| elbs | list Elastic Load Balancers |
| update | update cookbooks |
| setup | run setup recipes |
| configure | run configure recipes |
| deploy | deploy specified app |
| recipes | run specified recipes |

#### Shared options for these commands

* `-f` Specify filter (see below)
* `-u` Update cookbooks before running the command
* `-y` Do not ask for confirmation

**Note:** by default, when you do not specify `-y`, the CLI will display a summary of what commands it will run and on which layer of which stacks as a precaution.

#### Filtering

Any `opsworks` command accepts filters. There are three built-in filters :

| field | description |
|--------|--------------------------------|
| layer | The **Shortname** of the layer |
| stack | The **Name** of the stack |
| region | The stack's **region** |

The format is `field:filter,field2:filter2,...`
You can use wildcards, or even use regexes.

For example the command bellow would match all stacks whose name contain `wordpress`, and only include their **database** layer.

```
opsworks instances -f 'stack:*wordpress*,layer:database'
```

Using regexes to check ELBs of two wordpress stacks at once :

```
opsworks instances -f 'stack:(prod|staging)-wordpress'
```

Additionally, if you use [custom JSON](http://docs.aws.amazon.com/opsworks/latest/userguide/workingstacks-json.html) on your stacks or layers, you can use arbitrary filters. For example, if your custom JSON has an **env** variable, this would work :

```
opsworks instances -f 'env:production'
```

## Issues?

Please feel free to [open an issue](https://github.com/plivo/opsworks/issues/new) if you find a bug or to request a feature. Please make sure to include all relevant logs.

## Authors

Developed by [Tristan Foureur](https://github.com/esya) for [Plivo](https://www.plivo.com)

## License

Copyright &copy; Plivo Inc.

All code is licensed under the GPL, v3 or later. See `LICENSE.md` file for details.
107 changes: 107 additions & 0 deletions bin/opsworks
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/usr/bin/env node
var CommandRunner = require('./../lib/commandrunner');
var Logger = require('./../lib/logger');
var config = require('./../lib/config');

var argv = require('yargs')
.usage('$0 <command> [args]')
.strict()
.command('stacks', 'list OpsWorks stacks', function (yargs) {
yargs.command = 'toooo';
return yargs
.usage('$0 stacks\nWill list all the stacks matching your filters')
.option('f', {
description: 'Filters'
})
}, function(argv) { argv.command = 'stacks' })
.command('deployments', 'list OpsWorks deployments', function (yargs) {
yargs.command = 'toooo';
return yargs
.usage('$0 deployments\nWill list all the deployments on stacks matching your filters')
.option('f', {
description: 'Filters'
})
.boolean('i').alias('i', 'instances').describe('i','Show instances affected by deployment').default('i',false)
.option('n', {
description: 'Number of deployments to display per stack'
})
.number('n')
.default('n',5);
}, function(argv) { argv.command = 'deployments' })
.command('instances', 'list instances', function (yargs) {
return yargs
.usage('$0 instances\nWill list all instances per stack&layer matching your filters.')
.option('f', {
description: 'Filters'
})
}, function(argv) { argv.command = 'instances' })
.command('apps', 'list apps', function (yargs) {
return yargs
.usage('$0 apps\nWill list all apps per stack matching your filters.')
.option('f', {
description: 'Filters'
})
}, function(argv) { argv.command = 'apps' })
.command('elbs', 'list elastic load balancers', function (yargs) {
return yargs
.usage('$0 apps\nWill list all ELBs per stack/layers matching your filters.')
.option('f', {
description: 'Filters'
})
}, function(argv) { argv.command = 'elbs' })
.command('update', 'updates cookbooks', function (yargs) {
return yargs
.usage('$0 update\nWill update the cookbooks on the stacks and layers matching your filters, and wait for the update to be completed.')
.option('f', {
description: 'Filters'
})
}, function(argv) { argv.command = 'update' })
.command('setup', 'runs setup recipes', function (yargs) {
return yargs
.usage('$0 stacks\nRuns the setup deployment on the stacks and layers matching your filters, and wait for the setup to be completed.')
.option('f', {
description: 'Filters'
})
.boolean('u').alias('u','update-first').describe('u','Update the cookbooks on the instances first')
.default('u',false)
}, function(argv) { argv.command = 'setup' })
.command('configure', 'runs configure recipes', function (yargs) {
return yargs
.usage('$0 configure\nRuns the configure deployment on the stacks and layers matching your filters, and wait for the configuration to be completed.')
.option('f', {
description: 'Filters'
})
.boolean('u').alias('u','update-first').describe('u','Update the cookbooks on the instances first')
.default('u',false)
}, function(argv) { argv.command = 'configure' })
.command('deploy <application_name>', 'runs deploy recipes', function (yargs) {
return yargs
.usage('$0 deploy <application_name>\nRuns the "deploy" deployment on the stacks and layers matching your filters, and wait for the deployment to be completed.')
.option('f', {
description: 'Filters'
})
.boolean('u').alias('u','update-first').describe('u','Update the cookbooks on the instances first')
.default('u',false)
}, function(argv) { argv.command = 'deploy' })
.command('recipes <recipes_list>', 'runs custom recipes', function (yargs) {
return yargs
.usage('$0 recipes')
.option('f', {
description: 'Filters'
})
.boolean('u').alias('u','update-first').describe('u','Update the cookbooks on the instances first')
.default('u',false)
}, function(argv) { argv.command = 'recipes' })
.help('h')
.boolean('v').alias('v', 'verbose').describe('v','Turns on verbose mode').default('v',false).global('v')
.boolean('y').alias('y', 'yes').describe('y','Automatic yes to prompts, to run non-interactively').default('y',false).global('y')
.example("deployments -f 'stack:production-*'",'List deployments for all production stacks')
.example("recipes common::setup_users",'Execute setup_users on all your stacks')
.example("setup -f layer:webapp,env:production",'Runs the setup deployment on "webapp" production layers')
.argv;

var CR = new CommandRunner(argv);
CR.runCommand().catch(err => {
Logger.error(err);
Logger.error(`Full verbose log at ${config.logfile}`)
});
8 changes: 8 additions & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
default:
# Interval at which to poll opsworks API to check deployments.
pollInterval: 10000
verbosity: info
logfile: /tmp/opsworks.log
alias:
p-mediaserver: 'layer:mediaserver,env:production'
s-mediaserver: 'layer:mediaserver,env:staging'
Binary file added img/prompt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 389e2ce

Please sign in to comment.