Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/betahuhn/worker-setup
π·π οΈ Interactive setup and deployment of pre-made CloudFlare Workers
https://github.com/betahuhn/worker-setup
cloudflare cloudflare-worker cloudflare-wrangler wrangler wrangler-cli
Last synced: 3 months ago
JSON representation
π·π οΈ Interactive setup and deployment of pre-made CloudFlare Workers
- Host: GitHub
- URL: https://github.com/betahuhn/worker-setup
- Owner: BetaHuhn
- License: mit
- Created: 2021-05-06T13:11:17.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-16T13:07:03.000Z (about 2 years ago)
- Last Synced: 2024-11-19T07:51:13.579Z (3 months ago)
- Topics: cloudflare, cloudflare-worker, cloudflare-wrangler, wrangler, wrangler-cli
- Language: JavaScript
- Homepage: https://readme.fish/BetaHuhn/worker-setup
- Size: 1.02 MB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
β οΈ Still under development β οΈ# Worker Setup
[![Node CI](https://github.com/BetaHuhn/worker-setup/workflows/Node%20CI/badge.svg)](https://github.com/BetaHuhn/worker-setup/actions?query=workflow%3A%22Node+CI%22) [![Release CI](https://github.com/BetaHuhn/worker-setup/workflows/Release%20CI/badge.svg)](https://github.com/BetaHuhn/worker-setup/actions?query=workflow%3A%22Release+CI%22) [![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/BetaHuhn/worker-setup/blob/master/LICENSE) ![David](https://img.shields.io/david/betahuhn/worker-setup)
Interactive setup and deployment of pre-made Cloudflare Workers
![demo](https://user-images.githubusercontent.com/51766171/117510368-3e462a00-af8c-11eb-969c-011a6a8be14a.gif)
## π Introduction
While `wrangler generate` is meant to generate a completely new worker from an existing template, `worker-setup` is meant to setup a pre-made Worker like [cf-worker-redirect](https://github.com/BetaHuhn/cf-worker-redirect).
The basic wrangler configuration, required KV Namespaces, secrets and environment variables are stored in the `workerConfig.toml` file. When a user wants to setup your Worker, they can simply run `worker-setup deploy` and they will be guided through the process of logging in to their account, setting up and deploying the Worker. Required KV Namespaces are automatically created and the user is asked to input all required secrets and environment variables.
## β Features
- Generates ready-to-use wrangler.toml file filled with user specific values like Account/Zone/KV Namespace ID
- Installs and configures [Wrangler](https://github.com/cloudflare/wrangler) (Including authenticating with Cloudflare)
- Automatically creates required KV Namespaces
- Prompts the user for required Secrets and Environment Variables (and uploads them)
- Lets the user choose between deploying to [workers.dev](https://workers.dev) or a custom Zone
- Can dynamically fill wrangler.toml with user specific values using environment variables (useful for CI)## π Get started
Install [worker-setup](https://github.com/BetaHuhn/worker-setup) via npm:
```shell
npm install worker-setup
```See [below](#%EF%B8%8F-configuration) on how to configure [worker-setup](https://github.com/BetaHuhn/worker-setup) for your own Worker.
## π Usage
Run `worker-setup help` to see all available commands and options.
Here's an overview of the available commands:
### Deploy
```
worker-setup deploy
```Will start the interactive deployment process. You will be asked to login with Cloudflare if not already logged in. Required KV Namespaces are automatically created and you are asked to input all required secrets and environment variables. The final `wrangler.toml` will be generated from the template.
### Generate
```
worker-setup generate
```Will use a local `workerConfig.toml` and environment variables/.env file to generate a `wrangler.toml` (useful for CI purposes).
### Login
```
worker-setup login
```Will authenticate Wrangler with Cloudflare, either via the browser or by specifying an API token.
### Migrate
```
worker-setup migrate
```Will migrate your old `wrangler.toml` to a new `workerConfig.toml` by removing all personal fields, like account/zone id as well as the ids for kv_namespaces and values for environment variables and adding `wrangler.toml` to your `.gitignore` file. All other options will be transfered to the new config.
## π οΈ Setup
[worker-setup](https://github.com/BetaHuhn/worker-setup) uses a `workerConfig.toml` file which replaces your normal `wrangler.toml`. It supports everything you normally put into your `wrangler.toml` file as well as more (see below).
If you have an existing `wrangler.toml`, run the following to generate a new `workerConfig.toml` from your config:
```shell
worker-setup migrate
```If not, create a new `workerConfig.toml` file and fill it with your normal [Wrangler configuration options](https://developers.cloudflare.com/workers/cli-wrangler/configuration) manually.
If your Worker uses Workers KV or requires secrets/environment variables add the binding/keys as well.
When you run `worker-setup deploy`, [worker-setup](https://github.com/BetaHuhn/worker-setup) will use the `workerConfig.toml` file to know what your Worker needs and asks the user to input the required values, as well as create the required KV Namespaces. Once everything is done, it will output a normal `wrangler.toml` file and deploy the worker with [`wrangler`](https://github.com/cloudflare/wrangler).
## βοΈ Configuration
The `workerConfig.toml` file supports the following [configuration options](https://developers.cloudflare.com/workers/cli-wrangler/configuration):
| Key | Description | Required |
| ------------- | ------------- | ------------- |
| `name` | The default name of your Worker (can be changed by the user during setup) | **Yes** |
| `type` | Specifies how `wrangler build` will build your project. | **Yes** |
| `webpack_config` | This is the path to a custom webpack configuration file for your worker. | **No** |
| `site` | Determines the local folder to upload and serve from a Worker | **No** |
| `usage_model` | Specifies the [Usage Model](https://developers.cloudflare.com/workers/platform/pricing#usage-models) for your Worker. | **No** |
| `βtriggers` | Configures cron triggers for executing a Worker on a schedule | **No** |
| `dev` | Arguments for `wrangler dev`, configure local server | **No** |
| `βbuild` | Allows configuring a custom build step to be run by wrangler when building your worker. | **No** |> See [wrangler's docs](https://developers.cloudflare.com/workers/cli-wrangler/configuration) for more info on each option.
As well as these additional options:
| Key | Description | Required | Example |
| ------------- | ------------- | ------------- | ------------- |
| `kv_namespaces` | Specify the required KV namespace bindings (will be created during setup) | **No** | `[ "EXAMPLE_KV" ]` |
| `secrets` | Specify the required secrets (user will be asked to input during setup) | **No** | `[ "EXAMPLE_SECRET" ]` |
| `variables` | Specify the required plain-text variables (user will be asked to input during setup) | **No** | `[ "EXAMPLE_VARIABLE" ]` |
| `recommended_route` | A recommended route to be used with the Worker (will be shown to user) | **No** | `"*example.com/test"` |
| `instructions` | Specify additional instructions to be printed after deploying the worker | **No** | `Learn how to use the Worker at example.com` |## π Examples
Here are a few examples to help you get started!
## π Intructions for your README
Here are example intructions you can use in the README for your Worker:
---
If you want to deploy this Worker yourself, clone this repo and cd into it:
```shell
git clone https://github.com/betahuhn/cf-worker-redirect && cd cf-worker-redirect
```Next start the interactive deployment process:
```shell
worker-setup deploy
```You will be asked to login to Cloudflare if not already authenticated. The programm will guide you through the process of setting up and deploying the Worker under your own Cloudflare Account.
---
## π» Development
- run `yarn lint` or `npm run lint` to run eslint.
- run `npm link` to setup the program for development.
- run `yarn build` or `npm run build` to produce a compiled version in the `dist` folder.## β About
This project was developed by me ([@betahuhn](https://github.com/BetaHuhn)) in my free time. If you want to support me:
[![Donate via PayPal](https://img.shields.io/badge/paypal-donate-009cde.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=394RTSBEEEFEE)
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/F1F81S2RK)
**[worker-setup](https://github.com/BetaHuhn/worker-setup) is in no way affiliated with Cloudflare.**
## π License
Copyright 2021 Maximilian Schiller
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.