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 Mar 30, 2020
1 parent cd36ba4 commit fa55331
Show file tree
Hide file tree
Showing 9 changed files with 519 additions and 12 deletions.

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions packages/whook-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,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
2 changes: 2 additions & 0 deletions packages/whook-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@
"@whook/authorization": "^3.1.3",
"@whook/cli": "^3.1.3",
"@whook/cors": "^3.1.3",
"@whook/gcp-functions": "^3.1.3",
"@whook/http-router": "^3.1.3",
"@whook/http-transaction": "^3.1.3",
"@whook/swagger-ui": "^3.1.3",
"@whook/whook": "^3.1.3",
"common-services": "^7.0.0",
"ecstatic": "^4.1.2",
"http-auth-utils": "^2.3.0",
"js-yaml": "^3.13.1",
"knifecycle": "^9.0.0",
"strict-qs": "^6.0.2",
"yerror": "^5.0.0",
Expand Down
7 changes: 6 additions & 1 deletion packages/whook-example/src/__snapshots__/cli.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ Object {
",
"stdout": "
# Provided by \\"@whook/example\\": 1 commands
# Provided by \\"@whook/example\\": 2 commands
- printEnv: A command printing every env values
- terraformValues: A command printing functions informations for Terraform
# Provided by \\"@whook/cli\\": 6 commands
Expand All @@ -39,6 +40,10 @@ Object {
# Provided by \\"@whook/whook\\": none
# Provided by \\"@whook/gcp-functions\\": 1 commands
- testHTTPLambda: A command for testing AWS HTTP lambda
",
}
`;
81 changes: 81 additions & 0 deletions packages/whook-example/src/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ Object {
Array [
"➰ - Plugin \\"@whook/cli\\" resolved to: /home/whoiam/projects/whook/packages/whook-cli/dist",
],
Array [
"➰ - Plugin \\"@whook/gcp-functions\\" resolved to: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist",
],
Array [
"➰ - Plugin \\"@whook/whook\\" resolved to: /home/whoiam/projects/whook/dist",
],
Expand Down Expand Up @@ -303,6 +306,9 @@ Object {
Array [
"🚫 - Service \\"BUFFER_LIMIT\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/BUFFER_LIMIT",
],
Array [
"🚫 - Service \\"BUFFER_LIMIT\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/BUFFER_LIMIT",
],
Array [
"🚫 - Service \\"DECODERS\\" not found in: /home/whoiam/projects/whook/dist/services/DECODERS",
],
Expand All @@ -312,6 +318,9 @@ Object {
Array [
"🚫 - Service \\"DECODERS\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/DECODERS",
],
Array [
"🚫 - Service \\"DECODERS\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/DECODERS",
],
Array [
"🚫 - Service \\"DEFAULT_ERROR_CODE\\" not found in: /home/whoiam/projects/whook/dist/services/DEFAULT_ERROR_CODE",
],
Expand All @@ -321,6 +330,9 @@ Object {
Array [
"🚫 - Service \\"DEFAULT_ERROR_CODE\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/DEFAULT_ERROR_CODE",
],
Array [
"🚫 - Service \\"DEFAULT_ERROR_CODE\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/DEFAULT_ERROR_CODE",
],
Array [
"🚫 - Service \\"DEFAULT_MECHANISM\\" not found in: /home/whoiam/projects/whook/dist/services/DEFAULT_MECHANISM",
],
Expand All @@ -330,6 +342,9 @@ Object {
Array [
"🚫 - Service \\"DEFAULT_MECHANISM\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/DEFAULT_MECHANISM",
],
Array [
"🚫 - Service \\"DEFAULT_MECHANISM\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/DEFAULT_MECHANISM",
],
Array [
"🚫 - Service \\"DEV_ACCESS_TOKEN\\" not found in: /home/whoiam/projects/whook/dist/services/DEV_ACCESS_TOKEN",
],
Expand All @@ -339,6 +354,9 @@ Object {
Array [
"🚫 - Service \\"DEV_ACCESS_TOKEN\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/DEV_ACCESS_TOKEN",
],
Array [
"🚫 - Service \\"DEV_ACCESS_TOKEN\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/DEV_ACCESS_TOKEN",
],
Array [
"🚫 - Service \\"ENCODERS\\" not found in: /home/whoiam/projects/whook/dist/services/ENCODERS",
],
Expand All @@ -348,6 +366,9 @@ Object {
Array [
"🚫 - Service \\"ENCODERS\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/ENCODERS",
],
Array [
"🚫 - Service \\"ENCODERS\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/ENCODERS",
],
Array [
"🚫 - Service \\"IGNORED_FILES_PREFIXES\\" not found in: /home/whoiam/projects/whook/dist/services/IGNORED_FILES_PREFIXES",
],
Expand All @@ -357,6 +378,9 @@ Object {
Array [
"🚫 - Service \\"IGNORED_FILES_PREFIXES\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/IGNORED_FILES_PREFIXES",
],
Array [
"🚫 - Service \\"IGNORED_FILES_PREFIXES\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/IGNORED_FILES_PREFIXES",
],
Array [
"🚫 - Service \\"IGNORED_FILES_SUFFIXES\\" not found in: /home/whoiam/projects/whook/dist/services/IGNORED_FILES_SUFFIXES",
],
Expand All @@ -366,6 +390,9 @@ Object {
Array [
"🚫 - Service \\"IGNORED_FILES_SUFFIXES\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/IGNORED_FILES_SUFFIXES",
],
Array [
"🚫 - Service \\"IGNORED_FILES_SUFFIXES\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/IGNORED_FILES_SUFFIXES",
],
Array [
"🚫 - Service \\"KEEP_ALIVE_TIMEOUT\\" not found in: /home/whoiam/projects/whook/dist/services/KEEP_ALIVE_TIMEOUT",
],
Expand All @@ -375,6 +402,9 @@ Object {
Array [
"🚫 - Service \\"KEEP_ALIVE_TIMEOUT\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/KEEP_ALIVE_TIMEOUT",
],
Array [
"🚫 - Service \\"KEEP_ALIVE_TIMEOUT\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/KEEP_ALIVE_TIMEOUT",
],
Array [
"🚫 - Service \\"MAX_CLEAR_CHARS\\" not found in: /home/whoiam/projects/whook/dist/services/MAX_CLEAR_CHARS",
],
Expand All @@ -384,6 +414,9 @@ Object {
Array [
"🚫 - Service \\"MAX_CLEAR_CHARS\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/MAX_CLEAR_CHARS",
],
Array [
"🚫 - Service \\"MAX_CLEAR_CHARS\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/MAX_CLEAR_CHARS",
],
Array [
"🚫 - Service \\"MAX_CLEAR_RATIO\\" not found in: /home/whoiam/projects/whook/dist/services/MAX_CLEAR_RATIO",
],
Expand All @@ -393,6 +426,9 @@ Object {
Array [
"🚫 - Service \\"MAX_CLEAR_RATIO\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/MAX_CLEAR_RATIO",
],
Array [
"🚫 - Service \\"MAX_CLEAR_RATIO\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/MAX_CLEAR_RATIO",
],
Array [
"🚫 - Service \\"MAX_CONNECTIONS\\" not found in: /home/whoiam/projects/whook/dist/services/MAX_CONNECTIONS",
],
Expand All @@ -402,6 +438,9 @@ Object {
Array [
"🚫 - Service \\"MAX_CONNECTIONS\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/MAX_CONNECTIONS",
],
Array [
"🚫 - Service \\"MAX_CONNECTIONS\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/MAX_CONNECTIONS",
],
Array [
"🚫 - Service \\"MAX_HEADERS_COUNT\\" not found in: /home/whoiam/projects/whook/dist/services/MAX_HEADERS_COUNT",
],
Expand All @@ -411,6 +450,9 @@ Object {
Array [
"🚫 - Service \\"MAX_HEADERS_COUNT\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/MAX_HEADERS_COUNT",
],
Array [
"🚫 - Service \\"MAX_HEADERS_COUNT\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/MAX_HEADERS_COUNT",
],
Array [
"🚫 - Service \\"PARSERS\\" not found in: /home/whoiam/projects/whook/dist/services/PARSERS",
],
Expand All @@ -420,6 +462,9 @@ Object {
Array [
"🚫 - Service \\"PARSERS\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/PARSERS",
],
Array [
"🚫 - Service \\"PARSERS\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/PARSERS",
],
Array [
"🚫 - Service \\"PROCESS_NAME\\" not found in: /home/whoiam/projects/whook/dist/services/PROCESS_NAME",
],
Expand All @@ -429,6 +474,9 @@ Object {
Array [
"🚫 - Service \\"PROCESS_NAME\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/PROCESS_NAME",
],
Array [
"🚫 - Service \\"PROCESS_NAME\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/PROCESS_NAME",
],
Array [
"🚫 - Service \\"PROTOCOL\\" not found in: /home/whoiam/projects/whook/dist/services/PROTOCOL",
],
Expand All @@ -438,6 +486,9 @@ Object {
Array [
"🚫 - Service \\"PROTOCOL\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/PROTOCOL",
],
Array [
"🚫 - Service \\"PROTOCOL\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/PROTOCOL",
],
Array [
"🚫 - Service \\"SENSIBLE_HEADERS\\" not found in: /home/whoiam/projects/whook/dist/services/SENSIBLE_HEADERS",
],
Expand All @@ -447,6 +498,9 @@ Object {
Array [
"🚫 - Service \\"SENSIBLE_HEADERS\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/SENSIBLE_HEADERS",
],
Array [
"🚫 - Service \\"SENSIBLE_HEADERS\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/SENSIBLE_HEADERS",
],
Array [
"🚫 - Service \\"SENSIBLE_PROPS\\" not found in: /home/whoiam/projects/whook/dist/services/SENSIBLE_PROPS",
],
Expand All @@ -456,6 +510,9 @@ Object {
Array [
"🚫 - Service \\"SENSIBLE_PROPS\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/SENSIBLE_PROPS",
],
Array [
"🚫 - Service \\"SENSIBLE_PROPS\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/SENSIBLE_PROPS",
],
Array [
"🚫 - Service \\"SHIELD_CHAR\\" not found in: /home/whoiam/projects/whook/dist/services/SHIELD_CHAR",
],
Expand All @@ -465,6 +522,9 @@ Object {
Array [
"🚫 - Service \\"SHIELD_CHAR\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/SHIELD_CHAR",
],
Array [
"🚫 - Service \\"SHIELD_CHAR\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/SHIELD_CHAR",
],
Array [
"🚫 - Service \\"SIGNALS\\" not found in: /home/whoiam/projects/whook/dist/services/SIGNALS",
],
Expand All @@ -474,6 +534,9 @@ Object {
Array [
"🚫 - Service \\"SIGNALS\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/SIGNALS",
],
Array [
"🚫 - Service \\"SIGNALS\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/SIGNALS",
],
Array [
"🚫 - Service \\"SOCKET_TIMEOUT\\" not found in: /home/whoiam/projects/whook/dist/services/SOCKET_TIMEOUT",
],
Expand All @@ -483,6 +546,9 @@ Object {
Array [
"🚫 - Service \\"SOCKET_TIMEOUT\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/SOCKET_TIMEOUT",
],
Array [
"🚫 - Service \\"SOCKET_TIMEOUT\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/SOCKET_TIMEOUT",
],
Array [
"🚫 - Service \\"STRINGIFYERS\\" not found in: /home/whoiam/projects/whook/dist/services/STRINGIFYERS",
],
Expand All @@ -492,6 +558,9 @@ Object {
Array [
"🚫 - Service \\"STRINGIFYERS\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/STRINGIFYERS",
],
Array [
"🚫 - Service \\"STRINGIFYERS\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/STRINGIFYERS",
],
Array [
"🚫 - Service \\"TIMEOUT\\" not found in: /home/whoiam/projects/whook/dist/services/TIMEOUT",
],
Expand All @@ -501,6 +570,9 @@ Object {
Array [
"🚫 - Service \\"TIMEOUT\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/TIMEOUT",
],
Array [
"🚫 - Service \\"TIMEOUT\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/TIMEOUT",
],
Array [
"🚫 - Service \\"getPingWrapped\\" not found in: /home/whoiam/projects/whook/packages/whook-cli/dist/handlers/getPing",
],
Expand All @@ -516,6 +588,9 @@ Object {
Array [
"🚫 - Service \\"readDir\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/readDir",
],
Array [
"🚫 - Service \\"readDir\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/readDir",
],
Array [
"🚫 - Service \\"require\\" not found in: /home/whoiam/projects/whook/dist/services/require",
],
Expand All @@ -525,6 +600,9 @@ Object {
Array [
"🚫 - Service \\"require\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/require",
],
Array [
"🚫 - Service \\"require\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/require",
],
Array [
"🚫 - Service \\"uniqueId\\" not found in: /home/whoiam/projects/whook/dist/services/uniqueId",
],
Expand All @@ -534,6 +612,9 @@ Object {
Array [
"🚫 - Service \\"uniqueId\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/uniqueId",
],
Array [
"🚫 - Service \\"uniqueId\\" not found in: /home/whoiam/projects/whook/packages/whook-gcp-functions/dist/services/uniqueId",
],
Array [
"πŸ€– - Initializing the \`$autoload\` service.",
],
Expand Down
Loading

0 comments on commit fa55331

Please sign in to comment.