Skip to content

Commit

Permalink
Merge pull request #61 from developmentseed/v2.2.0
Browse files Browse the repository at this point in the history
V2.2.0 release
  • Loading branch information
Alireza authored May 9, 2018
2 parents e585e66 + 7dfd336 commit 47957f1
Show file tree
Hide file tree
Showing 20 changed files with 408 additions and 102 deletions.
9 changes: 5 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/node:4
- image: circleci/node:6


working_directory: ~/kes
Expand Down Expand Up @@ -39,11 +39,12 @@ jobs:
./bin/cli.js cf validate --kes-folder examples/full
./bin/cli.js cf validate --kes-folder examples/nested
./bin/cli.js cf validate --kes-folder examples/app_using_template --template examples/template
npm run test
- run:
name: Integration Tests
command: npm run integration-test

- add_ssh_keys:
fingerprints:
- "8f:58:d1:7d:1f:b0:ed:cc:fd:c9:46:cb:ee:6b:40:86"
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## v2.2.0

- show proper logs when the template merging fails due to a yaml
- a new flag `--showOutputs` will show the output of a CloudFormation template
- add cloudformation delete functionality
- support `system_bucket` as the variable for for holding the bucket name used in deployment

## v2.1.2

- fix a bug where determineKesClass failed to return the default class
Expand Down
13 changes: 8 additions & 5 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ program.version(pckg.version);
function extractCommanderOptions(program) {
const options = {};
Object.keys(program).forEach(property => {
if (typeof program[property] === 'string') {
if (typeof program[property] === 'string' || typeof program[property] === 'boolean') {
options[property] = program[property];
}
});
Expand Down Expand Up @@ -74,7 +74,7 @@ const init = function () {
config.default.buckets = {};
}

config.default.buckets.internal = result.bucket;
config.default.system_bucket = result.bucket;
fs.writeFileSync(path.join(kesFolder, 'config.yml'), yaml.safeDump(config));

fs.createReadStream(
Expand Down Expand Up @@ -105,20 +105,23 @@ program
.option('-k, --kes-folder <kesFolder>', 'Path to config folder')
.option('-r, --region <region>', 'AWS region', null)
.option('--stack <stack>', 'stack name, defaults to the config value')
.option('--showOutputs', 'Show the list of a CloudFormation template outputs')
.option('--yes', 'Skip all confirmation prompts')
.option('-d, --deployment <deployment>', 'Deployment name, default to default');

program
.command('cf [create|update|upsert|deploy|validate|compile]')
.command('cf [create|update|upsert|deploy|validate|compile|delete]')
.description(`CloudFormation Operations:
create Creates the CF stack (deprecated, start using deploy)
update Updates the CF stack (deprecated, start using deploy)
upsert Creates the CF stack and Update if already exists (deprected, start using deploy)
upsert Creates the CF stack and Update if already exists (deprecated, start using deploy)
deploy Creates the CF stack and Update if already exists
delete Delete the CF stack
validate Validates the CF stack
compile Compiles the CF stack`)
.action((cmd, o) => {
const options = extractCommanderOptions(program);
kes.buildCf(options ,cmd);
kes.buildCf(options, cmd).then(r => kes.utils.success(r)).catch(e => kes.utils.failure(e));
});

program
Expand Down
18 changes: 14 additions & 4 deletions bin/readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@
* -k, --kes-folder <kesFolder> Path to config folder
* -r, --region <region> AWS region
* --stack <stack> stack name, defaults to the config value
* --showOutputs Show the list of a CloudFormation template outputs
* --yes Skip all confirmation prompts
* -d, --deployment <deployment> Deployment name, default to default
* -h, --help output usage information
*
* Commands:
* cf [deploy|validate|compile] CloudFormation Operations:
* create Creates the CF stack (deprecated, start using deploy)
* update Updates the CF stack (deprecated, start using deploy)
* upsert Creates the CF stack and Update if already exists (deprected, start using deploy)
* upsert Creates the CF stack and Update if already exists (deprecated, start using deploy)
* deploy Creates the CF stack and Update if already exists
* delete Delete the CF stack
* validate Validates the CF stack
* compile Compiles the CF stack
* lambda <lambdaName> uploads a given lambda function to Lambda service
Expand Down Expand Up @@ -65,7 +68,7 @@
* the `default` section of the `config.yml` is parsed and used in `cloudformation.template.yml`. If
* another deployment is specified in the `config.yml` the values of that deployment overrides the
* values of `default`
* file which is sent to AWS CloudFormation to create and udpate the stack.
* file which is sent to AWS CloudFormation to create and update the stack.
*
* ### CF Stack Name
* The Cloudformation stack name is the same as `stackName` in `config.yml`.
Expand Down Expand Up @@ -247,7 +250,14 @@
* kes cf deploy
* ```
*
* ### Differenet deployment configurations
* ### Delete an existing stack
*
* To delete an existing stack:
* ```bash
* kes cf delete
* ```
*
* ### Different deployment configurations
*
* You can configure different values for different deployments. For example you might want to configure your test deployment
* differently from your staging and production deployments. Here is how to achieve it:
Expand Down Expand Up @@ -279,7 +289,7 @@
* **Note:** You still need an aws user with AssumeRole permission for this to work
*
* ```bash
* kes cf deploy --profile myUser --role arn:aws:iam::00000000000:role/myDeplymentRole
* kes cf deploy --profile myUser --role arn:aws:iam::00000000000:role/myDeploymentRole
* ```
*
* ### Updating One Lambda Function
Expand Down
43 changes: 42 additions & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
- [compileCF](#compilecf)
- [uploadToS3](#uploadtos3)
- [uploadCF](#uploadcf)
- [waitFor](#waitfor)
- [cloudFormation](#cloudformation)
- [validateTemplate](#validatetemplate)
- [describeCF](#describecf)
- [deleteCF](#deletecf)
- [opsStack](#opsstack)
- [upsertStack](#upsertstack)
- [deployStack](#deploystack)
- [createStack](#createstack)
- [updateStack](#updatestack)
- [deleteStack](#deletestack)
- [Lambda](#lambda)
- [buildS3Path](#builds3path)
- [getHash](#gethash)
Expand All @@ -34,6 +37,8 @@
- [mergeYamls](#mergeyamls)
- [determineKesClass](#determinekesclass)
- [failure](#failure)
- [success](#success)
- [getSystemBucket](#getsystembucket)

## Config

Expand Down Expand Up @@ -87,7 +92,7 @@ Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G

The main Kes class. This class is used in the command module to create
the CLI interface for kes. This class can be extended in order to override
and modify the behaviour of kes cli.
and modify the behavior of kes cli.

**Parameters**

Expand Down Expand Up @@ -151,6 +156,16 @@ Uploads the Cloud Formation template to a given S3 location

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object

### waitFor

Wait for the current stack and log the current outcome

**Parameters**

- `wait`

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** undefined

### cloudFormation

Calls CloudFormation's update-stack or create-stack methods
Expand All @@ -169,6 +184,12 @@ Describes the cloudformation stack deployed

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object

### deleteCF

Deletes the current stack

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** undefined

### opsStack

Generic create/update method for CloudFormation
Expand Down Expand Up @@ -201,6 +222,12 @@ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object

### deleteStack

Deletes the main stack

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object

## Lambda

Copy, zip and upload lambda functions to S3
Expand Down Expand Up @@ -398,3 +425,17 @@ In case of error logs the error and exit with error 1
**Parameters**

- `e` **[Error](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error)** error object

## success

Exists the process when called

## getSystemBucket

Discover and returns the system bucket used for deployment

**Parameters**

- `config` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** cumulus config object

Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** name of the bucket
22 changes: 17 additions & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
- [Lambda Functions](#lambda-functions)
- [Handlebar Helpers](#handlebar-helpers)
- [Deployment](#deployment)
- [Differenet deployment configurations](#differenet-deployment-configurations)
- [Delete an existing stack](#delete-an-existing-stack)
- [Different deployment configurations](#different-deployment-configurations)
- [Deployment Using IAM Role](#deployment-using-iam-role)
- [Updating One Lambda Function](#updating-one-lambda-function)
- [Use Templates](#use-templates)
Expand Down Expand Up @@ -50,15 +51,18 @@ It makes it much easier to deploy lambda functions and create API gateway resour
-k, --kes-folder <kesFolder> Path to config folder
-r, --region <region> AWS region
--stack <stack> stack name, defaults to the config value
--showOutputs Show the list of a CloudFormation template outputs
--yes Skip all confirmation prompts
-d, --deployment <deployment> Deployment name, default to default
-h, --help output usage information

Commands:
cf [deploy|validate|compile] CloudFormation Operations:
create Creates the CF stack (deprecated, start using deploy)
update Updates the CF stack (deprecated, start using deploy)
upsert Creates the CF stack and Update if already exists (deprected, start using deploy)
upsert Creates the CF stack and Update if already exists (deprecated, start using deploy)
deploy Creates the CF stack and Update if already exists
delete Delete the CF stack
validate Validates the CF stack
compile Compiles the CF stack
lambda <lambdaName> uploads a given lambda function to Lambda service
Expand Down Expand Up @@ -86,7 +90,7 @@ The variables in `config.yml` are parsed and used to generate the `cloudformatio
the `default` section of the `config.yml` is parsed and used in `cloudformation.template.yml`. If
another deployment is specified in the `config.yml` the values of that deployment overrides the
values of `default`
file which is sent to AWS CloudFormation to create and udpate the stack.
file which is sent to AWS CloudFormation to create and update the stack.
### CF Stack Name
Expand Down Expand Up @@ -273,7 +277,15 @@ To create a CF stack or update and existing one run
kes cf deploy
```
### Differenet deployment configurations
### Delete an existing stack
To delete an existing stack:
```bash
kes cf delete
```
### Different deployment configurations
You can configure different values for different deployments. For example you might want to configure your test deployment
differently from your staging and production deployments. Here is how to achieve it:
Expand Down Expand Up @@ -304,7 +316,7 @@ You can specify an IAM role for the deployment using `--role` option or by setti
**Note:** You still need an aws user with AssumeRole permission for this to work
```bash
kes cf deploy --profile myUser --role arn:aws:iam::00000000000:role/myDeplymentRole
kes cf deploy --profile myUser --role arn:aws:iam::00000000000:role/myDeploymentRole
```
### Updating One Lambda Function
Expand Down
9 changes: 6 additions & 3 deletions examples/app_using_template/cloudformation.template.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Outputs:
# this is not in the original template. we are adding it here to override
{{#each apis}}
{{Name}}Endpoint:
Value: !Ref {{name}}RestApi
{{#each lambdas}}
{{@key}}LambdaFunction:
Value:
Fn::GetAtt:
- {{@key}}LambdaFunction
- Arn
{{/each}}
14 changes: 10 additions & 4 deletions examples/app_using_template/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
myDeployment:
stackName: myDeployment-using-template
kesTestDeployment:
stackName: kes-test-using-template
noDash: myDeployment
system_bucket: devseed-kes-deployment

buckets:
internal: devseed-kes-deployment
tests: myTestArtifacts
tests: myTestArtifacts

lambdas:
func3: # function name must match the lambda folder name in build directory
handler: index.handler
timeout: 300
source: 'examples/code/lambda1/'
6 changes: 3 additions & 3 deletions examples/full/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ default:
stackName: kes-full-example
noDash: KesFullExample
retryValue: 10
system_bucket: devseed-kes-deployment

buckets:
internal: devseed-kes-deployment
tests: myTestArtifacts
test: myTestArtifacts

capabilities:
- CAPABILITY_NAMED_IAM
Expand Down Expand Up @@ -67,7 +67,7 @@ default:
memory: 256
source: 'examples/code/api/'
envs:
internal: '{{buckets.internal}}'
internal: '{{buckets.test}}'
apiGateway:
- path: list
method: get
Expand Down
23 changes: 14 additions & 9 deletions examples/lambdas/cloudformation.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,32 @@ Resources:
# Lambda config BEGIN
#################################################
{{#each lambdas}}
{{name}}LambdaFunction:
{{@key}}LambdaFunction:
Type: AWS::Lambda::Function
Properties:
Code:
S3Bucket: {{bucket}}
S3Key: {{remote}}
FunctionName: {{../stackName}}-{{name}}
{{#if this.s3Source}}
S3Bucket: {{this.s3Source.bucket}}
S3Key: {{this.s3Source.key}}
{{else}}
S3Bucket: {{this.bucket}}
S3Key: {{this.remote}}
{{/if}}
FunctionName: {{../stackName}}-{{@key}}
Environment:
Variables:
stackName: {{../stackName}}
{{#each envs}}
{{#each this.envs}}
{{@key}}: {{this}}
{{/each}}
Handler: {{handler}}
MemorySize: {{memory}}
Handler: {{this.handler}}
MemorySize: {{this.memory}}
Role:
Fn::GetAtt:
- LambdaRole
- Arn
Runtime: {{# if runtime}}{{runtime}}{{else}}nodejs6.10{{/if}}
Timeout: {{# if timeout}}{{timeout}}{{else}}300{{/if}}
Runtime: {{# if this.runtime}}{{this.runtime}}{{else}}nodejs6.10{{/if}}
Timeout: {{# if this.timeout}}{{this.timeout}}{{else}}300{{/if}}
{{/each}}
#################################################
# Lambda config END
Expand Down
Loading

0 comments on commit 47957f1

Please sign in to comment.