Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(janus-idp/cli): package-dynamic-plugins update annotations #2609

Merged
merged 4 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/flat-avocados-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@janus-idp/cli": major
---
changes to package-dynamic-plugins command:

- 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
kadel marked this conversation as resolved.
Show resolved Hide resolved
- use base64 for annotation values
4 changes: 4 additions & 0 deletions packages/cli/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ export function registerScriptCommand(program: Command) {
'By defult, the command uses podman to build the container image. Use this flag to use docker instead.',
false,
)
.option(
'-m, --marketplace-file <file>',
'Marketplace yaml file. This is a Plugin entity definition for Marketplace.',
)
.action(
lazy(() => import('./package-dynamic-plugins').then(m => m.command)),
);
Expand Down
42 changes: 40 additions & 2 deletions packages/cli/src/commands/package-dynamic-plugins/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ import { paths } from '../../lib/paths';
import { Task } from '../../lib/tasks';

export async function command(opts: OptionValues): Promise<void> {
const { exportTo, forceExport, preserveTempDir, tag, useDocker } = opts;
const {
exportTo,
forceExport,
preserveTempDir,
tag,
useDocker,
marketplaceFile,
} = opts;
if (!exportTo && !tag) {
Task.error(
`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`,
Expand All @@ -32,6 +39,19 @@ export async function command(opts: OptionValues): Promise<void> {
return;
}
}
const maketplaceInfo: Object[] = [];
if (marketplaceFile) {
if (!fs.existsSync(marketplaceFile)) {
Task.error(`Marketplace file ${marketplaceFile} does not exist`);
return;
}
const yamlDocuments = YAML.parseAllDocuments(
fs.readFileSync(marketplaceFile).toLocaleString(),
);
for (const document of yamlDocuments) {
maketplaceInfo.push(document.toJS());
}
}
const workspacePackage = (await fs.readJson(
paths.resolveTarget('package.json'),
)) as PackageJson;
Expand Down Expand Up @@ -183,6 +203,7 @@ export async function command(opts: OptionValues): Promise<void> {
);
}
}

// Write the plugin registry metadata
const metadataFile = path.join(tmpDir, 'index.json');
Task.log(`Writing plugin registry metadata to '${metadataFile}'`);
Expand All @@ -200,12 +221,29 @@ export async function command(opts: OptionValues): Promise<void> {
fs.copySync(source, destination, { recursive: true, overwrite: true });
});
} else {
// collect flags for the container build command
const flags = [
`--annotation io.backstage.dynamic-packages='${Buffer.from(JSON.stringify(pluginRegistryMetadata)).toString('base64')}'`,
];

for (const pluginInfo of maketplaceInfo) {
const base64pluginInfo = Buffer.from(
JSON.stringify(pluginInfo),
).toString('base64');
const pluginName = (pluginInfo as { metadata: { name: string } })
.metadata.name;
flags.push(
`--annotation io.backstage.marketplace/${pluginName}='${base64pluginInfo}'`,
);
}
// run the command to generate the image
Task.log(`Creating image using ${containerTool}`);
await Task.forCommand(
`echo "from scratch
COPY . .
" | ${containerTool} build --annotation com.redhat.rhdh.plugins='${JSON.stringify(pluginRegistryMetadata)}' -t '${tag}' -f - .
" | ${containerTool} build \
${flags.join(' ')} \
-t '${tag}' -f - .
`,
{ cwd: tmpDir },
);
Expand Down
Loading