New plugin architecture: How to build?

Hello,

We are currently switching to Elasticsearch/Kibana 7.9.1 and creating new plugins, following the new architecture.

We were already using our own plugins before, and were building them via the build command of the plugin-helpers.

As the new plugins no longer use a package.json file, is it still possible de generate an archive/a binary? Is it possible to create a ZIP archive with all the files and distribute it as is?

I haven't found any information on that topic, sorry :frowning:

Cheers

Hi Dasko,

Our documentation is unfortunately still a bit scattered. To build a plugin distributable archive you can use the kibana plugin helpers (there's some documentation here: https://github.com/elastic/kibana/tree/master/packages/kbn-plugin-helpers)

  1. Create a plugin with a kibana.json file inside kibana/plugins i.e. kibana/plugins/myplugin
  2. cd kibana/plugins/myplugin
  3. run node ../../scripts/plugin_helpers.js build

Feel free to reach out if you have any problems...

Hi Rudolf,
after build and install plugin for 7.9.1 Kibana don't start with error

FATAL  Error: Cannot find module '/usr/share/kibana/plugins/my_plugin'

and no index.js file in /usr/share/kibana/plugins/my_plugin and in my_plugin.zip

@16318a22907f3cbfa04b It seems plugin_helpers build only legacy plugins in 7.9.
1.Could you update Kibana to 7.10?
2.Did you use plugin-generator to create my_plugin structure? If so, yarn build in /plugins/my_plugin will build a distributable version.
3.index.js is not required in/plugins/my_plugin folder.

  1. I need plugin for 7.9.1
  2. Yes, I use plugin-generator
  3. I must use some dependency. Plugin-generator don't create package.json. So I had to create it manually. It looks like this
{
  "name": "my_plugin",
  "version": "1.0.0",
  "kibana": {
    "version": "7.9.1",
    "templateVersion": "1.0.0"
  },
  "license": "Apache-2.0",
  "scripts": {
    "kbn": "node ../../scripts/kbn.js",
    "build": "plugin-helpers build",
    "start": "node ../../scripts/kibana --dev",
    "lint:es": "node ../../scripts/eslint",
    "lint:sass": "node ../../scripts/sasslint",
    "lint": "yarn run lint:es && yarn run lint:sass"
  },
  "devDependencies": {
    "@kbn/plugin-helpers": "link:../../packages/kbn-plugin-helpers"
  },
  "dependencies": {
    "@hapi/joi": "^17.1.1",
    "@types/hapi__joi": "^17.1.6",
    "pg": "^8.4.2",
    "typescript": "^4.0.5"
  }
}

file .kibana-plugin-helpers.json look like this

{
  "buildSourcePatterns": [
    "package.json",
    "yarn.lock",
    "tsconfig.json",
    "{public,server}/**/*",
    "kibana.json"
  ]
}

kibana.json as created by plugin-generator

{
  "id": "myPlugin",
  "version": "7.9.1",
  "server": true,
  "ui": true,
  "requiredPlugins": ["navigation"],
  "optionalPlugins": []
}

Now yarn build create plugin zip and I can install plugin. Kibana starts with plugin. I see it in the list on the console (cli) when kibana starts. Now no errors. But kibana don't work, I see red banner when connect to http.
With yarn start --oss everything work fine.
Maybe someone has an example of how to build a plugin with dependencies

as it seems from kibana.json manifest file

{
  "id": "myPlugin",
  "version": "7.9.1",
  "server": true,
  "ui": true,
  "requiredPlugins": ["navigation"],
  "optionalPlugins": []
}

you are trying to build Kibana Platform plugin, but unfortunately plugin_helpers build only Legacy plugins in 7.9. You have to use this workaround https://github.com/elastic/kibana/issues/82466 or migrate Kibana to 7.10 where this problem has been fixed.

As I understand from what I read, the Kibana Platform plugin cannot use any additional nodejs modules. Is this correct? If this is incorrect, how and where should I specify dependencies?

no, you are fine to use any modules. make sure you declared deps in your package.json and run yarn kbn bootstrap

I think I'm getting something wrong. If I can't use plugin-helpers, maybe I should do the build in some other way? Should I use node scripts/build_kibana_platform_plugins --dist? My plugin is made in a new format. What is the correct build sequence in this case?

All right. I Should have looked here. Now everything is working. I will only add that the plugin archive should be done on Linux. On a Windows machine it turns out to be incorrect and there will be an error during installation Plugin installation was unsuccessful due to error "EACCES: permission denied, open '/usr/share/kibana/plugins/.plugin.installing/package.json'"
No more problems.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.