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 Dec 20, 2022
1 parent a38cf72 commit 97f053f
Show file tree
Hide file tree
Showing 16 changed files with 620 additions and 9 deletions.
4 changes: 4 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Wayne Campbell
"dependencies": {
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/gcp-functions": "^11.0.1",
"@whook/http-router": "<current_version>",
"@whook/http-server": "<current_version>",
"@whook/http-transaction": "<current_version>",
Expand All @@ -127,6 +128,7 @@ Wayne Campbell
"openapi-schema-validator": "^12.0.2",
"openapi-types": "^12.1.0",
"pkg-dir": "^7.0.0",
"js-yaml": "^3.13.1",
"strict-qs": "^7.0.1",
"type-fest": "^3.4.0",
"yerror": "^6.2.1",
Expand Down Expand Up @@ -416,6 +418,7 @@ Wayne Campbell
"dependencies": {
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/gcp-functions": "^11.0.1",
"@whook/http-router": "<current_version>",
"@whook/http-server": "<current_version>",
"@whook/http-transaction": "<current_version>",
Expand All @@ -428,6 +431,7 @@ Wayne Campbell
"openapi-schema-validator": "^12.0.2",
"openapi-types": "^12.1.0",
"pkg-dir": "^7.0.0",
"js-yaml": "^3.13.1",
"strict-qs": "^7.0.1",
"type-fest": "^3.4.0",
"yerror": "^6.2.1",
Expand Down Expand Up @@ -749,6 +753,7 @@ Wayne Campbell
"dependencies": {
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/gcp-functions": "^11.0.1",
"@whook/http-router": "<current_version>",
"@whook/http-server": "<current_version>",
"@whook/http-transaction": "<current_version>",
Expand All @@ -761,6 +766,7 @@ Wayne Campbell
"openapi-schema-validator": "^12.0.2",
"openapi-types": "^12.1.0",
"pkg-dir": "^7.0.0",
"js-yaml": "^3.13.1",
"strict-qs": "^7.0.1",
"type-fest": "^3.4.0",
"yerror": "^6.2.1",
Expand Down Expand Up @@ -1070,6 +1076,7 @@ Wayne Campbell
"dependencies": {
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/gcp-functions": "^11.0.1",
"@whook/http-router": "<current_version>",
"@whook/http-server": "<current_version>",
"@whook/http-transaction": "<current_version>",
Expand All @@ -1082,6 +1089,7 @@ Wayne Campbell
"openapi-schema-validator": "^12.0.2",
"openapi-types": "^12.1.0",
"pkg-dir": "^7.0.0",
"js-yaml": "^3.13.1",
"strict-qs": "^7.0.1",
"type-fest": "^3.4.0",
"yerror": "^6.2.1",
Expand Down
6 changes: 6 additions & 0 deletions packages/whook-create/src/services/createWhook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,15 @@ Mr Bean
"dependencies": {
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/gcp-functions": "^11.0.1",
"@whook/http-router": "<current_version>",
"@whook/http-server": "<current_version>",
"@whook/http-transaction": "<current_version>",
"@whook/swagger-ui": "<current_version>",
"@whook/whook": "<current_version>",
"common-services": "^12.0.0",
"http-auth-utils": "^3.0.4",
"js-yaml": "^3.13.1",
"jwt-service": "^9.0.2",
"knifecycle": "^14.1.0",
"openapi-schema-validator": "^12.0.2",
Expand Down Expand Up @@ -363,13 +365,15 @@ Mr Bean
"dependencies": {
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/gcp-functions": "^11.0.1",
"@whook/http-router": "<current_version>",
"@whook/http-server": "<current_version>",
"@whook/http-transaction": "<current_version>",
"@whook/swagger-ui": "<current_version>",
"@whook/whook": "<current_version>",
"common-services": "^12.0.0",
"http-auth-utils": "^3.0.4",
"js-yaml": "^3.13.1",
"jwt-service": "^9.0.2",
"knifecycle": "^14.1.0",
"openapi-schema-validator": "^12.0.2",
Expand Down Expand Up @@ -568,13 +572,15 @@ Mr Bean
"dependencies": {
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/gcp-functions": "^11.0.1",
"@whook/http-router": "<current_version>",
"@whook/http-server": "<current_version>",
"@whook/http-transaction": "<current_version>",
"@whook/swagger-ui": "<current_version>",
"@whook/whook": "<current_version>",
"common-services": "^12.0.0",
"http-auth-utils": "^3.0.4",
"js-yaml": "^3.13.1",
"jwt-service": "^9.0.2",
"knifecycle": "^14.1.0",
"openapi-schema-validator": "^12.0.2",
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 @@ -92,6 +92,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 @@ -79,6 +79,7 @@
"dependencies": {
"@whook/authorization": "^11.0.1",
"@whook/cors": "^11.0.1",
"@whook/gcp-functions": "^11.0.1",
"@whook/http-router": "^11.0.1",
"@whook/http-server": "^11.0.1",
"@whook/http-transaction": "^11.0.1",
Expand All @@ -91,6 +92,7 @@
"openapi-schema-validator": "^12.0.2",
"openapi-types": "^12.1.0",
"pkg-dir": "^7.0.0",
"js-yaml": "^3.13.1",
"strict-qs": "^7.0.1",
"type-fest": "^3.4.0",
"yerror": "^6.2.1",
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 @@ -28,8 +28,16 @@ exports[`commands should work with ls 1`] = `
",
"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/gcp-functions": 1 commands
- testHTTPFunction: A command for testing GCP HTTP function
# Provided by "@whook/cors": none
# Provided by "@whook/whook": 8 commands
Expand All @@ -41,9 +49,6 @@ exports[`commands should work with ls 1`] = `
- handler: Runs the given server handler for testing purpose
- inspect: A simple program that returns the result of the injected service
- ls: Print available commands
# Provided by "@whook/cors": none
",
}
`;
Loading

0 comments on commit 97f053f

Please sign in to comment.