roadie-backstage-plugins icon indicating copy to clipboard operation
roadie-backstage-plugins copied to clipboard

Migrate plugins to new Backstage Backend system

Open punkle opened this issue 10 months ago • 18 comments

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 avatar Apr 05 '24 10:04 punkle

@drodil here is the issue we discussed.

punkle avatar Apr 05 '24 10:04 punkle

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.

david-heidema avatar Apr 05 '24 21:04 david-heidema

Opened #1341

clementblaise avatar Apr 23 '24 09:04 clementblaise

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

david-heidema avatar Apr 26 '24 16:04 david-heidema

@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 :)

supersol avatar May 28 '24 11:05 supersol

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

clementblaise avatar May 30 '24 08:05 clementblaise

@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 avatar May 30 '24 10:05 kissmikijr

@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 

supersol avatar Jun 03 '24 15:06 supersol

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')));

martina-equinix avatar Jun 06 '24 09:06 martina-equinix

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')));

kissmikijr avatar Jun 06 '24 14:06 kissmikijr

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

clementblaise avatar Jun 26 '24 08:06 clementblaise

thanks @kissmikijr @martina-equinix for your replies.

After some time I managed to make it work with the new backend, in case it will help to someone, I'll leave it here. I made some tricks which mime the behavior for the new backend, it also looks like a part of migration actually. I added 2 files to the plugins folder,

  1. argocd_index.ts (name could be any)
export { argocdPlugin as default } from './argocd';
  1. argocd.ts (name should match export) Basically I wrapped a router with the new function for the plugins
import { createRouter } from '@roadiehq/backstage-plugin-argo-cd-backend';
import { loggerToWinstonLogger } from '@backstage/backend-common';
import {
  coreServices,
  createBackendPlugin,
} from '@backstage/backend-plugin-api';

export const argocdPlugin = createBackendPlugin({
  pluginId: 'argocd',
  register(env) {
    env.registerInit({
      deps: {
        logger: coreServices.logger,
        config: coreServices.rootConfig,
        reader: coreServices.urlReader,
        discovery: coreServices.discovery,
        auth: coreServices.auth,
        tokenManager: coreServices.tokenManager,
        httpRouter: coreServices.httpRouter,
      },
      async init({
        logger,
        config,
        httpRouter,
      }) {
        httpRouter.use(
          await createRouter({
            logger: loggerToWinstonLogger(logger),
            config,
          }),
        );
      },
    });
  },
});

3 . index.ts - added this "custom plugin" ( add parameters should match then name from 1. step)

...
backend.add(import('./plugins/argocd_index'));
...

Then the build didn't fail and the argocd cards in the UI were showing apps state and some history.

supersol avatar Jul 09 '24 10:07 supersol

Hello,

We're working on a port of the RAG-AI to backend system of Backstage v1.30.x which includes a lot of deprecated API removals. We backend modules to remove the dependency on CreateLegacyPlugin.

If you're interresed we can make PR once we update the doc ?

link to the repo: https://github.com/alithya-oss/backstage-plugins/tree/main/workspaces/rag-ai/plugins

fjudith avatar Aug 27 '24 14:08 fjudith

Thanks @fjudith, a pull request would be very welcome for that yeah.

Xantier avatar Aug 28 '24 07:08 Xantier