@pzwik/nx-gcloud-functions-plugin
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

nx-gcloud-functions-plugin

This library was being developed to support the deployment of Google Cloud Functions via one simple command while working with the Nx Monorepo.

Prerequisites

  • GCP account
  • Enabled at least following technologies/APIs on GCP: Deployment Manager, Cloud Functions, Storage
  • gcloud SDK installed
  • Make sure to have run gcloud auth login to be able to run the gcloud commands from your CLI
  • Nx Monorepo workspace

How to install the plugin

npm install -D @pzwik/nx-gcloud-function-deployment-plugin

Run installed plugin in workspace to create new cloud function app

nx generate @pzwik/nx-gcloud-functions-plugin:nxGcloudFunctionsPlugin YOUR_FUNC_NAME

How to use

Possible folder structure after you build you app:

.
├── dist
|   ├── apps
|   |   ├── myfunction
|   |   |   ├── configurable_functions.jinja
|   |   |   ├── deployment.yaml
|   |   |   ├── index.js
|   |   |   └── package.json

Snippet of workspace.json from your Nx workspace with example configuration for the above folder structure.

{
    "myfunction": {
        "root": "apps/myfunction",
        "sourceRoot": "apps/myfunction/src",
        "projectType": "application",
        "prefix": "myfunction",
        "schematics": {},
        "architect": {
            "deploy": {
                "builder": "@pzwik/nx-gcloud-function-deployment-plugin:build",
                "options": {
                    "files": ["dist/apps/myfunction/index.js", "dist/apps/myfunction/package.json"],
                    "deploymentYamlPath": "dist/apps/myfunction/deployment.yaml",
                    "bucketName": "myfunction-bucket",
                    "deploymentName": "myfunction-deployment"
                }
            }
        }
    }
}

An example .jinja file which is imported by the deployment.yaml, of course you can also do it without the .jinja and use only the deployment.yaml file:

### configurable_functions.jinja ###
resources:
- type: gcp-types/cloudfunctions-v1:projects.locations.functions
  name: {{ env['deployment'] }}-function
  properties:
    parent: projects/{{ env['project'] }}/locations/{{ properties['region'] }}
    function: {{ env['deployment'] }}
    sourceArchiveUrl: gs://{{ properties['codeBucket'] }}/{{ properties['codeBucketObject'] }}
    entryPoint: {{ properties['entryPoint'] }}
    runtime: {{ properties['runtime'] }}
    availableMemoryMb: {{ properties['availableMemoryMb'] }}
    timeout: {{ properties['timeout'] }}
    httpsTrigger: {}

The deployment.yaml file that describes the cloud function which should be deployed via the Google Deployment Manager:

### deployment.yaml ###
imports:
  - path: configurable_functions.jinja
resources:
  - name: myfunction
    type: configurable_functions.jinja
    properties:
      codeBucket: myfunction-bucket
      codeBucketObject: WILL_BE_OVERWRITTEN_ANYWAY.zip
      region: europe-west1
      entryPoint: handler
      runtime: nodejs8
      availableMemoryMb: 256
      timeout: 60s

Donate

If you like the plugin feel free to donate some $$$ for coffee :-) NX GCloud Function Plugin MoneyPool

Package Sidebar

Install

npm i @pzwik/nx-gcloud-functions-plugin

Weekly Downloads

104

Version

0.0.6

License

ISC

Unpacked Size

44.3 kB

Total Files

51

Last publish

Collaborators

  • pzwik