Skip to content

Commit

Permalink
feat(@whook/example): add Google Cloud Functions build
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Oct 28, 2020
1 parent 32136d4 commit 2aa60bb
Show file tree
Hide file tree
Showing 14 changed files with 13,430 additions and 4,326 deletions.
17,115 changes: 12,816 additions & 4,299 deletions package-lock.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions packages/whook-create/src/services/createWhook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,14 @@ Mr Bean
"@whook/authorization": "<current_version>",
"@whook/cli": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/gcp-functions": "^5.1.3",
"@whook/http-router": "<current_version>",
"@whook/http-transaction": "<current_version>",
"@whook/swagger-ui": "<current_version>",
"@whook/whook": "<current_version>",
"common-services": "^8.0.2",
"http-auth-utils": "^2.6.0",
"js-yaml": "^3.13.1",
"jwt-service": "^6.0.3",
"knifecycle": "^10.0.3",
"strict-qs": "^6.1.3",
Expand Down Expand Up @@ -305,7 +307,7 @@ Mr Bean
"private": true,
"scripts": Object {
"apitypes": "npm run --silent whook -- generateOpenAPISchema --authenticated=true | npm run --silent whook -- generateOpenAPITypes > src/openAPISchema.d.ts",
"build": "npm run compile && NODE_ENV=\${NODE_ENV:-development} node bin/build",
"build": "npm run compile && npm run types && NODE_ENV=\${NODE_ENV:-development} node bin/build",
"compile": "rimraf -f 'dist' && npm run compile:cjs && npm run compile:mjs",
"compile:cjs": "babel --env-name=cjs --out-dir=dist --extensions '.ts,.js' --source-maps=true src",
"compile:mjs": "babel --env-name=mjs --out-file-extension=.mjs --out-dir=dist --extensions '.ts,.js' --source-maps=true src",
Expand All @@ -316,7 +318,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 @@ -449,12 +451,14 @@ Mr Bean
"@whook/authorization": "<current_version>",
"@whook/cli": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/gcp-functions": "^5.1.3",
"@whook/http-router": "<current_version>",
"@whook/http-transaction": "<current_version>",
"@whook/swagger-ui": "<current_version>",
"@whook/whook": "<current_version>",
"common-services": "^8.0.2",
"http-auth-utils": "^2.6.0",
"js-yaml": "^3.13.1",
"jwt-service": "^6.0.3",
"knifecycle": "^10.0.3",
"strict-qs": "^6.1.3",
Expand Down Expand Up @@ -569,7 +573,7 @@ Mr Bean
"private": true,
"scripts": Object {
"apitypes": "npm run --silent whook -- generateOpenAPISchema --authenticated=true | npm run --silent whook -- generateOpenAPITypes > src/openAPISchema.d.ts",
"build": "npm run compile && NODE_ENV=\${NODE_ENV:-development} node bin/build",
"build": "npm run compile && npm run types && NODE_ENV=\${NODE_ENV:-development} node bin/build",
"compile": "rimraf -f 'dist' && npm run compile:cjs && npm run compile:mjs",
"compile:cjs": "babel --env-name=cjs --out-dir=dist --extensions '.ts,.js' --source-maps=true src",
"compile:mjs": "babel --env-name=mjs --out-file-extension=.mjs --out-dir=dist --extensions '.ts,.js' --source-maps=true src",
Expand All @@ -580,7 +584,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 @@ -698,12 +702,14 @@ Mr Bean
"@whook/authorization": "<current_version>",
"@whook/cli": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/gcp-functions": "^5.1.3",
"@whook/http-router": "<current_version>",
"@whook/http-transaction": "<current_version>",
"@whook/swagger-ui": "<current_version>",
"@whook/whook": "<current_version>",
"common-services": "^8.0.2",
"http-auth-utils": "^2.6.0",
"js-yaml": "^3.13.1",
"jwt-service": "^6.0.3",
"knifecycle": "^10.0.3",
"strict-qs": "^6.1.3",
Expand Down Expand Up @@ -818,7 +824,7 @@ Mr Bean
"private": true,
"scripts": Object {
"apitypes": "npm run --silent whook -- generateOpenAPISchema --authenticated=true | npm run --silent whook -- generateOpenAPITypes > src/openAPISchema.d.ts",
"build": "npm run compile && NODE_ENV=\${NODE_ENV:-development} node bin/build",
"build": "npm run compile && npm run types && NODE_ENV=\${NODE_ENV:-development} node bin/build",
"compile": "rimraf -f 'dist' && npm run compile:cjs && npm run compile:mjs",
"compile:cjs": "babel --env-name=cjs --out-dir=dist --extensions '.ts,.js' --source-maps=true src",
"compile:mjs": "babel --env-name=mjs --out-file-extension=.mjs --out-dir=dist --extensions '.ts,.js' --source-maps=true src",
Expand All @@ -829,7 +835,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
51 changes: 51 additions & 0 deletions packages/whook-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,57 @@ Debug `knifecycle` internals (dependency injection issues):
DEBUG=knifecycle npm run dev
```

## Deploying with Google Cloud Functions

Create a project and save its credentials to `.credentials.json`.

Then 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 functions:
```sh
NODE_ENV=staging npm run build
```

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

Plan the deployment:
```sh
.bin/terraform plan -var="project_id=my-project-1664" \
-out=terraform.plan terraform
```

Apply changes:
```sh
# parallelism may be necessary to avoid hitting
# timeouts with a slow connection
.bin/terraform apply -parallelism=1 terraform.plan
```

Finally retrieve the API URL and enjoy!
```sh
.bin/terraform -var="project_id=my-project-1664" \
output api_url
```

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

# Authors
Expand Down
6 changes: 4 additions & 2 deletions packages/whook-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"scripts": {
"apitypes": "npm run --silent whook -- generateOpenAPISchema --authenticated=true | npm run --silent whook -- generateOpenAPITypes > src/openAPISchema.d.ts",
"build": "npm run compile && NODE_ENV=${NODE_ENV:-development} node bin/build",
"build": "npm run compile && npm run types && NODE_ENV=${NODE_ENV:-development} node bin/build",
"cli": "env NODE_ENV=${NODE_ENV:-cli}",
"compile": "rimraf -f 'dist' && npm run compile:cjs && npm run compile:mjs",
"compile:cjs": "babel --env-name=cjs --out-dir=dist --extensions '.ts,.js' --source-maps=true src",
Expand All @@ -56,7 +56,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 @@ -80,13 +80,15 @@
"@whook/authorization": "^5.1.3",
"@whook/cli": "^5.1.3",
"@whook/cors": "^5.1.3",
"@whook/gcp-functions": "^5.1.3",
"@whook/http-router": "^5.1.3",
"@whook/http-transaction": "^5.1.3",
"@whook/swagger-ui": "^5.1.3",
"@whook/whook": "^5.1.3",
"common-services": "^8.0.2",
"http-auth-utils": "^2.6.0",
"jwt-service": "^6.0.3",
"js-yaml": "^3.13.1",
"knifecycle": "^10.0.3",
"strict-qs": "^6.1.3",
"yerror": "^5.0.0",
Expand Down
13 changes: 9 additions & 4 deletions packages/whook-example/src/__snapshots__/cli.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,18 @@ 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 functions informations for Terraform
# Provided by \\"@whook/gcp-functions\\": 1 commands
- testHTTPLambda: A command for testing AWS HTTP lambda
# Provided by \\"@whook/cors\\": none
# Provided by \\"@whook/cli\\": 6 commands
Expand All @@ -41,9 +49,6 @@ Object {
# Provided by \\"@whook/whook\\": none
# Provided by \\"@whook/cors\\": none
",
}
`;
Loading

0 comments on commit 2aa60bb

Please sign in to comment.