You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Summary
Update Plugin documentation in response to #1499.
* Adds more details about how to include/add a plugin
* Updated schema to match upcoming init_hook improvements
* Adds suggestions on how to structure the plugin directory, along with
an example from mongodb
## How was it tested?
Localhost, also check the preview URL from Vercel below
Copy file name to clipboardExpand all lines: docs/app/docs/guides/creating_plugins.md
+80-27Lines changed: 80 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,40 +8,33 @@ Plugins make it easier to get started with packages that require additional setu
8
8
9
9
Before writing a plugin, we recommend reading the [User Documentation](https://www.jetpack.io/devbox/docs/guides/plugins/) on plugins, as well as inspecting and testing a few of the plugins in the [plugin directory](https://github.com/jetpack-io/devbox/tree/main/plugins) of our repo. Note that the plugins in this directory are compiled into the Devbox binary, but your plugin can be sourced from a local directory or from within your project.
10
10
11
-
12
11
If you're looking for plugin ideas, check out our [Issues page](https://github.com/jetpack-io/devbox/issues?q=is%3Aissue+is%3Aopen+label%3A%22plugin+request%22) for any user requests.
13
12
14
13
Before contributing, please consult our [Contributing Guide](https://github.com/jetpack-io/devbox/CONTRIBUTING.md) and [Code of Conduct](https://github.com/jetpack-io/devbox/CODE_OF_CONDUCT.md) for details on how to contribute to Devbox.
15
14
16
-
### Testing your Plugin
15
+
##Creating a Plugin
17
16
18
-
1. Create a new `devbox.json` in an empty directory using `devbox init`.
19
-
2. Add your plugin to the `include` section of the `devbox.json` file. Add any expected packages using `devbox add <pkg>`.
20
-
3. Check that your plugin creates the correct files and environment variables when running `devbox shell`
21
-
4. If you are looking for sample projects to test your plugin with, check out our [examples](https://github.com/jetpack-io/devbox/tree/main/examples).
17
+
We recommend organizing your plugin with the following directory structure, where the top-level folder matches the name of your plugin:
22
18
23
-
## Plugin Design
19
+
```
20
+
my-plugin/
21
+
├── README.md
22
+
├── plugin.json
23
+
├── config/
24
+
│ ├── my-plugin.conf
25
+
│ └── process-compose.yaml
26
+
└── test/
27
+
├── devbox.json
28
+
└── devbox.lock
29
+
```
24
30
25
-
Plugins are defined as Go JSON Template files, using the following schema:
31
+
***README.md** -- Should contain a description of how your plugin works, and what files, variables, and services it adds to Devbox Projects
32
+
***plugin.json** -- This file is a Go JSON Template that defines your plugin. See the sections below for more detail
33
+
***config/** -- This folder contains any support or configuration files required by your plugin, as well as the process-compose.yaml for defining services
34
+
***test/** -- This directory contains an example project for testing your plugin
26
35
27
-
```json
28
-
{
29
-
"name": "",
30
-
"version": "",
31
-
"readme": "",
32
-
"env": {
33
-
"<key>": "<value>"
34
-
},
35
-
"create_files": {
36
-
"<destination>": "<source>"
37
-
},
38
-
"init_hook": [
39
-
"<bash commands>"
40
-
]
41
-
}
42
-
```
43
36
44
-
A plugin can define services by adding a `process-compose.yaml` file in its `create_files` stanza.
37
+
## Plugin Design
45
38
46
39
### Plugin Lifecycle
47
40
@@ -62,6 +55,31 @@ flowchart TD
62
55
H[Start Services]
63
56
```
64
57
58
+
### Plugin.json Schema
59
+
60
+
Plugins are defined as Go JSON Template files, using the following schema:
61
+
62
+
```json
63
+
{
64
+
"name": "",
65
+
"version": "",
66
+
"readme": "",
67
+
"env": {
68
+
"<key>": "<value>"
69
+
},
70
+
"create_files": {
71
+
"<destination>": "<source>"
72
+
},
73
+
"shell": {
74
+
"init_hook": [
75
+
"<bash commands>"
76
+
]
77
+
}
78
+
}
79
+
```
80
+
81
+
A plugin can define services by adding a `process-compose.yaml` file in its `create_files` stanza.
82
+
65
83
### Template Placeholders
66
84
67
85
Devbox's Plugin System provides a few special placeholders that should be used when specifying paths for env variables and helper files:
@@ -108,9 +126,11 @@ Will copy the Caddyfile in the `plugins/caddy` folder to `devbox.d/caddy/Caddyfi
108
126
109
127
You should use this to copy starter config files or templates needed to run the plugin's package.
110
128
111
-
#### `init_hook`*string | string[]*
129
+
#### `shell.init_hook`*string | string[]*
130
+
131
+
A single `bash` command or list of `bash` commands that should run before the user's shell is initialized.
112
132
113
-
A single `bash` command or list of `bash` commands that should run before the user's shell is initialized. This will run every time a shell is started, so you should avoid any resource heavy or long running processes in this step.
133
+
This will run every time a shell is started, so you should avoid any resource heavy or long running processes in this step.
114
134
115
135
### Adding Services
116
136
@@ -120,6 +140,39 @@ Plugins can add services to a user's project by adding a `process-compose.yaml`
120
140
121
141
See the process compose [docs](https://github.com/F1bonacc1/process-compose) for details on how to write define services in `process-compose.yaml`. You can also check the plugins in this directory for examples on how to write services.
122
142
143
+
## Testing your Plugin
144
+
145
+
Testing plugins can be done using an example Devbox project. Follow the steps below to create a new test project
146
+
147
+
1. Create a new `devbox.json` in an empty directory using `devbox init`.
148
+
2. Add your plugin to the `include` section of the `devbox.json` file.
149
+
2. Add any expected packages using `devbox add <pkg>`.
150
+
3. Check that your plugin creates the correct files and environment variables when running `devbox shell`
151
+
4. If you are looking for sample projects to test your plugin with, check out our [examples](https://github.com/jetpack-io/devbox/tree/main/examples).
152
+
153
+
154
+
## Example: MongoDB
155
+
156
+
The plugin.json below sets the environment variables and config needed to run MongoDB in Devbox. You can view the full example at
157
+
158
+
```json
159
+
{
160
+
"name": "mongodb",
161
+
"version": "0.0.1",
162
+
"readme": "Plugin for the [`mongodb`](https://www.nixhub.io/packages/mongodb) package. This plugin configures MonogoDB to use a local config file and data directory for this project, and configures a mongodb service.",
Copy file name to clipboardExpand all lines: docs/app/docs/guides/plugins.md
+28-10Lines changed: 28 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,22 @@ title: Using Plugins
4
4
5
5
This doc describes how to use Devbox Plugins with your project. **Plugins** provide a default Devbox configuration for a Nix package. Plugins make it easier to get started with packages that require additional setup when installed with Nix, and they offer a familiar interface for configuring packages. They also help keep all of your project's configuration within your project directory, which helps maintain portability and isolation.
6
6
7
-
If a plugin is available for your package, it will activate when you install the plugin using `devbox add <package name>`.
7
+
## Using Plugins
8
+
9
+
### Built-in PLguins
10
+
11
+
If you add one of the packages listed above to your project using `devbox add <pkg>`, Devbox will automatically activate the plugin for that package.
12
+
13
+
You can also explicitly add a built-in plugin in your project by adding it to the [`include` section](../configuration.md#include) of your `devbox.json` file. For example, to explicitly add the plugin for Nginx, you can add the following to your `devbox.json` file:
14
+
15
+
```json
16
+
{
17
+
"include": [
18
+
"plugin:nginx"
19
+
]
20
+
}
21
+
```
8
22
9
-
## Current Plugins
10
23
Built-in plugins are available for the following packages. You can activate the plugins for these packages by running `devbox add <package_name>`
Our team is rapidly adding new plugins to Devbox. If you want to request a plugin, please file an issue in the Devbox Repo.
24
36
25
-
##Using Plugins
37
+
### Local PLugins
26
38
27
-
If you add one of the packages listed above to your project using `devbox add <pkg>`, Devbox will automatically activate the plugin for that package.
39
+
You can also [define your own plugins](./creating_plugins.md) and use them in your project. To use a local plugin, add the following to the `include` section of your devbox.json:
28
40
29
-
You can also explicitly add a plugin in your project by adding it to the [`includes` section](../configuration.md#includes) of your `devbox.json` file. For example, to explicitly add the plugin for Nginx, you can add the following to your `devbox.json` file:
41
+
```json
42
+
"include": [
43
+
"path:./path/to/plugin.json"
44
+
]
45
+
```
46
+
47
+
### Github Hosted Plugins
48
+
49
+
Sometimes, you may want to share a plugin across multiple projects or users. In this case, you provide a Github reference to a plugin hosted on Github. To install a github hosted plugin, add the following to the include section of your devbox.json
0 commit comments