Skip to content

Commit

Permalink
feat(@whook/example): add AWS build to @whook/example
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Mar 3, 2021
1 parent bdfcd2f commit c49bbe3
Show file tree
Hide file tree
Showing 22 changed files with 2,413 additions and 298 deletions.
1,162 changes: 909 additions & 253 deletions package-lock.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

22 changes: 19 additions & 3 deletions packages/whook-create/src/services/createWhook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('initCreateWhook', () => {
dependencies: {
..._packageJSON.dependencies,
'@whook/authorization': '<current_version>',
'@whook/aws-lambda': '<current_version>',
'@whook/cli': '<current_version>',
'@whook/cors': '<current_version>',
'@whook/http-router': '<current_version>',
Expand Down Expand Up @@ -138,6 +139,7 @@ Mr Bean
"babel": Object {
"env": Object {
"cjs": Object {
"comments": true,
"presets": Array [
Array [
"@babel/env",
Expand All @@ -151,6 +153,7 @@ Mr Bean
],
},
"mjs": Object {
"comments": false,
"presets": Array [
Array [
"@babel/env",
Expand Down Expand Up @@ -184,6 +187,7 @@ Mr Bean
},
"dependencies": Object {
"@whook/authorization": "<current_version>",
"@whook/aws-lambda": "<current_version>",
"@whook/cli": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/http-router": "<current_version>",
Expand Down Expand Up @@ -216,6 +220,7 @@ Mr Bean
"@typescript-eslint/parser": "^4.8.1",
"axios": "^0.21.1",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"babel-plugin-knifecycle": "^5.0.0",
"chokidar": "^3.4.3",
"eslint": "^7.13.0",
Expand All @@ -227,6 +232,7 @@ Mr Bean
"rimraf": "^3.0.2",
"schema2dts": "^2.0.0",
"typescript": "^4.0.5",
"webpack": "4.44.2",
},
"engines": Object {
"node": ">=12.19.0",
Expand Down Expand Up @@ -308,7 +314,7 @@ Mr Bean
"lint": "eslint 'src/**/*.ts'",
"prettier": "prettier --write 'src/**/*.ts'",
"start": "NODE_ENV=\${NODE_ENV:-development} node bin/start",
"test": "npm run jest",
"test": "NODE_ENV=test npm run build && npm run jest",
"types": "rimraf -f 'dist/**/*.d.ts' && tsc --project . --declaration --emitDeclarationOnly --outDir dist",
"watch": "NODE_ENV=\${NODE_ENV:-development} DEV_MODE=1 DESTROY_SOCKETS=1 babel-node --extensions '.ts,.js' bin/watch",
"whook": "NODE_ENV=\${NODE_ENV:-development} whook",
Expand Down Expand Up @@ -393,6 +399,7 @@ Mr Bean
"babel": Object {
"env": Object {
"cjs": Object {
"comments": true,
"presets": Array [
Array [
"@babel/env",
Expand All @@ -406,6 +413,7 @@ Mr Bean
],
},
"mjs": Object {
"comments": false,
"presets": Array [
Array [
"@babel/env",
Expand Down Expand Up @@ -439,6 +447,7 @@ Mr Bean
},
"dependencies": Object {
"@whook/authorization": "<current_version>",
"@whook/aws-lambda": "<current_version>",
"@whook/cli": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/http-router": "<current_version>",
Expand Down Expand Up @@ -471,6 +480,7 @@ Mr Bean
"@typescript-eslint/parser": "^4.8.1",
"axios": "^0.21.1",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"babel-plugin-knifecycle": "^5.0.0",
"chokidar": "^3.4.3",
"eslint": "^7.13.0",
Expand All @@ -482,6 +492,7 @@ Mr Bean
"rimraf": "^3.0.2",
"schema2dts": "^2.0.0",
"typescript": "^4.0.5",
"webpack": "4.44.2",
},
"engines": Object {
"node": ">=12.19.0",
Expand Down Expand Up @@ -563,7 +574,7 @@ Mr Bean
"lint": "eslint 'src/**/*.ts'",
"prettier": "prettier --write 'src/**/*.ts'",
"start": "NODE_ENV=\${NODE_ENV:-development} node bin/start",
"test": "npm run jest",
"test": "NODE_ENV=test npm run build && npm run jest",
"types": "rimraf -f 'dist/**/*.d.ts' && tsc --project . --declaration --emitDeclarationOnly --outDir dist",
"watch": "NODE_ENV=\${NODE_ENV:-development} DEV_MODE=1 DESTROY_SOCKETS=1 babel-node --extensions '.ts,.js' bin/watch",
"whook": "NODE_ENV=\${NODE_ENV:-development} whook",
Expand Down Expand Up @@ -633,6 +644,7 @@ Mr Bean
"babel": Object {
"env": Object {
"cjs": Object {
"comments": true,
"presets": Array [
Array [
"@babel/env",
Expand All @@ -646,6 +658,7 @@ Mr Bean
],
},
"mjs": Object {
"comments": false,
"presets": Array [
Array [
"@babel/env",
Expand Down Expand Up @@ -679,6 +692,7 @@ Mr Bean
},
"dependencies": Object {
"@whook/authorization": "<current_version>",
"@whook/aws-lambda": "<current_version>",
"@whook/cli": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/http-router": "<current_version>",
Expand Down Expand Up @@ -711,6 +725,7 @@ Mr Bean
"@typescript-eslint/parser": "^4.8.1",
"axios": "^0.21.1",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"babel-plugin-knifecycle": "^5.0.0",
"chokidar": "^3.4.3",
"eslint": "^7.13.0",
Expand All @@ -722,6 +737,7 @@ Mr Bean
"rimraf": "^3.0.2",
"schema2dts": "^2.0.0",
"typescript": "^4.0.5",
"webpack": "4.44.2",
},
"engines": Object {
"node": ">=12.19.0",
Expand Down Expand Up @@ -803,7 +819,7 @@ Mr Bean
"lint": "eslint 'src/**/*.ts'",
"prettier": "prettier --write 'src/**/*.ts'",
"start": "NODE_ENV=\${NODE_ENV:-development} node bin/start",
"test": "npm run jest",
"test": "NODE_ENV=test npm run build && npm run jest",
"types": "rimraf -f 'dist/**/*.d.ts' && tsc --project . --declaration --emitDeclarationOnly --outDir dist",
"watch": "NODE_ENV=\${NODE_ENV:-development} DEV_MODE=1 DESTROY_SOCKETS=1 babel-node --extensions '.ts,.js' bin/watch",
"whook": "NODE_ENV=\${NODE_ENV:-development} whook",
Expand Down
58 changes: 58 additions & 0 deletions packages/whook-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,52 @@ List available commands:
```sh
npx whook ls
```
## Deploying with AWS Lambda

First install Terraform:
```sh
wget https://releases.hashicorp.com/terraform/0.12.24/terraform_0.12.24_linux_amd64.zip
mkdir .bin
unzip -d .bin terraform_0.12.24_linux_amd64.zip
rm terraform_0.12.24_linux_amd64.zip
```

Then initialize the Terraform configuration:
```sh
.bin/terraform init ./terraform;
```

Create a new workspace:
```sh
.bin/terraform workspace new staging
```

Build the lambdas:
```sh
NODE_ENV=staging npm run build
```

Build the commands Terraform depends on:
```sh
npm run compile
```

Plan the deployment:
```sh
.bin/terraform plan -out=terraform.plan terraform
```

Apply changes:
```sh
.bin/terraform apply terraform.plan
```

Finally retrieve the API URL and add and enjoy!
```sh
.bin/terraform output api_url
curl "$(.bin/terraform output api_url)staging/v3/ping"
# {"pong":"pong"}
```

Generate API types:
```sh
Expand All @@ -66,6 +112,18 @@ Debug `knifecycle` internals (dependency injection issues):
DEBUG=knifecycle npm run dev
```

Debug built lambdas:
```sh
## HTTP
NODE_ENV=staging npx whook testHTTPLambda --name putEcho \
--parameters '{ "body": { "echo": "Hey!" } }'
## Cron
NODE_ENV=staging npx whook testCronLambda --name handleMinutes
## Consumer
NODE_ENV=staging npx whook testConsumerLambda --name handleMessages \
--event '{ "Records": [{ "test": "test" }] }'
```

[//]: # (::contents:end)

# Authors
Expand Down
58 changes: 34 additions & 24 deletions packages/whook-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@
"testsFiles": "'src/**/*.test.ts'",
"distFiles": "'dist/**/*.js'",
"ignore": [
"dist"
"dist",
"builds",
".bin",
".terraform",
"*.plan",
"*.tfstate.d"
],
"bundleFiles": [
"bin",
Expand All @@ -56,7 +61,7 @@
"metapak": "metapak",
"prettier": "prettier --write 'src/**/*.ts'",
"start": "NODE_ENV=${NODE_ENV:-development} node bin/start",
"test": "npm run jest",
"test": "NODE_ENV=test npm run build && npm run jest",
"types": "rimraf -f 'dist/**/*.d.ts' && tsc --project . --declaration --emitDeclarationOnly --outDir dist",
"watch": "NODE_ENV=${NODE_ENV:-development} DEV_MODE=1 DESTROY_SOCKETS=1 babel-node --extensions '.ts,.js' bin/watch",
"whook": "NODE_ENV=${NODE_ENV:-development} whook",
Expand All @@ -78,6 +83,7 @@
"homepage": "https://github.com/nfroidure/whook",
"dependencies": {
"@whook/authorization": "^7.1.5",
"@whook/aws-lambda": "^7.1.5",
"@whook/cli": "^7.1.5",
"@whook/cors": "^7.1.5",
"@whook/http-router": "^7.1.5",
Expand Down Expand Up @@ -109,6 +115,7 @@
"@typescript-eslint/parser": "^4.8.1",
"axios": "^0.21.1",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"babel-plugin-knifecycle": "^5.0.0",
"chokidar": "^3.4.3",
"eslint": "^7.13.0",
Expand All @@ -121,7 +128,8 @@
"prettier": "^2.1.2",
"rimraf": "^3.0.2",
"schema2dts": "^2.0.0",
"typescript": "^4.0.5"
"typescript": "^4.0.5",
"webpack": "4.44.2"
},
"contributors": [],
"engines": {
Expand Down Expand Up @@ -170,7 +178,25 @@
"trailingComma": "all",
"proseWrap": "always"
},
"jest": {
"coverageReporters": [
"lcov",
"html"
],
"testPathIgnorePatterns": [
"/node_modules/"
],
"roots": [
"<rootDir>/src"
],
"testEnvironment": "node"
},
"babel": {
"plugins": [
"@babel/proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread",
"babel-plugin-knifecycle"
],
"presets": [
"@babel/typescript",
[
Expand All @@ -182,11 +208,6 @@
}
]
],
"plugins": [
"@babel/proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread",
"babel-plugin-knifecycle"
],
"env": {
"cjs": {
"presets": [
Expand All @@ -199,7 +220,8 @@
"modules": "commonjs"
}
]
]
],
"comments": true
},
"mjs": {
"presets": [
Expand All @@ -212,22 +234,10 @@
"modules": false
}
]
]
],
"comments": false
}
},
"sourceMaps": true
},
"jest": {
"coverageReporters": [
"lcov",
"html"
],
"testPathIgnorePatterns": [
"/node_modules/"
],
"roots": [
"<rootDir>/src"
],
"testEnvironment": "node"
}
}
}
17 changes: 14 additions & 3 deletions packages/whook-example/src/__snapshots__/cli.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,21 @@ Object {
",
"stdout": "
# Provided by \\"@whook/example\\": 3 commands
# Provided by \\"@whook/example\\": 4 commands
- generateOpenAPISchema: Write openAPI schema to stdout
- generateOpenAPITypes: Write openAPI types to stdout
- printEnv: A command printing every env values
- terraformValues: A command printing lambdas informations for Terraform
# Provided by \\"@whook/aws-lambda\\": 7 commands
- testConsumerLambda: A command for testing AWS consumer lambda
- testCronLambda: A command for testing AWS cron lambda
- testHTTPLambda: A command for testing AWS HTTP lambda
- testKafkaConsumerLambda: A command for testing AWS lambda Kafka consumers
- testS3Lambda: A command for testing AWS consumer lambda
- testS3Lambda: A command for testing AWS consumer lambda
- testTransformerLambda: A command for testing AWS lambda transformers
# Provided by \\"@whook/cli\\": 6 commands
Expand All @@ -43,10 +54,10 @@ Object {
- ls: Print available commands
# Provided by \\"@whook/whook\\": none
# Provided by \\"@whook/cors\\": none
# Provided by \\"@whook/cors\\": none
# Provided by \\"@whook/whook\\": none
",
}
`;
Loading

0 comments on commit c49bbe3

Please sign in to comment.