Skip to content

Commit 2f0e8eb

Browse files
authored
[plugins] Remove match and packages from schema (#1296)
## Summary After chatting with @Lagoja we decided to remove `packages` and `match` from plugin schema before we release custom plugins. The reason being: * `packages` is poorly defined and not a great experience. It was added so we could build plugins that install custom flakes (for php, haskell, etc) and replace planners. It was renamed to `__packages` and will not be externally documented. In very near future we plan on adding `suggested_packages` (final name TBD) which informs the user of any packages needed for a plugin and allows the user to install if needed. * `match` is designed to automatically add built-in plugins if certain packages are installed. This functionality doesn't make sense for custom plugins. This field was moved into a hardcoded map. Another benefit of removing this from schema is that we can put the plugins into the plugin github repo. cc: @Lagoja ## How was it tested? * unit tests * manual smoke testing (installed php)
1 parent 617b0a4 commit 2f0e8eb

File tree

24 files changed

+178
-86
lines changed

24 files changed

+178
-86
lines changed

docs/app/docs/guides/creating_plugins.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ Plugins are defined as Go JSON Template files, using the following schema:
2828
{
2929
"name": "",
3030
"version": "",
31-
"match": "",
3231
"readme": "",
3332
"env": {
3433
"<key>": "<value>"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[global]
2+
pid = ${PHPFPM_PID_FILE}
3+
error_log = ${PHPFPM_ERROR_LOG_FILE}
4+
daemonize = yes
5+
6+
[www]
7+
; user = www-data
8+
; group = www-data
9+
listen = 127.0.0.1:${PHPFPM_PORT}
10+
; listen.owner = www-data
11+
; listen.group = www-data
12+
pm = dynamic
13+
pm.max_children = 5
14+
pm.start_servers = 2
15+
pm.min_spare_servers = 1
16+
pm.max_spare_servers = 3
17+
chdir = /
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[php]
2+
3+
; Put your php.ini directives here. For the latest default php.ini file, see https://github.com/php/php-src/blob/master/php.ini-production
4+
5+
; memory_limit = 128M
6+
; expose_php = Off
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"packages": [],
3+
"shell": {
4+
"init_hook": [
5+
"echo 'Welcome to devbox!' > /dev/null"
6+
],
7+
"scripts": {
8+
"test": [
9+
"test -n \"$PHPRC\" || exit 1"
10+
]
11+
}
12+
},
13+
"include": [
14+
"plugin:php8"
15+
]
16+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"lockfile_version": "1",
3+
"packages": {}
4+
}

examples/stacks/lapp-stack/devbox.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"packages": {
44
55
"last_modified": "2023-05-01T16:53:22Z",
6-
"plugin_version": "0.0.1",
6+
"plugin_version": "0.0.2",
77
"resolved": "github:NixOS/nixpkgs/8670e496ffd093b60e74e7fa53526aa5920d09eb#apacheHttpd",
88
"version": "2.4.57"
99
},
@@ -19,15 +19,15 @@
1919
},
2020
2121
"last_modified": "2023-05-01T16:53:22Z",
22-
"plugin_version": "0.0.1",
22+
"plugin_version": "0.0.2",
2323
"resolved": "github:NixOS/nixpkgs/8670e496ffd093b60e74e7fa53526aa5920d09eb#php",
2424
"version": "8.1.18"
2525
},
2626
"postgresql@14": {
2727
"last_modified": "2023-05-01T16:53:22Z",
28-
"plugin_version": "0.0.1",
28+
"plugin_version": "0.0.2",
2929
"resolved": "github:NixOS/nixpkgs/8670e496ffd093b60e74e7fa53526aa5920d09eb#postgresql",
3030
"version": "14.7"
3131
}
3232
}
33-
}
33+
}

internal/cloud/openssh/config_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ func TestHostOrMatchRegex(t *testing.T) {
6060
"\tMatch all": true,
6161

6262
"Host": false,
63-
"Match": false,
6463
"Hostname devbox.sh": false,
6564
`# Host *.devbox.sh`: true,
6665
`# Match all`: true,

internal/plugin/files.go

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
package plugin
55

66
import (
7+
"io/fs"
78
"os"
8-
"regexp"
9-
"strings"
109

1110
"github.com/pkg/errors"
1211
"go.jetpack.io/devbox/internal/devpkg"
@@ -16,7 +15,7 @@ import (
1615
func getConfigIfAny(pkg Includable, projectDir string) (*config, error) {
1716
switch pkg := pkg.(type) {
1817
case *devpkg.Package:
19-
return getBuiltinPluginConfig(pkg, projectDir)
18+
return getBuiltinPluginConfigIfExists(pkg, projectDir)
2019
case *githubPlugin:
2120
return pkg.buildConfig(projectDir)
2221
case *localPlugin:
@@ -29,34 +28,16 @@ func getConfigIfAny(pkg Includable, projectDir string) (*config, error) {
2928
return nil, errors.Errorf("unknown plugin type %T", pkg)
3029
}
3130

32-
func getBuiltinPluginConfig(pkg Includable, projectDir string) (*config, error) {
33-
builtins, err := plugins.Builtins()
31+
func getBuiltinPluginConfigIfExists(
32+
pkg Includable,
33+
projectDir string,
34+
) (*config, error) {
35+
content, err := plugins.BuiltInForPackage(pkg.CanonicalName())
36+
if errors.Is(err, fs.ErrNotExist) {
37+
return nil, nil
38+
}
3439
if err != nil {
3540
return nil, errors.WithStack(err)
3641
}
37-
38-
for _, file := range builtins {
39-
// We deserialize first so we can check the Match field. If it's there
40-
// we use it, otherwise we use the name.
41-
// TODO(landau): this is weird, hard to understand code. Fetching the file
42-
// content of configs should probably not use FileContent()
43-
content, err := pkg.FileContent(file.Name())
44-
if err != nil {
45-
return nil, errors.WithStack(err)
46-
}
47-
48-
name := pkg.CanonicalName()
49-
cfg, err := buildConfig(pkg, projectDir, string(content))
50-
if err != nil {
51-
return nil, errors.WithStack(err)
52-
}
53-
// if match regex is set we use it to check. Otherwise we assume it's a
54-
// perfect match
55-
if (cfg.Match != "" && !regexp.MustCompile(cfg.Match).MatchString(name)) ||
56-
(cfg.Match == "" && strings.Split(file.Name(), ".")[0] != name) {
57-
continue
58-
}
59-
return cfg, nil
60-
}
61-
return nil, nil
42+
return buildConfig(pkg, projectDir, string(content))
6243
}

internal/plugin/plugin.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ var (
3939
type config struct {
4040
Name string `json:"name"`
4141
Version string `json:"version"`
42-
Match string `json:"match"`
4342
CreateFiles map[string]string `json:"create_files"`
44-
Packages []string `json:"packages"`
43+
Packages []string `json:"__packages"`
4544
Env map[string]string `json:"env"`
4645
Readme string `json:"readme"`
4746

plugins/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ Plugins are defined as Go JSON Template files, using the following schema:
2525
{
2626
"name": "",
2727
"version": "",
28-
"match": "",
2928
"readme": "",
3029
"env": {
3130
"<key>": "<value>"

0 commit comments

Comments
 (0)