Developer Hub

Stand up a Backstage developer portal on OpenShift and add a software template that scaffolds a new service into Git.

Updated CompTech Team

A new service should start from a template, not from the last repository someone cloned. Developer Hub is a Backstage portal on OpenShift: a catalog of the services you already run, and a scaffolder that creates the next one with a pipeline, a catalog entry and a GitOps overlay already wired.

This lab installs Red Hat Developer Hub, registers one component by hand, and adds a template that publishes a new service to GitLab. The portal does not replace GitOps. It creates the pull request that GitOps will sync.

Prerequisites

  • An OpenShift cluster with the Red Hat Developer Hub operator, which is Red Hat's build of Backstage
  • A GitLab group the scaffolder can create projects in, and a token for that group
  • The catalog content below, in a repository the portal can read

Create the operand from the operator's sample Backstage resource in the rhdh.redhat.com API group. Point it at an app-config ConfigMap. The route the operator creates is the URL developers open.

Register what you already have

catalog-info.yaml in the payments repository tells the catalog who owns the service and where the code lives.

apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
  name: payments
  description: Accepts and records payments.
  annotations:
    gitlab.com/project-slug: platform/payments
    backstage.io/techdocs-ref: dir:.
  tags: [java, payments]
spec:
  type: service
  lifecycle: production
  owner: payments-team
  system: retail

Load it from app-config.yaml:

app:
  title: Developer Hub
  baseUrl: https://developer-hub.apps.example.com
organization:
  name: Platform
catalog:
  locations:
    - type: url
      target: https://gitlab.apps.example.com/platform/payments/-/blob/main/catalog-info.yaml
      rules:
        - allow: [Component]
    - type: url
      target: https://gitlab.apps.example.com/platform/templates/-/blob/main/template.yaml
      rules:
        - allow: [Template]

Mount that file through the Backstage operand's app-config and restart the pod. The catalog page should list payments with its owner. An owner that does not match a Group in the catalog is a signal to fix the catalog, not to delete the field. The owner is how you find who to call.

A template for the next service

template.yaml is a Backstage Software Template. The scaffolder asks for a name and an owner, renders a skeleton, pushes a GitLab project and registers the new component.

apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
  name: quarkus-service
  title: Quarkus service
  description: A Quarkus service with a catalog entry and a GitOps overlay.
spec:
  owner: platform
  type: service
  parameters:
    - title: Service
      required: [name, owner]
      properties:
        name:
          title: Name
          type: string
          pattern: '^[a-z][a-z0-9-]{1,30}$'
        owner:
          title: Owner
          type: string
  steps:
    - id: fetch
      name: Render the skeleton
      action: fetch:template
      input:
        url: ./skeleton
        values:
          name: ${{ parameters.name }}
          owner: ${{ parameters.owner }}
    - id: publish
      name: Create the GitLab project
      action: publish:gitlab
      input:
        repoUrl: gitlab.apps.example.com?owner=platform&repo=${{ parameters.name }}
        defaultBranch: main
    - id: register
      name: Add it to the catalog
      action: catalog:register
      input:
        repoContentsUrl: ${{ steps.publish.output.repoContentsUrl }}
        catalogInfoPath: /catalog-info.yaml

The skeleton directory next to the template holds ${{ values.name }} markers the scaffolder fills in: a Dockerfile, a .gitlab-ci.yml from the GitLab CI lab, a catalog-info.yaml, and overlays/dev for GitOps. Store the GitLab token in a Kubernetes Secret and reference it from app-config.yaml under integrations.gitlab. Do not put the token in the template.

Run the template from Create... in the portal. You should get a new GitLab project, a pipeline on main, and a catalog entry whose owner is the group you typed.

What the portal is for

Job Where it lives
Find a service, its owner and its repository Catalog (Component, System, Group)
Create a service that already meets the platform bar Software Template
Docs beside the code TechDocs, from the repository
Actually deploy it OpenShift GitOps, not the portal

A template that developers bypass is a template that is missing something they need. Fix the skeleton. A one-off in someone's home directory will not be patched when the base image is.

What's next

  1. The skeleton's pipeline is GitLab CI, and its manifests are synced by OpenShift GitOps.
  2. The project and quota the template assumes are created in Infrastructure as code.
  3. Whether teams actually use the template shows up in lead time, in Measuring DevOps.