RoadieHQ / roadie-backstage-plugins

All Backstage plugins created by Roadie.
https://roadie.io
Apache License 2.0
251 stars 371 forks source link

Migrate plugins to new Backstage Backend system #1325

Open punkle opened 3 months ago

punkle commented 3 months ago

The new backstage backend system is ready to be used at this point. The old backend system will be deprecated and is scheduled to be removed at the end of this year. As such this repo needs its backend plugins migrated to use the new Backstage Backend system.

If you would like to take ownership of migrating a plugin in this repo please, write a comment on this issue expressing your interest in helping out. Then create a pull request referencing this issue.

Here is an example of the pull request for the rag-ai-backend plugin https://github.com/RoadieHQ/roadie-backstage-plugins/pull/1319

punkle commented 3 months ago

@drodil here is the issue we discussed.

david-heidema commented 3 months ago

I have interest on updating scoffolder-backend-module-http-request and scaffolder-backend-module-utils. I will share the PR once the work is complete.

clementblaise commented 2 months ago

Opened #1341

david-heidema commented 2 months ago

1348, #1349 , and #1361 complete the migration of scoffolder-backend-module-http-request and scaffolder-backend-module-utils.

supersol commented 1 month ago

@kissmikijr @vanessap-aa could you advice if there is a way to use argocd backend plugin with the new backstage backend system? or do you have any migration plans? I attempted to manage it to work but without any success and at the same time I have a very little js/ts coding experience :)

clementblaise commented 1 month ago

Is it possible to re-open #1341 and get a review?

kissmikijr commented 1 month ago

@kissmikijr @vanessap-aa could you advice if there is a way to use argocd backend plugin with the new backstage backend system? or do you have any migration plans? I attempted to manage it to work but without any success and at the same time I have a very little js/ts coding experience :)

I think you should be able to use the legacyPlugin and register not migrated plugins yet to your backstage if you already use the new backend-system. I did not test it yet but something like this:

import { legacyPlugin } from '@backstage/backend-common';

backend.add(legacyPlugin('argoCd', import('./plugins/argocd')));
supersol commented 1 month ago

@kissmikijr @vanessap-aa could you advice if there is a way to use argocd backend plugin with the new backstage backend system? or do you have any migration plans? I attempted to manage it to work but without any success and at the same time I have a very little js/ts coding experience :)

I think you should be able to use the legacyPlugin and register not migrated plugins yet to your backstage if you already use the new backend-system. I did not test it yet but something like this:

import { legacyPlugin } from '@backstage/backend-common';

backend.add(legacyPlugin('argoCd', import('./plugins/argocd')));

@kissmikijr First of all thanks for the reply.

I tried that way, unfortunately it doesn't work. In the beginning when it failed there was PluginEnvironment entity dependency from types.ts file, so I tried to bring back that file,

  import { createRouter } from '@roadiehq/backstage-plugin-argo-cd-backend';
  import { PluginEnvironment } from '../types';

  export default async function createPlugin({
    logger,
    config,
  }: PluginEnvironment) {
    return await createRouter({ logger, config });
  }

it didn't work, then I tried to remove that entity completely, so it doesn't depend on PluginEnvironment and just import the plugin, it still didn't work

tried like this: backend.add(legacyPlugin('argocd', import('@roadiehq/backstage-plugin-argo-cd-backend')));

it gave me some incompatibilities at the compile time.

#8 18.22 packages/backend/src/index.ts:60:36 - error TS2345: Argument of type 'Promise<{ default: typeof import("/backstage/node_modules/@roadiehq/backstage-plugin-argo-cd-backend/dist/index"); ArgoService: typeof ArgoService; createRouter: ({ logger, config, }: RouterOptions) => Promise<...>; }>' is not assignable to parameter of type 'Promise<{ default: LegacyCreateRouter<TransformedEnv<{ cache: CacheService; config: RootConfigService; database: DatabaseService; discovery: DiscoveryService; ... 5 more ...; identity: IdentityService; }, { ...; }>>; }>'.
#8 18.22   Type '{ default: typeof import("/backstage/node_modules/@roadiehq/backstage-plugin-argo-cd-backend/dist/index"); ArgoService: typeof ArgoService; createRouter: ({ logger, config, }: RouterOptions) => Promise<...>; }' is not assignable to type '{ default: LegacyCreateRouter<TransformedEnv<{ cache: CacheService; config: RootConfigService; database: DatabaseService; discovery: DiscoveryService; ... 5 more ...; identity: IdentityService; }, { ...; }>>; }'.
#8 18.22     Types of property 'default' are incompatible.
#8 18.22       Type 'typeof import("/backstage/node_modules/@roadiehq/backstage-plugin-argo-cd-backend/dist/index")' is not assignable to type 'LegacyCreateRouter<TransformedEnv<{ cache: CacheService; config: RootConfigService; database: DatabaseService; discovery: DiscoveryService; ... 5 more ...; identity: IdentityService; }, { ...; }>>'.
#8 18.22         Type 'typeof import("/backstage/node_modules/@roadiehq/backstage-plugin-argo-cd-backend/dist/index")' provides no match for the signature '(deps: TransformedEnv<{ cache: CacheService; config: RootConfigService; database: DatabaseService; discovery: DiscoveryService; ... 5 more ...; identity: IdentityService; }, { ...; }>): Promise<...>'.
#8 18.22 
martina-equinix commented 4 weeks ago

Hey @supersol

I got the backend plugin working with this:

// backend/src/plugins/argocd.ts

import { createRouter } from '@roadiehq/backstage-plugin-argo-cd-backend';
import { PluginEnvironment } from '../types';
import {Router} from "express";

export default async function createPlugin(
  env: PluginEnvironment,
): Promise<Router> {
  return await createRouter({
    logger: env.logger,
    config: env.config,
  });
}
// backend/src/index.ts

+import {legacyPlugin} from '@backstage/backend-common';
...
+backend.add(legacyPlugin('argocd', import('./plugins/argocd')));
kissmikijr commented 4 weeks ago

If you have a custom environment for your plugins you will need to use the following way to provide the custom environment to your plugins

An example custom env config.

// backend/src/index.ts

import { coreServices } from '@backstage/backend-plugin-api';
import {
  makeLegacyPlugin,
  loggerToWinstonLogger,
  cacheToPluginCacheManager,
} from '@backstage/backend-common';
...
const legacyPlugin = makeLegacyPlugin(
  {
    logger: coreServices.logger,
    cache: coreServices.cache,
    database: coreServices.database,
    auth: coreServices.auth,
    config: coreServices.config,
    reader: coreServices.urlReader,
    discovery: coreServices.discovery,
    tokenManager: coreServices.tokenManager,
    permissions: coreServices.permissions,
    scheduler: coreServices.scheduler,
    // ... and your own additions

  },
  {
    logger: log => loggerToWinstonLogger(log),
    cache: cache => cacheToPluginCacheManager(cache),
  },
);

...
backend.add(legacyPlugin('argocd', import('./plugins/argocd')));
clementblaise commented 1 week ago

Hello @kissmikijr is it possible to get a review on #1341 ?