Skip to content

Commit e3cb596

Browse files
authored
Plugin scaffold CLI (#51)
* Add doc for plugin scaffold command * Update plugin developers' guide * Update timestamps * Address comments by @zeina1i * Update timestamps
1 parent bbea24e commit e3cb596

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+105
-94
lines changed

developing-plugins/grpc-api-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
last_modified_date: 2024-04-16 09:21:37
2+
last_modified_date: 2024-05-11 20:53:27
33
layout: default
44
title: gRPC API Reference
55
description: GatewayD exposes a gRPC API that can be used to interact with the GatewayD plugin system. This API can be used by the GatewayD plugins and is available in the GatewayD SDK.

developing-plugins/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
last_modified_date: 2024-04-16 09:21:37
2+
last_modified_date: 2024-05-11 20:53:27
33
layout: default
44
title: Developing Plugins
55
nav_order: 4

developing-plugins/plugin-developers-guide.md

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
last_modified_date: 2024-04-16 09:21:36
2+
last_modified_date: 2024-05-11 21:33:25
33
layout: default
44
title: Plugin Developers Guide
55
description: Plugin developers' guide of GatewayD
@@ -15,30 +15,29 @@ The usage of plugin from the user perspective is described [here](/using-plugins
1515

1616
Follow these steps to create a plugin:
1717

18-
1. Use the [GatewayD plugin template for Go](https://github.com/gatewayd-io/plugin-template-go) repository to create a new repository for your plugin.
19-
2. Clone the repository and start developing your plugin.
20-
3. Update the `gatewayd_plugins.yml` file with the correct information.
21-
4. Test your plugin locally using the `make run` target of GatewayD.
22-
5. Test your plugin in the CI pipeline.
23-
6. Test your plugin using this [`test.yaml`](https://github.com/gatewayd-io/gatewayd-plugin-cache/blob/main/.github/workflows/test.yaml) workflow.
24-
7. Publish your plugin to GitHub using this [`release.yaml`](https://github.com/gatewayd-io/gatewayd-plugin-cache/blob/main/.github/workflows/release.yaml) workflow and this [`Makefile`](https://github.com/gatewayd-io/gatewayd-plugin-cache/blob/main/Makefile).
25-
8. Publish your plugin.
26-
27-
{: .note }
28-
> You can also use the [GatewayD plugin template for Python](https://github.com/gatewayd-io/plugin-template-python) repository to create a new repository for your plugin. The project is not as mature as the Go template and might have some rough edges.
18+
1. Generate a plugin scaffold using the `gatewayd plugin scaffold` command.
19+
2. Update the `gatewayd_plugins.yml` file with the correct information.
20+
3. Test your plugin locally using the `make run` target of GatewayD.
21+
4. Test your plugin in the CI pipeline.
22+
5. Test your plugin using this [`test.yaml`](https://github.com/gatewayd-io/gatewayd-plugin-cache/blob/main/.github/workflows/test.yaml) workflow.
23+
6. Publish your plugin to GitHub using this [`release.yaml`](https://github.com/gatewayd-io/gatewayd/blob/main/plugin/.template/project/%7B%7B%20plugin_name%20%7D%7D/.github/workflows/release.yaml) workflow and this [`Makefile`](https://github.com/gatewayd-io/gatewayd/blob/main/plugin/.template/project/%7B%7B%20plugin_name%20%7D%7D/Makefile).
2924

3025
In the following sections, each step is described in more detail.
3126

32-
## Step 1: Use the GatewayD plugin template
27+
## Step 1: Generate a plugin scaffold
3328

34-
The [GatewayD plugin template for Go](https://github.com/gatewayd-io/plugin-template-go) repository contains a template for a plugin. You can use this template to create a new repository for your plugin. As a concrete example, the [cache plugin](https://github.com/gatewayd-io/gatewayd-plugin-cache) contains a `Makefile` and a GitHub workflow to test and release your plugin.
29+
The `gatewayd plugin scaffold` command generates a plugin scaffold for you. You can use the scaffolds, which is based on the [GatewayD plugin template for Go](https://github.com/gatewayd-io/plugin-template-go) project, to create your own plugin. The generated scaffold contains all the hooks you can use with typical message payloads, which you can safely remove. The scaffold contains all the necessary workflows, `Makefile` and metadata files to get you started quickly.
3530

36-
You can always start from scratch, but it is recommended to use the template to get started quickly.
31+
{: .note}
32+
> Previously, the [GatewayD plugin template for Go](https://github.com/gatewayd-io/plugin-template-go) project could be used to create a plugin. This project is now deprecated and the `gatewayd plugin scaffold` command should be used instead.
3733
38-
This is the structure of the template:
34+
This is the structure of the generated directory with the scaffold command:
3935

4036
```bash
4137
.
38+
├── .github/workflows/
39+
│   ├── commits-signed.yaml # Check if commits are signed
40+
│   └── release.yaml # Release workflow
4241
├── gatewayd_plugin.yaml # Metadata
4342
├── go.mod # Dependencies
4443
├── go.sum
@@ -53,11 +52,24 @@ This is the structure of the template:
5352
└── README.md # Documentation
5453
```
5554

56-
## Step 2: Clone the repository and start developing your plugin
55+
To run the command, you need to have an `input.yaml` file that contains the following information. This file is used to scaffold the plugin, which you can find an example [here](https://raw.githubusercontent.com/gatewayd-io/gatewayd/main/plugin/.template/input.example.yaml).
56+
57+
```yaml
58+
remote_url: https://github.com/me/gatewayd-plugin-test
59+
version: 0.0.1
60+
description: This is test plugin
61+
license: Apache-2.0
62+
authors:
63+
- Me <me@example.com>
64+
```
65+
66+
After you have created the `input.yaml` file, run the following command to generate the plugin scaffold:
5767

58-
After you have created a new repository for your plugin, clone it and start developing your plugin. The template contains a `Makefile` with targets to build the plugin, create checksum and update dependencies. You can use these targets to build your plugin.
68+
```bash
69+
gatewayd plugin scaffold --input-file input.yaml --output-dir gatewayd-plugin-test
70+
```
5971

60-
## Step 3: Update the `gatewayd_plugins.yml` file with the correct information
72+
## Step 2: Update the `gatewayd_plugins.yml` file with the correct information
6173

6274
The `gatewayd_plugins.yml` file contains the metadata of your plugin. This file is used by GatewayD to load your plugin. The following fields are required:
6375

@@ -71,12 +83,15 @@ The following fields are optional:
7183
- `args`: The arguments that are passed to the plugin.
7284
- `checksum`: The checksum of the plugin binary.
7385

74-
These two environment variables with their exact values are required. They must be passed to the [HandshakeConfig](https://github.com/gatewayd-io/plugin-template-go/blob/c103e739467a9814086508e1e8257871c00932e4/main.go#L44-L45) of the plugin. These pieces of information are used by GatewayD to verify and load the plugin:
86+
{: .note }
87+
> Use the `./gatewayd run --dev` command to disable plugin checksum verification when developing a plugin. Otherwise, the plugin will not be loaded or you must change the checksum every time you make a change to the plugin. **This is not recommended for production.**
88+
89+
These two environment variables with their exact values are required. They must be passed to the [HandshakeConfig](https://github.com/gatewayd-io/gatewayd/blob/1709235b0629fc591b29473551f8f623926662cb/plugin/.template/project/%7B%7B%20plugin_name%20%7D%7D/main.go#L44-L45) of the plugin. These pieces of information are used by GatewayD to verify and load the plugin:
7590

7691
- `MAGIC_COOKIE_KEY=GATEWAYD_PLUGIN`
7792
- `MAGIC_COOKIE_VALUE=5712b87aa5d7e9f9e9ab643e6603181c5b796015cb1c09d6f5ada882bf2a1872`
7893

79-
## Step 4: Test your plugin locally using the `make run` target of GatewayD
94+
## Step 3: Test your plugin locally using the `make run` target of GatewayD
8095

8196
You can test your plugin locally by running GatewayD CLI in development mode. The development mode lets your test your plugin without checksum verification. For more information, see GatewayD [CLI](/using-gatewayd/CLI).
8297

@@ -90,32 +105,27 @@ You can test your plugin locally by running GatewayD CLI in development mode. Th
90105
{: .note }
91106
> It is recommended to use the `trace` log level to see the logs of your plugin. For more information, see [loggers](/using-gatewayd/global-configuration/loggers).
92107

93-
## Step 5: Test your plugin in the CI pipeline
108+
## Step 4: Test your plugin in the CI pipeline
94109

95110
Copy the [`test-plugin`](https://github.com/gatewayd-io/gatewayd/blob/213ba09fbf20f0b3923d246d4320dab46fdf8be3/.github/workflows/test.yaml#L61-L144) job of the GatewayD CI pipeline into the `.github/workflows/test.yaml` file. This job will test your plugin using the [GatewayD CLI](/using-gatewayd/CLI) in development mode.
96111

97-
## Step 6: Test your plugin using this `test.yaml` workflow
112+
## Step 5: Test your plugin using this `test.yaml` workflow
98113

99114
If you have written tests for your plugin, you can use the following workflow to test your plugin. Copy the [`test.yaml`](https://github.com/gatewayd-io/gatewayd-plugin-cache/blob/main/.github/workflows/test.yaml) workflow into the `.github/workflows/` directory of your plugin. This workflow will test your plugin using the [GatewayD CLI](/using-gatewayd/CLI) in development mode.
100115

101-
## Step 7: Publish your plugin to GitHub using this `release.yaml` workflow and this `Makefile`
102-
103-
If you want to publish your plugin to GitHub, you can use the following workflow and `Makefile` to release your plugin. Copy the [`release.yaml`](https://github.com/gatewayd-io/gatewayd-plugin-cache/blob/main/.github/workflows/release.yaml) workflow and this [`Makefile`](https://github.com/gatewayd-io/gatewayd-plugin-cache/blob/main/Makefile) into the `.github/workflows/` and the root directory of your plugin. This workflow will release your plugin to GitHub.
104-
105-
{: .note }
106-
> You must modify the example `Makefile`, `release.yaml` and `test.yaml` files to match your plugin.
116+
## Step 6: Publish your plugin to GitHub
107117

108-
## Step 8: Publish your plugin
118+
If you want to publish your plugin to GitHub, you can use the `release.yaml` workflow and `Makefile` that are generated as part of the scaffold files in the `.github/workflows` directory. All you have to do is to push your changes to your desired GitHub repository and create a release with the tag, for example v0.1.0. The workflow will [build](https://github.com/gatewayd-io/gatewayd/blob/51bb3a48edd783ff623234c8c34c4bfa335ae045/plugin/.template/project/%7B%7B%20plugin_name%20%7D%7D/Makefile#L25-L32) your plugin for three platforms and two CPU architectures, create a release with the given tag, and upload the plugin binaries (as archive files) and `checksums.txt` as release assets, just like [this](https://github.com/gatewayd-io/gatewayd-plugin-cache/releases/latest).
109119

110-
If you want GatewayD to install your plugin from GitHub, you must adhere to the following rules:
120+
Now, if you want GatewayD to install your plugin from GitHub, you must adhere to the following rules:
111121

112122
1. The plugin binary must be named as the repository name, aka. the plugin name.
113123
2. The plugin binary must be placed in the root directory of the release asset.
114-
3. The checksums should be generated using sha256sum, published as release assets and named `checksums.txt`.
115-
4. The release assets must be published as `tar.gz` archives.
116-
5. The release assets must follow the naming convention: `plugin-name-$GOOS-$GOARCH-version.tar.gz`.
117-
6. The releases must follow semantic versioning and prefixed with `v`.
118-
7. The `latest` release must point to the latest release, otherwise the plugin will not be installed if the version is not specified.
124+
3. Each published release asset that contains a plugin binary must also have a `checksum.txt` file next to the plugin binary in the archive file containing the checksum of the plugin binary.
125+
4. The checksums of all the release assets should be generated using sha256sum, and published as release assets, and named `checksums.txt`.
126+
5. The release assets must be published as `tar.gz` or `.zip` archives.
127+
6. The release assets must follow the naming convention: `plugin-name-$GOOS-$GOARCH-version.tar.gz`. For example, `gatewayd-plugin-cache-linux-amd64-v0.1.0.tar.gz`.
128+
7. The name of the archive files in the release assets must follow semantic versioning and prefixed with `v`.
119129

120130
<!-- ## Step 9: Publish your plugin to the GatewayD plugin registry
121131

developing-plugins/sdk-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
last_modified_date: 2024-04-16 09:21:37
2+
last_modified_date: 2024-05-11 20:53:27
33
layout: default
44
title: SDK Reference
55
description: The GatewayD plugin SDK provides a number of interfaces, structs and methods to help you build your plugin.

developing-plugins/template-projects.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
last_modified_date: 2024-04-16 09:21:36
2+
last_modified_date: 2024-05-11 20:53:27
33
layout: default
44
title: Template Projects
55
description: Template projects can be used to quickly get started with developing plugins.

getting-started/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
last_modified_date: 2024-04-16 09:21:36
2+
last_modified_date: 2024-05-11 20:53:27
33
layout: default
44
title: Getting Started
55
nav_order: 1

getting-started/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
last_modified_date: 2024-04-16 09:21:36
2+
last_modified_date: 2024-05-11 20:53:27
33
layout: default
44
title: Installation
55
description: How to install GatewayD and its plugins on different platforms and how to build it from source.

getting-started/running-gatewayd.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
last_modified_date: 2024-04-16 09:21:36
2+
last_modified_date: 2024-05-11 20:53:27
33
layout: default
44
title: Running GatewayD
55
description: How to run GatewayD and test it with psql

getting-started/welcome.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
last_modified_date: 2024-04-16 15:00:31
2+
last_modified_date: 2024-05-11 20:53:27
33
layout: default
44
title: Welcome
55
description: Introduction to GatewayD and its key features

miscellaneous/glossary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
last_modified_date: 2024-04-16 09:21:37
2+
last_modified_date: 2024-05-11 20:53:27
33
layout: default
44
title: Glossary
55
description: Glossary of GatewayD terms

miscellaneous/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
last_modified_date: 2024-04-16 09:21:37
2+
last_modified_date: 2024-05-11 20:53:27
33
layout: default
44
title: Miscellaneous
55
nav_order: 6

miscellaneous/telemetry-and-usage-report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
last_modified_date: 2024-04-16 09:21:37
2+
last_modified_date: 2024-05-11 20:53:27
33
layout: default
44
title: Telemetry and Usage Report
55
description: Telemetry and usage report of GatewayD

plugins/gatewayd-plugin-cache.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
last_modified_date: 2024-04-16 09:21:37
2+
last_modified_date: 2024-05-11 20:53:27
33
layout: default
44
title: gatewayd-plugin-cache
55
description: GatewayD plugin for caching query results in Redis.

plugins/gatewayd-plugin-js.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
last_modified_date: 2024-04-16 09:21:37
2+
last_modified_date: 2024-05-11 20:53:27
33
layout: default
44
title: gatewayd-plugin-js
55
description: GatewayD plugin for running JS functions as hooks.

plugins/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
last_modified_date: 2024-04-16 09:21:37
2+
last_modified_date: 2024-05-11 20:53:27
33
layout: default
44
title: Plugins
55
nav_order: 5

using-gatewayd/API.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
last_modified_date: 2024-04-16 09:21:37
2+
last_modified_date: 2024-05-11 20:53:27
33
layout: default
44
title: API
55
description: GatewayD exposes a gRPC API with an HTTP gateway for querying and managing the `gatewayd` process and its plugins.

using-gatewayd/Act.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
last_modified_date: 2024-04-16 09:21:37
2+
last_modified_date: 2024-05-11 20:53:27
33
layout: default
44
title: Act
55
description: Act is a policy engine that supports signals, policies and actions. It is used to automate the execution of business rules.

0 commit comments

Comments
 (0)