Skip to content

Commit eac5451

Browse files
authored
feat(janus-idp/cli): package-dynamic-plugins update annotations (#2609)
* feat(janus-idp/cli): package-dynamic-plugins update annotations - rename com.redhat.rhdh.plugins to io.backstage.dynamic-packages to make it more "upstream friendly" - add io.backstage.marketplace/<plugin-name> annotations, value is read from file specified by optional --marketplace flag - use base64 for anotation values Signed-off-by: Tomas Kral <[email protected]> * add changeset * fix typos --------- Signed-off-by: Tomas Kral <[email protected]>
1 parent 37f0b43 commit eac5451

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

.changeset/flat-avocados-appear.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@janus-idp/cli": major
3+
---
4+
changes to package-dynamic-plugins command:
5+
6+
- rename com.redhat.rhdh.plugins to io.backstage.dynamic-packages to make it more "upstream friendly"
7+
- add io.backstage.marketplace/<plugin-name> annotations, value is read from file specified by optional --marketplace flag
8+
- use base64 for annotation values

packages/cli/src/commands/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ export function registerScriptCommand(program: Command) {
186186
'By defult, the command uses podman to build the container image. Use this flag to use docker instead.',
187187
false,
188188
)
189+
.option(
190+
'-m, --marketplace-file <file>',
191+
'Marketplace yaml file. This is a Plugin entity definition for Marketplace.',
192+
)
189193
.action(
190194
lazy(() => import('./package-dynamic-plugins').then(m => m.command)),
191195
);

packages/cli/src/commands/package-dynamic-plugins/command.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@ import { paths } from '../../lib/paths';
1313
import { Task } from '../../lib/tasks';
1414

1515
export async function command(opts: OptionValues): Promise<void> {
16-
const { exportTo, forceExport, preserveTempDir, tag, useDocker } = opts;
16+
const {
17+
exportTo,
18+
forceExport,
19+
preserveTempDir,
20+
tag,
21+
useDocker,
22+
marketplaceFile,
23+
} = opts;
1724
if (!exportTo && !tag) {
1825
Task.error(
1926
`Neither ${chalk.white('--export-to')} or ${chalk.white('--tag')} was specified, either specify ${chalk.white('--export-to')} to export plugins to a directory or ${chalk.white('--tag')} to export plugins to a container image`,
@@ -32,6 +39,19 @@ export async function command(opts: OptionValues): Promise<void> {
3239
return;
3340
}
3441
}
42+
const maketplaceInfo: Object[] = [];
43+
if (marketplaceFile) {
44+
if (!fs.existsSync(marketplaceFile)) {
45+
Task.error(`Marketplace file ${marketplaceFile} does not exist`);
46+
return;
47+
}
48+
const yamlDocuments = YAML.parseAllDocuments(
49+
fs.readFileSync(marketplaceFile).toLocaleString(),
50+
);
51+
for (const document of yamlDocuments) {
52+
maketplaceInfo.push(document.toJS());
53+
}
54+
}
3555
const workspacePackage = (await fs.readJson(
3656
paths.resolveTarget('package.json'),
3757
)) as PackageJson;
@@ -183,6 +203,7 @@ export async function command(opts: OptionValues): Promise<void> {
183203
);
184204
}
185205
}
206+
186207
// Write the plugin registry metadata
187208
const metadataFile = path.join(tmpDir, 'index.json');
188209
Task.log(`Writing plugin registry metadata to '${metadataFile}'`);
@@ -200,12 +221,29 @@ export async function command(opts: OptionValues): Promise<void> {
200221
fs.copySync(source, destination, { recursive: true, overwrite: true });
201222
});
202223
} else {
224+
// collect flags for the container build command
225+
const flags = [
226+
`--annotation io.backstage.dynamic-packages='${Buffer.from(JSON.stringify(pluginRegistryMetadata)).toString('base64')}'`,
227+
];
228+
229+
for (const pluginInfo of maketplaceInfo) {
230+
const base64pluginInfo = Buffer.from(
231+
JSON.stringify(pluginInfo),
232+
).toString('base64');
233+
const pluginName = (pluginInfo as { metadata: { name: string } })
234+
.metadata.name;
235+
flags.push(
236+
`--annotation io.backstage.marketplace/${pluginName}='${base64pluginInfo}'`,
237+
);
238+
}
203239
// run the command to generate the image
204240
Task.log(`Creating image using ${containerTool}`);
205241
await Task.forCommand(
206242
`echo "from scratch
207243
COPY . .
208-
" | ${containerTool} build --annotation com.redhat.rhdh.plugins='${JSON.stringify(pluginRegistryMetadata)}' -t '${tag}' -f - .
244+
" | ${containerTool} build \
245+
${flags.join(' ')} \
246+
-t '${tag}' -f - .
209247
`,
210248
{ cwd: tmpDir },
211249
);

0 commit comments

Comments
 (0)