Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Cloudflare Workers #5258

Merged
merged 18 commits into from
Sep 11, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
71 changes: 71 additions & 0 deletions docs/providers/cloudflare-workers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<!--
title: Serverless - Cloudflare Workers Documentation
menuText: Cloudflare Workers
layout: Doc
-->

<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/)
<!-- DOCS-SITE-LINK:END -->

# Cloudflare Provider Documentation

Welcome to the Serverless Cloudflare Workers documentation!

If you have any questions, [search the forums](https://forum.serverless.com?utm_source=framework-docs) or [start your own thread](https://forum.serverless.com?utm_source=framework-docs)

<div class="docsSections">
<div class="docsSection">
<div class="docsSectionHeader">
<a href="./guide/">
Cloudflare Workers Guide
</a>
</div>
<div class="test">
<ul>
<li><a href="./guide/intro.md">Intro</a></li>
<li><a href="./guide/quick-start.md">Quickstart</a></li>
<li><a href="./guide/installation.md">Installation</a></li>
<li><a href="./guide/services.md">Services</a></li>
<li><a href="./guide/functions.md">Functions</a></li>
<li><a href="./guide/events.md">Events</a></li>
<li><a href="./guide/deploying.md">Deploying</a></li>
<li><a href="./guide/debugging.md">Debugging</a></li>
<li><a href="./guide/workflow.md">Workflow</a></li>
</ul>
</div>
</div>

<div class="docsSection">
<div class="docsSectionHeader">
<a href="./cli-reference/">
Cloudflare Workers CLI Reference
</a>
</div>
<div>
<ul>
<li><a href="./cli-reference/create.md">Create</a></li>
<li><a href="./cli-reference/deploy.md">Deploy</a></li>
<li><a href="./cli-reference/invoke.md">Invoke</a></li>
<li><a href="./cli-reference/remove.md">Remove</a></li>
<li><a href="./cli-reference/plugin-list.md">Plugin List</a></li>
<li><a href="./cli-reference/plugin-search.md">Plugin Search</a></li>
<li><a href="./cli-reference/plugin-install.md">Plugin Install</a></li>
<li><a href="./cli-reference/plugin-uninstall.md">Plugin Uninstall</a></li>
</ul>
</div>
</div>

<div class="docsSection">
<div class="docsSectionHeader">
<a href="./events/">
Cloudflare Workers Events Reference
</a>
</div>
<div>
<ul>
<li><a href="./events/http.md">HTTP Events</a></li>
</ul>
</div>
</div>
</div>
15 changes: 15 additions & 0 deletions docs/providers/cloudflare-workers/cli-reference/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!--
title: Serverless - Cloudflare Workers - CLI Reference
menuText: CLI Reference
layout: Doc
-->

<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare-workers/cli-reference/)
<!-- DOCS-SITE-LINK:END -->

# Serverless Cloudflare Workers CLI Reference

Welcome to the Serverless Cloudflare Workers CLI Reference! Please select a section on the left to get started.

If you have questions, join the [chat in gitter](https://gitter.im/serverless/serverless) or [post over on the forums](http://forum.serverless.com/).
76 changes: 76 additions & 0 deletions docs/providers/cloudflare-workers/cli-reference/create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!--
title: Serverless Framework Commands - Cloudflare Workers - Create
menuText: create
menuOrder: 1
description: Creates a new Service in your current working directory
layout: Doc
-->

<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare-workers/cli-reference/create)
<!-- DOCS-SITE-LINK:END -->


# Cloudflare Workers - Create
Creates a new Serverless service in the current working directory based on the provided template.

**Create service in current working directory:**

```bash
serverless create --template cloudflare-workers
```

Or for Enterprise Cloudflare accounts:

```bash
serverless create --template cloudflare-workers-enterprise
```

**Create service in new folder:**

```bash
serverless create --template cloudflare-workers --path my-service
```

Or for Enterprise Cloudflare accounts:

```bash
serverless create --template cloudflare-workers-enterprise --path my-service
```

## Options
- `--template` or `-t` The name of one of the available templates. Required if --template-url and --template-path are not present.
- `--template-url` or `-u` The name of one of the available templates. Required if --template and --template-path are not present.
- `--template-path` The local path of your template. Required if --template and --template-url are not present.
- `--path` or `-p` The path where the service should be created.
- `--name` or `-n` the name of the service in `serverless.yml`.
## Provided lifecycle events
- `create:create`
## Available Templates for Cloudflare Workers
To see a list of available templates run `serverless create --help`
These are the current available templates for Cloudflare Workers:

- cloudflare-workers
- cloudflare-workers-enterprise

## Examples
### Creating a new service
```bash
serverless create --template cloudflare-workers --name my-special-service
```

This example will generate scaffolding for a service with `Cloudflare` as a provider. The scaffolding will be generated in the current working directory.

### Creating a named service in a (new) directory
```bash
serverless create --template cloudflare-workers --path my-new-service
```

This example will generate scaffolding for a service with `Cloudflare` as a provider. The scaffolding will be generated in the `my-new-service` directory. This directory will be created if not present. Otherwise, Serverless will use the already present directory.
Additionally, Serverless will rename the service according to the path you provide. In this example, the service will be renamed to `my-new-service`.

### Creating a new service using a local template
```bash
serverless create --template-path path/to/my/template/folder --path path/to/my/service --name my-new-service
```
This will copy the `path/to/my/template/folder` folder into `path/to/my/service` and rename the service to `my-new-service`.
50 changes: 50 additions & 0 deletions docs/providers/cloudflare-workers/cli-reference/deploy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!--
title: Serverless Framework Commands - Cloudflare Workers - Deploy
menuText: deploy
menuOrder: 2
description: Deploy your service to the specified provider
layout: Doc
-->

<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare-workers/cli-reference/deploy)
<!-- DOCS-SITE-LINK:END -->


# Cloudflare Workers - Deploy
In order to be able to deploy any Cloudflare Workers, You will need to set your Global API key from Cloudflare as an environmental variable named `CLOUDFLARE_AUTH_KEY`, and your Cloudflare account email as an environmental variable named `CLOUDFLARE_AUTH_EMAIL`. You can get your Global API key from your [Cloudflare profile](https://dash.cloudflare.com/profile) page. You will also need to set `zoneId` for your domain name in `serverless.yml` under `service.config`, the `zoneId` can be found from the overview tab after selecting the desired zone from the [Cloudflare dashboard](https://dash.cloudflare.com/).

Environmental variables are variables that live inside your terminal.

For Mac and Linux users, you can set environmental variables like this:

```bash
export CLOUDFLARE_AUTH_KEY=YOUR_API_KEY_HERE
export CLOUDFLARE_AUTH_EMAIL=YOUR_CLOUDFLARE_EMAIL
```

And for Windows (CMD) users, you can set environmental variables like this:

```bash
set CLOUDFLARE_AUTH_KEY=YOUR_API_KEY_HERE
set CLOUDFLARE_AUTH_EMAIL=YOUR_CLOUDFLARE_EMAIL
```

You’ll need to redefine your environmental variables after each time you close your terminal.

The `serverless deploy` command deploys your entire service via the Cloudflare Workers API. Run this command when you have made service changes (i.e., you edited `serverless.yml`).
Use `serverless deploy -f my-function` when you have made code changes and you want to quickly upload your updated code to Cloudflare.

```bash
serverless deploy
```

This is the simplest deployment usage possible. With this command, Serverless will deploy your service to Cloudflare.

## Options
- `--verbose` or `-v`: Shows all stack events during deployment, and display any Stack Output.
- `--function` or `-f`: Invokes `deploy function` (see above). Convenience shortcut

## Provided lifecycle events
- `deploy:deploy`
- `deploy:function:deploy`
62 changes: 62 additions & 0 deletions docs/providers/cloudflare-workers/cli-reference/invoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!--
title: Serverless Framework Commands - Fn - Invoke
menuText: invoke
menuOrder: 3
description: Invoke an Fn Function using the Serverless Framework
layout: Doc
-->

<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/fn/cli-reference/invoke)
<!-- DOCS-SITE-LINK:END -->

# Fn - Invoke

Invokes deployed function. It allows to send event data to the function, read logs and display other important information of the function invocation.

```bash
serverless invoke --function functionName
```

## Options
- `--function` or `-f` The name of the function in your service that you want to invoke. **Required**.
- `--data` or `-d` String data to be passed as an event to your function. By default data is read from standard input.
- `--path` or `-p` The path to a json file with input data to be passed to the invoked function. This path is relative to the root directory of the service.
- `--log` or `-l` If set to `true`, it will output logging data of the invocation. Default is `false`.

## Provided lifecycle events
- `invoke:invoke`

## Examples

### Fn

```bash
serverless invoke --function functionName
```

This example will invoke your deployed function on the configured Fn Api Url
endpoint. This will output the result of the invocation in your terminal.

#### Function invocation with data

```bash
serverless invoke --function functionName --data '{"name": "Bernie"}'
```

#### Function invocation with logging

```bash
serverless invoke --function functionName --log
```

Just like the first example, but will also outputs logging information about your invocation.

#### Function invocation with data passing

```bash
serverless invoke --function functionName --path lib/data.json
```

This example will pass the json data in the `lib/data.json` file (relative to the root of the service) while invoking
the specified/deployed function.
42 changes: 42 additions & 0 deletions docs/providers/cloudflare-workers/cli-reference/plugin-install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!--
title: Serverless Framework Commands - Cloudflare Workers - Plugin Install
menuText: Plugin Install
menuOrder: 7
description: Install a Serverless plugin
layout: Doc
-->

<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare-workers/cli-reference/plugin-install)
<!-- DOCS-SITE-LINK:END -->

# Plugin Install

Install a Serverless plugin and add it to the services `plugins` array. By default, a latest version is installed.
If you want a specific version, you can specify `<pluginname>@<version>` as name option.

**Note:** You might want to change the order of the plugin in the services `plugins` array.

```bash
serverless plugin install --name pluginName
```

## Options
- `--name` or `-n` The plugins name. **Required**.

## Provided lifecycle events
- `plugin:install:install`

## Examples

### Install the `serverless-webpack` plugin

```bash
serverless plugin install --name serverless-webpack
```

### Install a specific version

```bash
serverless plugin install --name serverless-webpack@3.0.0-rc.2
```
25 changes: 25 additions & 0 deletions docs/providers/cloudflare-workers/cli-reference/plugin-list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
title: Serverless Framework Commands - Cloudflare Workers - Plugin List
menuText: Plugin List
menuOrder: 5
description: List all available Serverless plugins
layout: Doc
-->

<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare-workers/cli-reference/plugin-list)
<!-- DOCS-SITE-LINK:END -->

# Plugin List

List all available plugins on the terminal. Connected to the [Serverless plugin registry](https://github.com/serverless/plugins).

```bash
serverless plugin list
```

## Options
- *None*

## Provided lifecycle events
- `plugin:list:list`
33 changes: 33 additions & 0 deletions docs/providers/cloudflare-workers/cli-reference/plugin-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!--
title: Serverless Framework Commands - Cloudflare Workers - Plugin Search
menuText: Plugin Search
menuOrder: 6
description: Search through all available Serverless plugins
layout: Doc
-->

<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare-workers/cli-reference/plugin-search)
<!-- DOCS-SITE-LINK:END -->

# Plugin Search

Search for a specific plugin based on a search query. Connected to the [Serverless plugin registry](https://github.com/serverless/plugins).

```bash
serverless plugin search --query query
```

## Options
- `--query` or `-q` The query you want to use for your search. **Required**.

## Provided lifecycle events
- `plugin:search:search`

## Examples

### Search for a `sqs` plugin

```bash
serverless plugin search --query sqs
```