|
1 | | -# [Backstage](https://backstage.io) |
| 1 | +# DevHub Backstage Integration for BC Data Catalogue Plugins |
2 | 2 |
|
3 | | -This is your newly scaffolded Backstage App, Good Luck! |
| 3 | +This guide explains how to update the DevHub Backstage project to use the three BC Data Catalogue packages together: |
4 | 4 |
|
5 | | -To start the app, run: |
| 5 | +- `@bcgov/plugin-catalog-backend-module-bc-data-catalogue` |
| 6 | +- `@bcgov/plugin-catalog-common-bc-data-catalogue` |
| 7 | +- `@bcgov/catalog-dataset` |
| 8 | + |
| 9 | +These packages work together to provide: |
| 10 | + |
| 11 | +- backend ingestion of BC Data Catalogue content into the Backstage catalog |
| 12 | +- shared dataset types and utilities |
| 13 | +- a frontend dataset page for rendering `Dataset` entities |
| 14 | + |
| 15 | +--- |
| 16 | + |
| 17 | +## What Each Package Does |
| 18 | + |
| 19 | +### `@bcgov/plugin-catalog-backend-module-bc-data-catalogue` |
| 20 | + |
| 21 | +Provides the backend catalog module that connects to the BC Data Catalogue and creates catalog entities such as: |
| 22 | + |
| 23 | +- `Dataset` |
| 24 | +- `API` |
| 25 | +- `System` |
| 26 | +- `Group` |
| 27 | +- `User` |
| 28 | + |
| 29 | +### `@bcgov/plugin-catalog-common-bc-data-catalogue` |
| 30 | + |
| 31 | +Provides shared types, helpers, and utilities used by the backend and frontend integration. |
| 32 | + |
| 33 | +### `@bcgov/catalog-dataset` |
| 34 | + |
| 35 | +Provides the frontend dataset page and related UI components for rendering `Dataset` entities in DevHub. |
| 36 | + |
| 37 | +--- |
| 38 | + |
| 39 | +## Prerequisites |
| 40 | + |
| 41 | +These packages are published to GitHub Packages and require authentication to install, even if the packages are public. |
| 42 | + |
| 43 | +### 1. Create a GitHub Personal Access Token |
| 44 | + |
| 45 | +1. Go to GitHub Settings → Developer settings → Personal access tokens → Tokens (classic) |
| 46 | +2. Click **Generate new token (classic)** |
| 47 | +3. Give it a descriptive name such as `Backstage Package Access` |
| 48 | +4. Select the `read:packages` scope |
| 49 | +5. Set a lifespan (90 days or less recommended) |
| 50 | +6. Authorize the token for SSO with the `bcgov` organization |
| 51 | +7. Copy the token |
| 52 | + |
| 53 | +### 2. Export the Token |
| 54 | + |
| 55 | +```bash |
| 56 | +export GITHUB_TOKEN=your_token_here |
| 57 | +``` |
| 58 | + |
| 59 | +--- |
| 60 | + |
| 61 | +## Configure Package Registry Access |
| 62 | + |
| 63 | +### `.npmrc` |
6 | 64 |
|
7 | | -```sh |
8 | | -yarn install |
9 | | -yarn start |
10 | 65 | ``` |
| 66 | +@bcgov:registry=https://npm.pkg.github.com |
| 67 | +//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN} |
| 68 | +``` |
| 69 | + |
| 70 | +### `.yarnrc.yaml` (if required) |
| 71 | + |
| 72 | +```yaml |
| 73 | +npmScopes: |
| 74 | + bcgov: |
| 75 | + npmRegistryServer: "https://npm.pkg.github.com" |
| 76 | + |
| 77 | +npmRegistries: |
| 78 | + "https://npm.pkg.github.com": |
| 79 | + npmAuthToken: "${GITHUB_TOKEN}" |
| 80 | +``` |
| 81 | +
|
| 82 | +--- |
| 83 | +
|
| 84 | +## Install the Packages |
| 85 | +
|
| 86 | +```bash |
| 87 | +yarn add @bcgov/plugin-catalog-backend-module-bc-data-catalogue |
| 88 | +yarn add @bcgov/plugin-catalog-common-bc-data-catalogue |
| 89 | +yarn add @bcgov/catalog-dataset |
| 90 | +``` |
| 91 | + |
| 92 | +--- |
| 93 | + |
| 94 | +## Backend Changes |
| 95 | + |
| 96 | +### 1. Register the Backend Module |
| 97 | + |
| 98 | +Update: |
| 99 | + |
| 100 | +`packages/backend/src/index.ts` |
| 101 | + |
| 102 | +```diff |
| 103 | +import { createBackend } from '@backstage/backend-defaults'; |
| 104 | + |
| 105 | +const backend = createBackend(); |
| 106 | + |
| 107 | +// ... other backend.add() calls ... |
| 108 | + |
| 109 | ++ backend.add(import('@bcgov/plugin-catalog-backend-module-bc-data-catalogue')); |
| 110 | + |
| 111 | +backend.start(); |
| 112 | +``` |
| 113 | + |
| 114 | +--- |
| 115 | + |
| 116 | +### 2. Allow BC Data Catalogue API Access |
| 117 | + |
| 118 | +Update `app-config.yaml`: |
| 119 | + |
| 120 | +```yaml |
| 121 | +backend: |
| 122 | + reading: |
| 123 | + allow: |
| 124 | + - host: catalogue.data.gov.bc.ca |
| 125 | + scheme: https |
| 126 | +``` |
| 127 | +
|
| 128 | +--- |
| 129 | +
|
| 130 | +### 3. Configure Provider Schedule |
| 131 | +
|
| 132 | +```yaml |
| 133 | +catalog: |
| 134 | + providers: |
| 135 | + bc-data-catalogue: |
| 136 | + env: dev |
| 137 | + schedule: |
| 138 | + frequency: 10m |
| 139 | +``` |
| 140 | +
|
| 141 | +--- |
| 142 | +
|
| 143 | +## Frontend Changes |
| 144 | +
|
| 145 | +The dataset plugin requires **two changes** in the DevHub frontend. |
| 146 | +
|
| 147 | +--- |
| 148 | +
|
| 149 | +### 1. Add Dataset Route |
| 150 | +
|
| 151 | +Update: |
| 152 | +
|
| 153 | +`packages/app/src/App.tsx` |
| 154 | + |
| 155 | +```diff |
| 156 | ++ import { CatalogDatasetPage } from '@bcgov/catalog-dataset'; |
| 157 | +
|
| 158 | +const routes = ( |
| 159 | + <FlatRoutes> |
| 160 | + ... |
| 161 | ++ <Route path="/catalog-dataset" element={<CatalogDatasetPage />} /> |
| 162 | + </FlatRoutes> |
| 163 | +); |
| 164 | +``` |
| 165 | + |
| 166 | +--- |
| 167 | + |
| 168 | +### 2. Register Dataset Page in Entity Switch |
| 169 | + |
| 170 | +Update: |
| 171 | + |
| 172 | +`packages/app/src/components/catalog/EntityPage.tsx` |
| 173 | + |
| 174 | +```diff |
| 175 | ++ import { CatalogDatasetPage } from '@bcgov/catalog-dataset'; |
| 176 | +
|
| 177 | +<EntitySwitch> |
| 178 | + <EntitySwitch.Case if={isKind('user')} children={userPage} /> |
| 179 | + <EntitySwitch.Case if={isKind('system')} children={systemPage} /> |
| 180 | + <EntitySwitch.Case if={isKind('domain')} children={domainPage} /> |
| 181 | +
|
| 182 | ++ <EntitySwitch.Case if={isKind('dataset')} children={<CatalogDatasetPage />} /> |
| 183 | +
|
| 184 | + <EntitySwitch.Case>{defaultEntityPage}</EntitySwitch.Case> |
| 185 | +</EntitySwitch> |
| 186 | +``` |
| 187 | + |
| 188 | +--- |
| 189 | + |
| 190 | +## Expected Result |
| 191 | + |
| 192 | +After completing all steps: |
| 193 | + |
| 194 | +- BC Data Catalogue datasets are ingested into Backstage |
| 195 | +- `Dataset` entities appear in the catalog |
| 196 | +- Selecting a dataset opens the custom dataset page |
| 197 | +- Dataset-specific UI (schema, lineage, support, etc.) is rendered |
| 198 | + |
| 199 | +--- |
| 200 | + |
| 201 | +## Summary |
| 202 | + |
| 203 | +### Install |
| 204 | + |
| 205 | +- `@bcgov/plugin-catalog-backend-module-bc-data-catalogue` |
| 206 | +- `@bcgov/plugin-catalog-common-bc-data-catalogue` |
| 207 | +- `@bcgov/catalog-dataset` |
| 208 | + |
| 209 | +### Backend |
| 210 | + |
| 211 | +- Register backend module |
| 212 | +- Allow API host |
| 213 | +- Configure provider schedule |
| 214 | + |
| 215 | +### Frontend |
| 216 | + |
| 217 | +- Add route in `App.tsx` |
| 218 | +- Add EntitySwitch case in `EntityPage.tsx` |
| 219 | + |
| 220 | +--- |
| 221 | + |
| 222 | +## Notes |
| 223 | + |
| 224 | +- Keep `GITHUB_TOKEN` out of source control |
| 225 | +- Additional hosts may need to be added to `backend.reading.allow` |
| 226 | +- The dataset plugin relies on all three packages working together |
0 commit comments