unity-builder icon indicating copy to clipboard operation
unity-builder copied to clipboard

CLI: Plugins

Open webbertakken opened this issue 2 years ago • 0 comments

Context Introduce a simple plugins system in the CLI that can be extended.

Plugins themselves are centrally maintained (as part of the CLI itself?).

Rationale

Currently if someone wants SonarQube to run, they have to spend several hours or days to implement it properly.

Each team is doing this separately, which is bascially a waste of everyones time and in practice it means that new developers will not have cool tools like this integrated.

Using centrally maintained plugins allows the community to together come up with the best approaches for each plugin.

Technical details

The interface of an action could look something like this:

- uses: unity-builder
  with:
    plugins:
      sonar: { my, config, params } # specific to sonar

A plugin definition, maintained by the community could look something like this

class BlenderAddOn {
  static get name() {
    return 'blender';
  }

  static get version() {
    return '1'
  }

  static get dockerCacheKey() {
    return `${BlenderAddOn.name}.${BlenderAddOn.version}`
  }

  static getAptGetPackages() {
    'my-package my-other-package'
  }

  static getRawDockerInstructions() {
    return `
      RUN echo 'test'
      RUN echo 'another layer'
    `
  }

  static runBefore() {
    if (someOS) {
      // install blender on VM instead of in docker
    }
  }

  static runAfter() {
    // cleanup
  }
}

It's not just an extension of the Dockerfile, but also other logic: a plugin is something that goes into a registry. And each part of the logic asks the registry if there is a piece to be injected in the logic that it is responsible for.

For example:

  • Docker build (docker.ts) will use getAptGetPackages and inject it into docker as an argument. It'll do this for all active plugins.
  • After it detects that your repository is dirty or not for example, some code, probably in pre-flight.ts or something, would call runBefore

webbertakken avatar May 22 '22 12:05 webbertakken