0.1.0 • Published 8 months ago

@armyknife/backstage-gitlab-template v0.1.0

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
8 months ago

Backstage GitLab Template

This package provides GitLab repository template creation for Backstage.

Installation

# npm
npm install @armyknife/backstage-gitlab-template

# yarn
yarn add @armyknife/backstage-gitlab-template

Usage

In your packages/backend/src/plugins/scaffolder.ts file:

import { createRouter } from '@backstage/plugin-scaffolder-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';
import { createGitLabRepoAction } from '@armyknife/backstage-gitlab-template';

export default async function createPlugin(
  env: PluginEnvironment,
): Promise<Router> {
  const catalogClient = new CatalogClient({
    discoveryApi: env.discovery,
  });

  const actions = [
    createGitLabRepoAction({
      integrations: ScmIntegrations.fromConfig(env.config),
      config: env.config,
      catalogClient,
      reader: env.reader,
    }),
    // ... other actions
  ];

  return await createRouter({
    actions,
    logger: env.logger,
    config: env.config,
    database: env.database,
    reader: env.reader,
    catalogClient,
    identity: env.identity,
  });
}

Template Configuration

Create a template with GitLab repository creation:

apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
  name: gitlab-repo-template
  title: GitLab Repository
  description: Create a new GitLab repository
spec:
  owner: user:guest
  type: service

  parameters:
    - title: Repository Information
      required:
        - name
        - owner
        - description
      properties:
        name:
          title: Repository Name
          type: string
          description: Name of the repository
        owner:
          title: Repository Owner
          type: string
          description: Owner of the repository (group or user)
        description:
          title: Description
          type: string
          description: Description of the repository
        visibility:
          title: Repository Visibility
          type: string
          enum: ['public', 'private', 'internal']
          default: private
          description: Visibility of the repository
        enableSecurityFeatures:
          title: Enable Security Features
          type: boolean
          default: true
          description: Enable security features like branch protection, CODEOWNERS, etc.

  steps:
    - id: createGitLabRepo
      name: Create GitLab Repository
      action: armyknife:gitlab:create-repo
      input:
        name: ${{ parameters.name }}
        owner: ${{ parameters.owner }}
        description: ${{ parameters.description }}
        visibility: ${{ parameters.visibility }}
        enableSecurityFeatures: ${{ parameters.enableSecurityFeatures }}

    - id: registerCatalog
      name: Register in Catalog
      action: catalog:register
      input:
        repoContentsUrl: ${{ steps.createGitLabRepo.output.repoContentsUrl }}
        catalogInfoPath: '/catalog-info.yaml'

Environment Variables

You'll need to set the following environment variables:

GITLAB_TOKEN=your-gitlab-personal-access-token

License

Apache-2.0