Git Product home page Git Product logo

netlify-plugin-nimbella's Introduction

netlify-plugin-nimbella

Version Downloads/week License Join Slack Twitter

The Nimbella add-on for Netlify is a Netlify Build Plugin that extends Netlify Sites with portable and stateful serverless functions using Nimbella. The add-on enables developers to deploy sites to Netlify's CDN, or to use Netlify as a proxy to sites hosted on other clouds. With this plugin, developers can build APIs using serverless functions that can be hosted on a cloud of their choice using the Nimbella portable serverless cloud.

The Nimbella add-on provides the following benefits.

  1. More runtimes: implement APIs in numerous languages including Python, Rust, Swift, Ruby, PHP, Java, Go, Node, and Deno. You can even use Docker containers.
  2. Resource customization: run APIs for longer durations, and with more memory.
  3. Integrated key-value and object stores: build stateful APIs, and handle images or files with no additional resources to provision.
  4. Easier packaging: skip the hassles of web packing and working with dependencies.
  5. Cloud portability: repeatable deployments that work across clouds.

Learn more about the Nimbella add-on for Netlify on our website.

Add-On Setup

  • Netlify Build Plugins are not available on the legacy "Ubuntu Trusty 14.04" build image. Update your Netlify build image to "Ubuntu Xenial 16.04".
  • Node 12 or newer is required. You can set a Netlify Build environment variable to request a compatible Node runtime. For example set variable NODE_VERSION to 14.

New to Nimbella

Add the Nimbella add-on for Netlify to connect your Netlify site to Nimbella. You can do this in two ways: from the Netlify Site UI or from your terminal.

  • Netlify UI: Select Plugins from your Site management toolbar, and search for Nimbella in the "plugin directory" and click "Install".

  • Command Line: Run the following command from the base of your local project directory which is linked to your Netlify site.

netlify addons:create nimbella

The add-on will create a Nimbella namespace where your resources are allocated. Your Nimbella namespace includes your serverless APIs, a dedicated key-value store, and access to an integrated object store.

Existing Nimbella Developer

You can use the Nimbella add-on for Netlify with your existing Nimbella account. This is accomplished by creating a Netlify Build environment variable so the plugin can deploy the resources to the Nimbella namespace of your choosing.

  1. Use the Nimbella CLI nim or the Nimbella Workbench to export a login token. If you want to sign up for a free Nimbella account or to login, visit nimbella.com/login to get started.
nim auth export --non-expiring
  1. Next, create a Build environment variable named NIMBELLA_LOGIN_TOKEN and provide the token you just obtained as its value. You may do this from the Netlify Build UI or run the following command in your terminal netlify env:set NIMBELLA_LOGIN_TOKEN <token>.

You can optional set another Build environment variable NIMBELLA_API_HOST to indicate which Nimbella cloud you are using.

Minimal Netlify TOML Configuration

Once your add-on is configured, you can start using it by appending the section below to your netlify.toml file.

[[plugins]]
package = "netlify-plugin-nimbella"

You may provide additional configuration in the netlify.toml file. The plugin input configuration is optional, however you will want to at least set the API path to avoid CORS issues between the frontend and backend components of your cloud application.

[[plugins]]
package = "netlify-plugin-nimbella"

[plugins.inputs]
path    = "/api"   # The prefix path to access your deployed packages.
web     = false    # Deploy frontend and proxy domain to Nimbella (allowed values are true or false).
env     = []       # Environment variables to export to serverless APIs.

Understanding your Nimbella Project

The Nimbella add-on for Netlify allows you to use Nimbella projects to automate packaging and deployment. We suggest reading the documentation about Nimbella projects at some point. We provide a quick introduction here.

Nimbella projects inspect a directory named packages at the base of your repository. The contents of this directory dictate the serverless APIs that are deployed. The plugin will automatically deploy each API inside the packages directory. We use the term action to be synonymous with serverless API (or serverless function). Each API can accessed using the following pattern: https://your-site.com/<path(default="api")>/<packageName>/<actionName>.

For example, for the following project structure:

site
├── netlify.toml
├── packages
│   ├── auth
│   │   ├── login
│   │   │   └── index.js
│   │   └── logout.js
│   └── todos
│       ├── create.py
│       ├── delete.php
│       ├── list.go
│       └── update.swift
└── web
    └── index.html

The APIs are auth/login, auth/logout, todos/create, and so on. An API may be a single file, or built from a set of files within an enclosing directory. You may mix languages, and deploy functions as source, without even building languages that require compilation. To API end point for any of the actions is constructed in the same way. For example the serverless API implemented by auth/login/index.js is invoked with the REST end point https://your-site.com/api/auth/login.

Your Nimbella project may also include a web folder which can be deployed to the Nimbella cloud as well. The web folder represents the frontend assets for your projects (e.g., HTML, CSS, JavaScript). In a typical deployment of a Nimbella project using Netlify, you will use the Netlify CDN to serve your web assets.

There are however some use-cases where you want to deploy the entire project to Nimbella, and proxy to your Nimbella domain from your Netlify site. A motivation for doing this is to use a custom domain name and automatically managed SSL certificate but host your project entirely on a cloud of your choice otherwise.

To do this, you need to enable the deployment of the web portion of your project by setting an option web = true in the plugins.inputs section of your netlify.toml file.

[plugins.inputs]
# Deploy the web folder and proxy your site entirely to your Nimbella deployment.
web = true

Cleaning your Nimbella Namespace

The Nimbella project configuration (project.yml) allows for cleaning your namespace, or deployed API package. See the documentation for more details on sanitizing the namespace between deployments.

Exporting Environment Variables to Serverless APIs

If your serverless APIs require environment variables, you have to export the variables explicitly in the plugins.inputs section of the netlify.toml file. This is to avoid exporting the entire environment to your APIs, and instead selecting exporting only the variables the actions need access to.

# Export specified environment variables to the serverless APIs
[plugins.inputs]
envs = ['ENV_ONE', 'ENV_TWO']

Deploying Netlify Functions as Nimbella APIs

The plugin supports deploying your existing Netlify functions as Nimbella APIs. The plugin will automatically build your Netlify functions, and then deploy each function as an API.

Functions implemented in Node.js are deployed using Nimbella's AWS Lambda compatibility runtime so that you may not need to make any changes to your code. This will not always work. So if you encounter issues, please let us know.

If your functions directory contains files that are not in Node.js, the plugin will attempt to deploy those functions as well.

You can enable this feature by setting the plugins.inputs properties as illustrated below.

# Specify the path containing your Netlify functions
[plugins.inputs]
functions = 'functions'
timeout = 3000 # (optional) max duration in milliseconds
timeout = 512  # (optional) max amount of memory per function

Example Projects

These are few sites that use netlify-plugin-nimbella to deploy frontend content to Netlify and functions on Nimbella.

Look at netlify.toml of these repositories to get an idea on how the plugin is used.

Support

We welcome your feedback, and we are happy to help you with any issues you encounter. You may want to join our Slack community to engage with us for a more rapid response. Otherwise, open an issue and provide us with details about your situation so we can respond adequately.

License

Apache-2.0. See LICENSE to learn more.

netlify-plugin-nimbella's People

Contributors

dependabot[bot] avatar erezrokah avatar rabbah avatar satyarohith avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

netlify-plugin-nimbella's Issues

dependecies installation error

hello, i've been trying to build my site on netlify but the deploys are constantly failing and this seems to be the reason.

6:05:11 PM: ❯ Installing plugins
6:05:11 PM:    - [email protected]
6:13:00 PM: ​
6:13:00 PM:   Dependencies installation error                               
6:13:00 PM: ────────────────────────────────────────────────────────────────
6:13:00 PM: ​
6:13:00 PM:   Error message
6:13:00 PM:   Error while installing dependencies in /opt/build/repo/.netlify/plugins/
6:13:00 PM:   npm ERR! code ETIMEDOUT
6:13:00 PM:   npm ERR! syscall connect
6:13:00 PM:   npm ERR! errno ETIMEDOUT
6:13:00 PM:   npm ERR! network request to https://apigcp.nimbella.io/downloads/nim/nimbella-cli.tgz failed, reason: connect ETIMEDOUT 35.199.52.22:443
6:13:00 PM:   npm ERR! network This is a problem related to network connectivity.
6:13:00 PM:   npm ERR! network In most cases you are behind a proxy or have bad network settings.
6:13:00 PM:   npm ERR! network
6:13:00 PM:   npm ERR! network If you are behind a proxy, please make sure that the
6:13:00 PM:   npm ERR! network 'proxy' config is set properly.  See: 'npm help config'
6:13:00 PM: ​
6:13:01 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)

If nimbella wont work is there any other way to work with python api in netlify?

Login isn't working anymore after using `npx nim auth`

The following error is thrown.

10:01:01 PM: npx: installed 9 in 1.623s
10:01:01 PM: Cannot find module 'auth'
10:01:01 PM: Require stack:
10:01:01 PM: - /opt/buildhome/.npm/_npx/1344/lib/node_modules/nim/index.js
10:01:01 PM: - /opt/buildhome/.npm/_npx/1344/lib/node_modules/nim/bin/nim.js
10:01:02 PM: Error: Command failed with exit code 1: npx nim auth login ****
10:01:02 PM:     at makeError (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/execa/lib/error.js:56:11)
10:01:02 PM:     at handlePromise (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/execa/index.js:114:26)
10:01:02 PM:     at processTicksAndRejections (internal/process/task_queues.js:97:5)
10:01:02 PM:     at async onPreBuild (/opt/build/repo/netlify-plugin-nimbella/index.js:76:9)
10:01:02 PM:     at async Object.run (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins/child/run.js:17:3)
10:01:02 PM:     at async handleEvent (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins/child/main.js:34:38)
10:01:02 PM:     at async process.<anonymous> (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins/ipc.js:102:9) {
10:01:02 PM:   command: 'npx nim auth login ****',
10:01:02 PM:   exitCode: 1,
10:01:02 PM:   signal: undefined,
10:01:02 PM:   signalDescription: undefined,
10:01:02 PM:   stdout: '',
10:01:02 PM:   stderr: 'npx: installed 9 in 1.623s\n' +
10:01:02 PM:     "Cannot find module 'auth'\n" +
10:01:02 PM:     'Require stack:\n' +
10:01:02 PM:     '- /opt/buildhome/.npm/_npx/1344/lib/node_modules/nim/index.js\n' +
10:01:02 PM:     '- /opt/buildhome/.npm/_npx/1344/lib/node_modules/nim/bin/nim.js',
10:01:02 PM:   failed: true,
10:01:02 PM:   timedOut: false,
10:01:02 PM:   isCanceled: false,
10:01:02 PM:   killed: false
10:01:02 PM: }

Question: is a different endpoint generated per deploy context?

I'm not completely sure how this work on Nimbella's end, but is a separate endpoint created per deploy context?

e.g. if I run the plugin from a production context, then from a branch/Deploy Preview context would those endpoints co-exist on Nimbella's end?

Bug: plugin fails with an error when there is no [nimbella] setting in netlify.toml

To reproduce:
Use https://github.com/nimbella/netlify-plugin-nimbella#minimal-netlify-toml-configuration, e.g. a netlify.toml as such:

[[plugins]]
package = "netlify-plugin-nimbella"

See https://app.netlify.com/sites/determined-johnson-c85a62/deploys/5f79bdc630173a00089717dc

Error message:

Error: Cannot read property 'functions' of undefined

I believe this error is coming from:

isActions = existsSync(config.nimbella.functions);

I would also recommend checking if netlify.toml exists as some sites don't have it (e.g. you install the plugin using the UI)

Feature: cleanup old functions

Not sure if this is a feature. bug or a discussion.

Should the plugin remove old functions on each deploy? I noticed that if I delete a function locally and push the changes the endpoint is still available.

That might be confusing to some users.

Bug: TypeError: Cannot read property 'functions' of undefined when trying to build Netlify functions

I'm trying to follow https://github.com/nimbella/netlify-plugin-nimbella#deploy-netlify-functions-on-nimbella-cloud

and getting this error:
https://app.netlify.com/sites/erez-build-reproductions/deploys/5f7c3a3e676f5553e5d3bb04

I believe it's coming from https://github.com/satyarohith/netlify-lambda/blob/0096a57fa11601b87eb20dbffe29166ed8f5df8e/lib/build.js#L34 expecting to find the removed nimbella configuration. Looks like it should get that information from the plugin inputs

Feature: print functions endpoints to logs after deploy

I'm having a hard time accessing my functions after a successful deploy:
https://app.netlify.com/sites/determined-johnson-c85a62/deploys/5f79cbb4b714649255cbc826
https://github.com/erezrokah/netlify-build-reproductions/blob/plugin/nimbella/netlify.toml

My project structure is:

├── functions
│   └── hello.js
├── netlify.toml
├── packages
│   └── auth
│       └── login.js
├── public
│   └── index.html

I tried:

curl -i -L https://5f79cbb4b714649255cbc826--determined-johnson-c85a62.netlify.app/.netlify/functions/default/hello
curl -i -L https://5f79cbb4b714649255cbc826--determined-johnson-c85a62.netlify.app/.netlify/functions/hello

curl -i -L https://5f79cbb4b714649255cbc826--determined-johnson-c85a62.netlify.app/.netlify/functions/auth/login

All resulting in failures.

Also:

$ nim action get auth/login --url
$ https://apigcp.nimbella.io/api/v1/web/erezroka-0sjnfe3jhr5/auth/login
$ nim action get hello --url
$ https://apigcp.nimbella.io/api/v1/web/erezroka-0sjnfe3jhr5/default/hello

Trying to curl the above URLs also fails.

What am I doing wrong?

It might be useful to print the excepted endpoint so users can easily verify them.

Failure to install plugin dependencies

Hello, I'm getting an error while trying to install the plugin's dependencies:

12:20:37 PM: ────────────────────────────────────────────────────────────────
12:20:37 PM:   Dependencies installation error                               
12:20:37 PM: ────────────────────────────────────────────────────────────────
12:20:37 PM: ​
12:20:37 PM:   Error message
12:20:37 PM:   Error while installing dependencies in /opt/build/repo/.netlify/plugins/
12:20:37 PM:   npm ERR! code E404
12:20:37 PM:   npm ERR! 404 Not Found - GET https://apigcp.nimbella.io/downloads/nim/nim-v1.8.0/nim-v1.8.0.tar.gz
12:20:37 PM:   npm ERR! 404
12:20:37 PM:   npm ERR! 404  'nimbella-cli@https://apigcp.nimbella.io/downloads/nim/nim-v1.8.0/nim-v1.8.0.tar.gz' is not in the npm registry.
12:20:37 PM:   npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
12:20:37 PM:   npm ERR! 404 It was specified as a dependency of 'netlify-plugin-nimbella'
12:20:37 PM:   npm ERR! 404
12:20:37 PM:   npm ERR! 404 Note that you can also install from a
12:20:37 PM:   npm ERR! 404 tarball, folder, http url, or git url.

https://app.netlify.com/sites/gatsby-starter-netlify-cms-erez/deploys/5fd0b29985acf600079497f8

It seems the following URL

"nimbella-cli": "https://apigcp.nimbella.io/downloads/nim/nim-v1.8.0/nim-v1.8.0.tar.gz"
returns 404

Chore: add nim CLI as a dependency instead of globally installing on each build

Currently the plugin installs the CLI on each build, which can be quite slow.

Netlify build installs all plugins dependencies before the build starts and we even pre-install dependencies in our build image for official plugins in https://github.com/netlify/plugins to make that process faster.

Also, the plugin uses npm which might conflict with users using another package manager (e.g. yarn).

See here an example of a plugin using a CLI as a local dependency.

Specifying dependencies versions is also important for creating consistent and reproducible builds

Bug: netlify addons:auth nimbella redirects to https://nimbella.com/

I tried following the README by running netlify addons:create nimbella and netlify addons:auth nimbell.

netlify addons:create nimbella creates the addon, netlify addons:auth nimbella creates the auth link and opens the browser, but redirects to https://nimbella.com/.

I was able to use an existing account with nim auth export --non-expiring.

Feel free to close this if this flow is not intended to work yet.

Feature: allow login to different Nimbella API hosts

The plugin assumes an API host. Add an environment variable to permit other API hosts.

const {stdout} = await utils.run.command('nim auth current', {
stdout: 'pipe'
});
console.log(`Using the following namespace: ${stdout}`);
} catch (error) {

This can be set using a netlify env var NIMBELLA_API_HOST set to the desired api host, defaulting to a standard host if not specified.

This crashes when the publish directory does not exist

constants.PUBLISH_DIR is always defined, but might point to a directory which does not exist.
When this happens, this plugin crashes at the following line:

await appendFile(redirectsFile, redirectRules.join('\n'));

ENOTDIR: not a directory, open 'index.html/_redirects' 
    /opt/build/repo/.netlify/plugins/node_modules/netlify-plugin-nimbella/index.js:189:19 onPostBuild

This can be fixed by creating constants.PUBLISH_DIR directory if it does not exist (e.g. using a library like make-dir).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.