Skip to content

Commit 946e8fc

Browse files
authored
RHIDP-4807: Third-party plugin installation in RHDH (redhat-developer#733)
* RHIDP-4807: Third-party plugin installation in RHDH * fixed minor issues * Incorporated review suggestions * incorporated review suggestions * fixed links and added context to install plugin assembly * review suggestions incorporated * review suggestions incorporated * review suggestions incorporated * review suggestions incorporated * review suggestions incorporated
1 parent 783442d commit 946e8fc

14 files changed

+660
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[id="assembly-install-third-party-plugins-rhdh"]
2+
= Installing third-party plugins in {product}
3+
:context: assembly-install-third-party-plugins-rhdh
4+
5+
You can install a third-party plugins in {product} without rebuilding the {product-very-short} application.
6+
7+
The location of the `dynamic-plugin-config.yaml` file depends on the deployment method. For more details, refer to xref:proc-config-dynamic-plugins-rhdh-operator_rhdh-installing-rhdh-plugins[Installing dynamic plugins with the {product} Operator] and xref:con-install-dynamic-plugin-helm_rhdh-installing-rhdh-plugins[Installing dynamic plugins using the Helm chart].
8+
9+
Plugins are defined in the `plugins` array within the `dynamic-plugin-config.yaml` file. Each plugin is represented as an object with the following properties:
10+
11+
* `package`: The plugin's package definition, which can be an OCI image, a TGZ file, a JavaScript package, or a directory path.
12+
* `disabled`: A boolean value indicating whether the plugin is enabled or disabled.
13+
* `integrity`: The integrity hash of the package, required for TGZ file and JavaScript packages.
14+
* `pluginConfig`: The plugin's configuration. For backend plugins, this is optional; for frontend plugins, it is required. The `pluginConfig` is a fragment of the `app-config.yaml` file, and any added properties are merged with the {product-very-short} `app-config.yaml` file.
15+
16+
[NOTE]
17+
====
18+
You can also load dynamic plugins from another directory, though this is intended for development or testing purposes and is not recommended for production, except for plugins included in the {product-very-short} container image.
19+
====
20+
21+
//OCI image
22+
include::../modules/dynamic-plugins/proc-load-plugin-oci-image.adoc[leveloffset=+2]
23+
24+
//TGZ file
25+
include::../modules/dynamic-plugins/proc-load-plugin-tgz-file.adoc[leveloffset=+2]
26+
27+
//JavaScript package
28+
include::../modules/dynamic-plugins/proc-load-plugin-js-package.adoc[leveloffset=+2]
29+
30+
//example third-party plugin installation
31+
include::../modules/dynamic-plugins/ref-example-third-party-plugin-installation.adoc[leveloffset=+2]
32+
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
[id="rhdh-installing-rhdh-plugins_{context}"]
22
= Installing dynamic plugins in {product}
3+
:context: rhdh-installing-rhdh-plugins
34

45
The dynamic plugin support is based on the backend plugin manager package, which is a service that scans a configured root directory (`dynamicPlugins.rootDirectory` in the `app-config.yaml` file) for dynamic plugin packages and loads them dynamically.
56

67
You can use the dynamic plugins that come preinstalled with {product} or install external dynamic plugins from a public NPM registry.
78

89
// Operator installation
9-
include::../modules/dynamic-plugins/proc-config-dynamic-plugins-rhdh-operator.adoc[leveloffset=+1]
10+
include::../modules/dynamic-plugins/proc-config-dynamic-plugins-rhdh-operator.adoc[leveloffset=+2]
1011

1112
// Helm installation
12-
include::../modules/dynamic-plugins/con-install-dynamic-plugin-helm.adoc[leveloffset=+1]
13-
include::../modules/dynamic-plugins/proc-obtaining-integrity-checksum.adoc[leveloffset=+2]
14-
include::../modules/dynamic-plugins/ref-example-dynamic-plugin-helm-installations.adoc[leveloffset=+2]
15-
include::../modules/dynamic-plugins/proc-rhdh-example-external-dynamic-plugins.adoc[leveloffset=+2]
13+
include::../modules/dynamic-plugins/con-install-dynamic-plugin-helm.adoc[leveloffset=+2]
14+
//include::../modules/dynamic-plugins/proc-obtaining-integrity-checksum.adoc[leveloffset=+3] //from tkral:This is documented in a better way in "= Installing third-party plugins in {product}" we can remove this module. It is not even placed correctly here as this is not specific to helm chart in anyway
15+
include::../modules/dynamic-plugins/ref-example-dynamic-plugin-helm-installations.adoc[leveloffset=+3]
16+
//include::../modules/dynamic-plugins/proc-rhdh-example-external-dynamic-plugins.adoc[leveloffset=+3] assemblies/dynamic-plugins/assembly-third-party-plugins-installation.adoc replaces this
1617

1718
// Air gapped environment
1819
//include::../modules/dynamic-plugins/proc-rhdh-installing-external-dynamic-plugins-airgapped.adoc[leveloffset=+1]
19-
include::../modules/dynamic-plugins/proc-using-custom-npm-registry.adoc[leveloffset=+1]
20-
21-
// Viewing installed plugins
22-
include::../modules/dynamic-plugins/proc-viewing-installed-plugins.adoc[leveloffset=+1]
20+
include::../modules/dynamic-plugins/proc-install-plugins-using-custom-npm-registry.adoc[leveloffset=+2]
2321

2422
//basic plugin configuration
2523
//include::../modules/dynamic-plugins/con-basic-config-dynamic-plugins.adoc[leveloffset=+1]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[id="assembly-package-publish-third-party-dynamic-plugin"]
2+
= Packaging and publishing third-party plugins as dynamic plugins
3+
:context: assembly-package-publish-third-party-dynamic-plugin
4+
5+
After xref:proc-export-third-party-plugins-rhdh_assembly-third-party-plugins[exporting a third-party plugin], you can package the derived package into one of the following supported formats:
6+
7+
* Open Container Initiative (OCI) image (recommended)
8+
* TGZ file
9+
* JavaScript package
10+
+
11+
[IMPORTANT]
12+
====
13+
Exported dynamic plugin packages must only be published to private NPM registries.
14+
====
15+
16+
//OCI image
17+
include::../modules/dynamic-plugins/proc-create-plugin-oci-image.adoc[leveloffset=+2]
18+
19+
//TGZ file
20+
include::../modules/dynamic-plugins/proc-create-plugin-tgz-file.adoc[leveloffset=+2]
21+
22+
//JavaScript package
23+
include::../modules/dynamic-plugins/proc-create-plugin-js-package.adoc[leveloffset=+2]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[id="assembly-third-party-plugins"]
2+
= Third-party plugins in {product}
3+
:context: assembly-third-party-plugins
4+
5+
You can integrate third-party dynamic plugins into {product} to enhance its functionality without modifying its source code or rebuilding it. To add these plugins, export them as derived packages.
6+
7+
While exporting the plugin package, you must ensure that dependencies are correctly bundled or marked as shared, depending on their relationship to the {product-short} environment.
8+
9+
To integrate a third-party plugin into {product-short}:
10+
11+
. First, obtain the plugin's source code.
12+
. Export the plugin as a dynamic plugin package. See xref:proc-export-third-party-plugins-rhdh_assembly-third-party-plugins[].
13+
. Package and publish the dynamic plugin. See xref:assembly-package-publish-third-party-dynamic-plugin[].
14+
. Install the plugin in the {product-short} environment. See xref:assembly-install-third-party-plugins-rhdh[].
15+
16+
//Export third-party plugins
17+
include::../modules/dynamic-plugins/proc-export-third-party-plugins-rhdh.adoc[leveloffset=+2]
18+
19+
//package and publish third-party plugins
20+
include::assembly-package-publish-third-party-dynamic-plugin.adoc[leveloffset=+1]
21+
22+
//Install third-party plugin
23+
include::assembly-install-third-party-plugins-rhdh.adoc[leveloffset=+1]
24+
25+
26+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[id="proc-create-plugin-js-package_{context}"]
2+
= Creating a JavaScript package with dynamic packages
3+
4+
[WARNING]
5+
====
6+
The derived dynamic plugin JavaScript packages must not be published to the public NPM registry. If you must publish to the NPM registry, use a private registry.
7+
====
8+
9+
.Prerequisites
10+
* You have exported a third-party dynamic plugin package. For more information, see xref:proc-export-third-party-plugins-rhdh_assembly-third-party-plugins[].
11+
12+
.Procedure
13+
. Navigate to the `dist-dynamic` directory.
14+
. Run the following command to publish the package to your private NPM registry:
15+
+
16+
--
17+
.Example command to publish a plugin package to an NPM registry
18+
[source,terminal]
19+
----
20+
npm publish --registry <npm_registry_url>
21+
----
22+
23+
[TIP]
24+
====
25+
You can add the following to your `package.json` file before running the `export` command:
26+
27+
.Example `package.json` file
28+
[source,json]
29+
----
30+
{
31+
"publishConfig": {
32+
"registry": "<npm_registry_url>"
33+
}
34+
}
35+
----
36+
37+
If you modify `publishConfig` after exporting the dynamic plugin, re-run the `export-dynamic-plugin` command to ensure the correct configuration is included.
38+
====
39+
--
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[id="proc-create-plugin-oci-image_{context}"]
2+
= Creating an OCI image with dynamic packages
3+
4+
.Prerequisites
5+
* You have installed `podman` or `docker`.
6+
* You have exported a third-party dynamic plugin package. For more information, see xref:proc-export-third-party-plugins-rhdh_assembly-third-party-plugins[].
7+
8+
.Procedure
9+
. Navigate to the plugin's root directory (not the `dist-dynamic` directory).
10+
. Run the following command to package the plugin into an OCI image:
11+
+
12+
--
13+
.Example command to package an exported third-party plugin
14+
[source,terminal]
15+
----
16+
npx @janus-idp/cli@latest package package-dynamic-plugins --tag quay.io/example/image:v0.0.1
17+
----
18+
19+
In the previous command, the `--tag` argument specifies the image name and tag.
20+
--
21+
. Run one of the following commands to push the image to a registry:
22+
+
23+
--
24+
.Example command to push an image to a registry using podman
25+
[source,terminal]
26+
----
27+
podman push quay.io/example/image:v0.0.1
28+
----
29+
30+
.Example command to push an image to a registry using docker
31+
[source,terminal]
32+
----
33+
docker push quay.io/example/image:v0.0.1
34+
----
35+
36+
The output of the `package-dynamic-plugins` command provides the plugin's path for use in the `dynamic-plugin-config.yaml` file.
37+
--
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
[id="proc-create-plugin-tgz-file_{context}"]
2+
= Creating a TGZ file with dynamic packages
3+
4+
.Prerequisites
5+
* You have exported a third-party dynamic plugin package. For more information, see xref:proc-export-third-party-plugins-rhdh_assembly-third-party-plugins[].
6+
7+
.Procedure
8+
. Navigate to the `dist-dynamic` directory.
9+
. Run the following command to create a `tgz` archive:
10+
+
11+
--
12+
.Example command to create a `tgz` archive
13+
[source,terminal]
14+
----
15+
npm pack
16+
----
17+
You can obtain the integrity hash from the output of the `npm pack` command by using the `--json` flag as follows:
18+
19+
.Example command to obtain the integrity hash of a `tgz` archive
20+
[source,terminal]
21+
----
22+
npm pack --json | head -n 10
23+
----
24+
--
25+
26+
. Host the archive on a web server accessible to your {product-very-short} instance, and reference its URL in the `dynamic-plugin-config.yaml` file as follows:
27+
+
28+
--
29+
.Example `dynamic-plugin-config.yaml` file
30+
[source,yaml]
31+
----
32+
plugins:
33+
- package: https://example.com/backstage-plugin-myplugin-1.0.0.tgz
34+
integrity: sha512-<hash>
35+
----
36+
--
37+
. Run the following command to package the plugins:
38+
+
39+
--
40+
.Example command to package a dynamic plugin
41+
[source,terminal]
42+
----
43+
npm pack --pack-destination ~/test/dynamic-plugins-root/
44+
----
45+
46+
[TIP]
47+
====
48+
To create a plugin registry using HTTP server on {ocp-short}, run the following commands:
49+
50+
.Example commands to build and deploy an HTTP server in {ocp-short}
51+
[source,terminal]
52+
----
53+
oc project rhdh
54+
oc new-build httpd --name=plugin-registry --binary
55+
oc start-build plugin-registry --from-dir=dynamic-plugins-root --wait
56+
oc new-app --image-stream=plugin-registry
57+
----
58+
====
59+
--
60+
61+
. Configure your {product-very-short} to use plugins from the HTTP server by editing the `dynamic-plugin-config.yaml` file:
62+
+
63+
--
64+
.Example configuration to use packaged plugins in {product-very-short}
65+
[source,yaml]
66+
----
67+
plugins:
68+
- package: http://plugin-registry:8080/backstage-plugin-myplugin-1.9.6.tgz
69+
----
70+
--
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
[id="proc-export-third-party-plugins-rhdh_{context}"]
2+
= Exporting third-party plugins in {product}
3+
4+
To use plugins in {product}, you can export plugins as derived dynamic plugin packages. These packages contain the plugin code and dependencies, ready for dynamic plugin integration into {product-short}.
5+
6+
.Prerequisites
7+
* The `@janus-idp/cli` package is installed. Use the latest version (`@latest` tag) for compatibility with the most recent features and fixes.
8+
* Node.js and NPM is installed and configured.
9+
* The third-party plugin is compatible with your {product} version. For more information, see link:https://github.com/janus-idp/backstage-showcase/blob/main/docs/dynamic-plugins/versions.md[Version compatibility matrix].
10+
* The third-party plugin must have a valid `package.json` file in its root directory, containing all required metadata and dependencies.
11+
+
12+
--
13+
Backend plugins::
14+
+
15+
To ensure compatibility with the dynamic plugin support and enable their use as dynamic plugins, existing backend plugins must be compatible with the new Backstage backend system. Additionally, these plugins must be rebuilt using a dedicated CLI command.
16+
+
17+
The new Backstage backend system entry point (created using `createBackendPlugin()` or `createBackendModule()`) must be exported as the default export from either the main package or an `alpha` package (if the plugin instance support is still provided using `alpha` APIs). This doesn't add any additional requirement on top of the standard plugin development guidelines of the plugin instance.
18+
+
19+
The dynamic export mechanism identifies private dependencies and sets the `bundleDependencies` field in the `package.json` file. This export mechanism ensures that the dynamic plugin package is published as a self-contained package, with its private dependencies bundled in a private `node_modules` folder.
20+
+
21+
Certain plugin dependencies require specific handling in the derived packages, such as:
22+
+
23+
* *Shared dependencies* are provided by the {product-very-short} application and listed as `peerDependencies` in `package.json` file, not bundled in the dynamic plugin package. For example, by default, all `@backstage` scoped packages are shared.
24+
+
25+
You can use the `--shared-package` flag to specify shared dependencies, that are expected to be provided by {product} application and not bundled in the dynamic plugin package.
26+
+
27+
To treat a `@backstage` package as private, use the negation prefix (`!`). For example, when a plugin depends on the package in `@backstage` that is not provided by the {product} application.
28+
29+
* *Embedded dependencies* are bundled into the dynamic plugin package with their dependencies hoisted to the top level. By default, packages with `-node` or `-common` suffixes are embedded.
30+
+
31+
You can use the `--embed-package` flag to specify additional embedded packages. For example, packages from the same workspace that do not follow the default naming convention.
32+
+
33+
The following is an example of exporting a dynamic plugin with shared and embedded packages:
34+
+
35+
.Example dynamic plugin export with shared and embedded packages
36+
[source,terminal]
37+
----
38+
npx @janus-idp/cli@latest export-dynamic-plugin --shared-package '!/@backstage/plugin-notifications/' <1> --embed-package @backstage/plugin-notifications-backend <2>
39+
----
40+
+
41+
<1> `@backstage/plugin-notifications` package is treated as a private dependency and is bundled in the dynamic plugin package, despite being in the `@backstage` scope.
42+
<2> `@backstage/plugin-notifications-backend` package is marked as an embedded dependency and is bundled in the dynamic plugin package.
43+
44+
Front-end plugins::
45+
+
46+
Front-end plugins can use `scalprum` for configuration, which the CLI can generate automatically during the export process. The generated default configuration is logged when running the following command:
47+
+
48+
.Example command to log the default configuration
49+
[source,terminal]
50+
----
51+
npx @janus-idp/cli@latest export-dynamic
52+
----
53+
+
54+
The following is an example of default `scalprum` configuration:
55+
+
56+
.Default `scalprum` configuration
57+
[source,json]
58+
----
59+
"scalprum": {
60+
"name": "<package_name>", // The Webpack container name matches the NPM package name, with "@" replaced by "." and "/" removed.
61+
"exposedModules": {
62+
"PluginRoot": "./src/index.ts" // The default module name is "PluginRoot" and doesn't need explicit specification in the app-config.yaml file.
63+
}
64+
}
65+
----
66+
+
67+
You can add a `scalprum` section to the `package.json` file. For example:
68+
+
69+
.Example `scalprum` customization
70+
[source,json]
71+
----
72+
"scalprum": {
73+
"name": "custom-package-name",
74+
"exposedModules": {
75+
"FooModuleName": "./src/foo.ts",
76+
"BarModuleName": "./src/bar.ts"
77+
// Define multiple modules here, with each exposed as a separate entry point in the Webpack container.
78+
}
79+
}
80+
----
81+
+
82+
Dynamic plugins might need adjustments for {product-short} needs, such as static JSX for mountpoints or dynamic routes. These changes are optional but might be incompatible with static plugins.
83+
+
84+
To include static JSX, define an additional export and use it as the dynamic plugin's `importName`. For example:
85+
+
86+
.Example static and dynamic plugin export
87+
[source,tsx]
88+
----
89+
// For a static plugin
90+
export const EntityTechdocsContent = () => {...}
91+
92+
// For a dynamic plugin
93+
export const DynamicEntityTechdocsContent = {
94+
element: EntityTechdocsContent,
95+
staticJSXContent: (
96+
<TechDocsAddons>
97+
<ReportIssue />
98+
</TechDocsAddons>
99+
),
100+
};
101+
----
102+
--
103+
104+
.Procedure
105+
* Use the `package export-dynamic-plugin` command from the `@janus-idp/cli` package to export the plugin:
106+
+
107+
--
108+
.Example command to export a third-party plugin
109+
[source,terminal]
110+
----
111+
npx @janus-idp/cli@latest package export-dynamic-plugin
112+
----
113+
114+
Ensure that you execute the previous command in the root directory of the plugin's JavaScript package (containing `package.json` file).
115+
116+
The resulting derived package will be located in the `dist-dynamic` subfolder. The exported package name consists of the original plugin name with `-dynamic` appended.
117+
118+
[WARNING]
119+
====
120+
The derived dynamic plugin JavaScript packages must not be published to the public NPM registry. For more appropriate packaging options, see xref:assembly-package-publish-third-party-dynamic-plugin[]. If you must publish to the NPM registry, use a private registry.
121+
====
122+
--
123+
124+

0 commit comments

Comments
 (0)