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 Apr 6, 2020
1 parent 2650251 commit 9771b85
Show file tree
Hide file tree
Showing 12 changed files with 605 additions and 26 deletions.

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 @@ -174,12 +174,14 @@ Mr Bean
"@whook/authorization": "<current_version>",
"@whook/cli": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/gcp-functions": "^3.1.3",
"@whook/http-router": "<current_version>",
"@whook/http-transaction": "^3.1.3",
"@whook/swagger-ui": "<current_version>",
"@whook/whook": "<current_version>",
"common-services": "^7.1.4",
"http-auth-utils": "^2.5.0",
"js-yaml": "^3.13.1",
"knifecycle": "^9.1.1",
"strict-qs": "^6.1.1",
"yerror": "^5.0.0",
Expand Down Expand Up @@ -291,7 +293,7 @@ Mr Bean
},
"private": true,
"scripts": Object {
"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 @@ -304,7 +306,7 @@ Mr Bean
"prettier": "prettier --write 'src/**/*.ts'",
"preversion": "npm run compile",
"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",
"whook": "NODE_ENV=\${NODE_ENV:-development} whook",
"whook-dev": "PROJECT_SRC=\\"$PWD/src\\" NODE_ENV=\${NODE_ENV:-development} babel-node --extensions '.ts,.js' -- node_modules/@whook/cli/bin/whook.js",
Expand Down Expand Up @@ -427,12 +429,14 @@ Mr Bean
"@whook/authorization": "<current_version>",
"@whook/cli": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/gcp-functions": "^3.1.3",
"@whook/http-router": "<current_version>",
"@whook/http-transaction": "^3.1.3",
"@whook/swagger-ui": "<current_version>",
"@whook/whook": "<current_version>",
"common-services": "^7.1.4",
"http-auth-utils": "^2.5.0",
"js-yaml": "^3.13.1",
"knifecycle": "^9.1.1",
"strict-qs": "^6.1.1",
"yerror": "^5.0.0",
Expand Down Expand Up @@ -544,7 +548,7 @@ Mr Bean
},
"private": true,
"scripts": Object {
"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 @@ -557,7 +561,7 @@ Mr Bean
"prettier": "prettier --write 'src/**/*.ts'",
"preversion": "npm run compile",
"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",
"whook": "NODE_ENV=\${NODE_ENV:-development} whook",
"whook-dev": "PROJECT_SRC=\\"$PWD/src\\" NODE_ENV=\${NODE_ENV:-development} babel-node --extensions '.ts,.js' -- node_modules/@whook/cli/bin/whook.js",
Expand Down Expand Up @@ -665,12 +669,14 @@ Mr Bean
"@whook/authorization": "<current_version>",
"@whook/cli": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/gcp-functions": "^3.1.3",
"@whook/http-router": "<current_version>",
"@whook/http-transaction": "^3.1.3",
"@whook/swagger-ui": "<current_version>",
"@whook/whook": "<current_version>",
"common-services": "^7.1.4",
"http-auth-utils": "^2.5.0",
"js-yaml": "^3.13.1",
"knifecycle": "^9.1.1",
"strict-qs": "^6.1.1",
"yerror": "^5.0.0",
Expand Down Expand Up @@ -782,7 +788,7 @@ Mr Bean
},
"private": true,
"scripts": Object {
"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 @@ -795,7 +801,7 @@ Mr Bean
"prettier": "prettier --write 'src/**/*.ts'",
"preversion": "npm run compile",
"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",
"whook": "NODE_ENV=\${NODE_ENV:-development} whook",
"whook-dev": "PROJECT_SRC=\\"$PWD/src\\" NODE_ENV=\${NODE_ENV:-development} babel-node --extensions '.ts,.js' -- node_modules/@whook/cli/bin/whook.js",
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 @@ -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
6 changes: 4 additions & 2 deletions packages/whook-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
}
},
"scripts": {
"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 @@ -57,7 +57,7 @@
"prettier": "prettier --write 'src/**/*.ts'",
"preversion": "npm run compile",
"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",
"whook": "NODE_ENV=${NODE_ENV:-development} whook",
"whook-dev": "PROJECT_SRC=\"$PWD/src\" NODE_ENV=${NODE_ENV:-development} babel-node --extensions '.ts,.js' -- node_modules/@whook/cli/bin/whook.js"
Expand All @@ -80,12 +80,14 @@
"@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.1.4",
"http-auth-utils": "^2.5.0",
"js-yaml": "^3.13.1",
"knifecycle": "^9.1.1",
"strict-qs": "^6.1.1",
"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,8 +25,16 @@ 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/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 @@ -39,9 +47,6 @@ Object {
# Provided by \\"@whook/whook\\": none
# Provided by \\"@whook/cors\\": none
",
}
`;
Loading

0 comments on commit 9771b85

Please sign in to comment.