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

Plugin scaffold CLI #51

Merged
merged 5 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion developing-plugins/grpc-api-reference.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
last_modified_date: 2024-04-16 09:21:37
last_modified_date: 2024-04-16 15:01:00
layout: default
title: gRPC API Reference
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.
Expand Down
2 changes: 1 addition & 1 deletion developing-plugins/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
last_modified_date: 2024-04-16 09:21:37
last_modified_date: 2024-04-16 15:01:00
layout: default
title: Developing Plugins
nav_order: 4
Expand Down
65 changes: 39 additions & 26 deletions developing-plugins/plugin-developers-guide.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
last_modified_date: 2024-04-16 09:21:36
last_modified_date: 2024-05-10 11:19:14
layout: default
title: Plugin Developers Guide
description: Plugin developers' guide of GatewayD
Expand All @@ -15,30 +15,30 @@ The usage of plugin from the user perspective is described [here](/using-plugins

Follow these steps to create a plugin:

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.
2. Clone the repository and start developing your plugin.
3. Update the `gatewayd_plugins.yml` file with the correct information.
4. Test your plugin locally using the `make run` target of GatewayD.
5. Test your plugin in the CI pipeline.
6. Test your plugin using this [`test.yaml`](https://github.com/gatewayd-io/gatewayd-plugin-cache/blob/main/.github/workflows/test.yaml) workflow.
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).
8. Publish your plugin.

{: .note }
> 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.
1. Generate a plugin scaffold using the `gatewayd plugin scaffold` command.
2. Update the `gatewayd_plugins.yml` file with the correct information.
mostafa marked this conversation as resolved.
Show resolved Hide resolved
3. Test your plugin locally using the `make run` target of GatewayD.
4. Test your plugin in the CI pipeline.
5. Test your plugin using this [`test.yaml`](https://github.com/gatewayd-io/gatewayd-plugin-cache/blob/main/.github/workflows/test.yaml) workflow.
6. 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).
mostafa marked this conversation as resolved.
Show resolved Hide resolved
7. Publish your plugin.

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

## Step 1: Use the GatewayD plugin template
## Step 1: Generate a plugin scaffold

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.
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.

You can always start from scratch, but it is recommended to use the template to get started quickly.
{: .note}
> 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.

This is the structure of the template:
This is the structure of the generated directory with the scaffold command:

```bash
.
├── .github/workflows/
│   ├── commits-signed.yaml # Check if commits are signed
│   └── release.yaml # Release workflow
├── gatewayd_plugin.yaml # Metadata
├── go.mod # Dependencies
├── go.sum
Expand All @@ -53,11 +53,24 @@ This is the structure of the template:
└── README.md # Documentation
```

## Step 2: Clone the repository and start developing your plugin
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).

```yaml
remote_url: https://github.com/me/gatewayd-plugin-test
version: 0.0.1
description: This is test plugin
license: Apache-2.0
authors:
- Me <[email protected]>
```

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.
After you have created the `input.yaml` file, run the following command to generate the plugin scaffold:

```bash
gatewayd plugin scaffold --input-file input.yaml --output-dir gatewayd-plugin-test
mostafa marked this conversation as resolved.
Show resolved Hide resolved
```

## Step 3: Update the `gatewayd_plugins.yml` file with the correct information
## Step 2: Update the `gatewayd_plugins.yml` file with the correct information

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:

Expand All @@ -71,12 +84,12 @@ The following fields are optional:
- `args`: The arguments that are passed to the plugin.
- `checksum`: The checksum of the plugin binary.
mostafa marked this conversation as resolved.
Show resolved Hide resolved

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:
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:

- `MAGIC_COOKIE_KEY=GATEWAYD_PLUGIN`
- `MAGIC_COOKIE_VALUE=5712b87aa5d7e9f9e9ab643e6603181c5b796015cb1c09d6f5ada882bf2a1872`

## Step 4: Test your plugin locally using the `make run` target of GatewayD
## Step 3: Test your plugin locally using the `make run` target of GatewayD

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).

Expand All @@ -90,22 +103,22 @@ You can test your plugin locally by running GatewayD CLI in development mode. Th
{: .note }
> 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).

## Step 5: Test your plugin in the CI pipeline
## Step 4: Test your plugin in the CI pipeline

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.

## Step 6: Test your plugin using this `test.yaml` workflow
## Step 5: Test your plugin using this `test.yaml` workflow

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.

## Step 7: Publish your plugin to GitHub using this `release.yaml` workflow and this `Makefile`
## Step 6: Publish your plugin to GitHub using this `release.yaml` workflow and this `Makefile`

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.
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/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) into the `.github/workflows/` and the root directory of your plugin. This workflow will release your plugin to GitHub.
mostafa marked this conversation as resolved.
Show resolved Hide resolved

{: .note }
> You must modify the example `Makefile`, `release.yaml` and `test.yaml` files to match your plugin.
mostafa marked this conversation as resolved.
Show resolved Hide resolved

## Step 8: Publish your plugin
## Step 7: Publish your plugin

If you want GatewayD to install your plugin from GitHub, you must adhere to the following rules:

Expand Down
2 changes: 1 addition & 1 deletion developing-plugins/sdk-reference.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
last_modified_date: 2024-04-16 09:21:37
last_modified_date: 2024-04-16 15:01:00
layout: default
title: SDK Reference
description: The GatewayD plugin SDK provides a number of interfaces, structs and methods to help you build your plugin.
Expand Down
2 changes: 1 addition & 1 deletion developing-plugins/template-projects.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
last_modified_date: 2024-04-16 09:21:36
last_modified_date: 2024-04-16 15:01:00
layout: default
title: Template Projects
description: Template projects can be used to quickly get started with developing plugins.
Expand Down
2 changes: 1 addition & 1 deletion getting-started/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
last_modified_date: 2024-04-16 09:21:36
last_modified_date: 2024-04-16 15:01:00
layout: default
title: Getting Started
nav_order: 1
Expand Down
2 changes: 1 addition & 1 deletion getting-started/installation.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
last_modified_date: 2024-04-16 09:21:36
last_modified_date: 2024-04-16 15:01:00
layout: default
title: Installation
description: How to install GatewayD and its plugins on different platforms and how to build it from source.
Expand Down
2 changes: 1 addition & 1 deletion getting-started/running-gatewayd.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
last_modified_date: 2024-04-16 09:21:36
last_modified_date: 2024-04-16 15:01:00
layout: default
title: Running GatewayD
description: How to run GatewayD and test it with psql
Expand Down
2 changes: 1 addition & 1 deletion getting-started/welcome.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
last_modified_date: 2024-04-16 15:00:31
last_modified_date: 2024-04-16 15:01:00
layout: default
title: Welcome
description: Introduction to GatewayD and its key features
Expand Down
2 changes: 1 addition & 1 deletion miscellaneous/glossary.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
last_modified_date: 2024-04-16 09:21:37
last_modified_date: 2024-04-16 15:01:00
layout: default
title: Glossary
description: Glossary of GatewayD terms
Expand Down
2 changes: 1 addition & 1 deletion miscellaneous/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
last_modified_date: 2024-04-16 09:21:37
last_modified_date: 2024-04-16 15:01:00
layout: default
title: Miscellaneous
nav_order: 6
Expand Down
2 changes: 1 addition & 1 deletion miscellaneous/telemetry-and-usage-report.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
last_modified_date: 2024-04-16 09:21:37
last_modified_date: 2024-04-16 15:01:00
layout: default
title: Telemetry and Usage Report
description: Telemetry and usage report of GatewayD
Expand Down
2 changes: 1 addition & 1 deletion plugins/gatewayd-plugin-cache.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
last_modified_date: 2024-04-16 09:21:37
last_modified_date: 2024-04-16 15:01:00
layout: default
title: gatewayd-plugin-cache
description: GatewayD plugin for caching query results in Redis.
Expand Down
2 changes: 1 addition & 1 deletion plugins/gatewayd-plugin-js.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
last_modified_date: 2024-04-16 09:21:37
last_modified_date: 2024-04-16 15:01:00
layout: default
title: gatewayd-plugin-js
description: GatewayD plugin for running JS functions as hooks.
Expand Down
2 changes: 1 addition & 1 deletion plugins/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
last_modified_date: 2024-04-16 09:21:37
last_modified_date: 2024-04-16 15:01:00
layout: default
title: Plugins
nav_order: 5
Expand Down
2 changes: 1 addition & 1 deletion using-gatewayd/API.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
last_modified_date: 2024-04-16 09:21:37
last_modified_date: 2024-04-16 15:01:00
layout: default
title: API
description: GatewayD exposes a gRPC API with an HTTP gateway for querying and managing the `gatewayd` process and its plugins.
Expand Down
2 changes: 1 addition & 1 deletion using-gatewayd/Act.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
last_modified_date: 2024-04-16 09:21:37
last_modified_date: 2024-04-16 15:01:00
layout: default
title: Act
description: Act is a policy engine that supports signals, policies and actions. It is used to automate the execution of business rules.
Expand Down
Loading
Loading