|
1 | | -# flagsmith |
| 1 | +# Flagsmith Plugin for Backstage |
2 | 2 |
|
3 | | -Welcome to the Flagsmith plugin! |
| 3 | +Integrate [Flagsmith](https://flagsmith.com) feature flags into your Backstage instance. |
4 | 4 |
|
5 | | -This plugins: |
| 5 | +## Features |
6 | 6 |
|
7 | | -- Adds a 'Feature Flags' tab on component pages. |
8 | | -- Provides 2 Cards that can be added to component Overview pages. |
| 7 | +- **Feature Flags Tab** - View all feature flags for a service directly in the entity page |
| 8 | +- **Overview Card** - Quick summary of flags and their states |
| 9 | +- **Usage Card** - Display Flagsmith usage metrics |
9 | 10 |
|
10 | | -## Getting started |
| 11 | +## Installation |
11 | 12 |
|
12 | | -Currently, it is only meant for local development, and the setup for it can be found inside the [/dev](./dev) directory. |
| 13 | +### 1. Install the plugin |
13 | 14 |
|
14 | | -Add the following annotations to a component to link it to a flagsmith project, replacing with your Project and Organization IDs: |
| 15 | +```bash |
| 16 | +# From your Backstage root directory |
| 17 | +yarn --cwd packages/app add @flagsmith/backstage-plugin |
| 18 | +``` |
| 19 | + |
| 20 | +### 2. Configure the Backstage proxy |
| 21 | + |
| 22 | +Add to your `app-config.yaml` (or `app-config.local.yaml` for local development): |
| 23 | + |
| 24 | +```yaml |
| 25 | +proxy: |
| 26 | + endpoints: |
| 27 | + '/flagsmith': |
| 28 | + target: 'https://api.flagsmith.com/api/v1' |
| 29 | + headers: |
| 30 | + Authorization: Api-Key ${FLAGSMITH_API_TOKEN} |
| 31 | +``` |
15 | 32 |
|
| 33 | +> **Note:** Use an environment variable for the API token in production. Never commit tokens to version control. |
| 34 | +
|
| 35 | +For self-hosted Flagsmith, change the target URL: |
| 36 | +
|
| 37 | +```yaml |
| 38 | +proxy: |
| 39 | + endpoints: |
| 40 | + '/flagsmith': |
| 41 | + target: 'https://your-flagsmith-instance.com/api/v1' |
| 42 | + headers: |
| 43 | + Authorization: Api-Key ${FLAGSMITH_API_TOKEN} |
16 | 44 | ``` |
17 | | -annotations: |
18 | | - flagsmith.com/project-id: "00000" |
19 | | - flagsmith.com/org-id: "00000" # Optional, defaults to first org |
| 45 | +
|
| 46 | +### 3. Add the Feature Flags tab to entity pages |
| 47 | +
|
| 48 | +In `packages/app/src/components/catalog/EntityPage.tsx`: |
| 49 | + |
| 50 | +```typescript |
| 51 | +import { FlagsTab } from '@flagsmith/backstage-plugin'; |
| 52 | +
|
| 53 | +// Add to your entity page layout (e.g., serviceEntityPage) |
| 54 | +<EntityLayout.Route path="/feature-flags" title="Feature Flags"> |
| 55 | + <FlagsTab /> |
| 56 | +</EntityLayout.Route> |
| 57 | +``` |
| 58 | + |
| 59 | +### 4. (Optional) Add cards to the Overview page |
| 60 | + |
| 61 | +```typescript |
| 62 | +import { |
| 63 | + FlagsmithOverviewCard, |
| 64 | + FlagsmithUsageCard, |
| 65 | +} from '@flagsmith/backstage-plugin'; |
| 66 | +
|
| 67 | +// Add to your entity overview page |
| 68 | +<Grid item md={6}> |
| 69 | + <FlagsmithOverviewCard /> |
| 70 | +</Grid> |
| 71 | +<Grid item md={6}> |
| 72 | + <FlagsmithUsageCard /> |
| 73 | +</Grid> |
| 74 | +``` |
| 75 | + |
| 76 | +### 5. Annotate your entities |
| 77 | + |
| 78 | +Add Flagsmith annotations to your `catalog-info.yaml`: |
| 79 | + |
| 80 | +```yaml |
| 81 | +apiVersion: backstage.io/v1alpha1 |
| 82 | +kind: Component |
| 83 | +metadata: |
| 84 | + name: my-service |
| 85 | + annotations: |
| 86 | + flagsmith.com/project-id: '12345' |
| 87 | + flagsmith.com/org-id: '67890' # Optional - defaults to first organization |
| 88 | +spec: |
| 89 | + type: service |
| 90 | + owner: team-a |
20 | 91 | ``` |
21 | 92 |
|
22 | | -Configure your credentials by adding the following to app-config.yaml (or your local override app-config.local.yaml): |
| 93 | +## Getting your Flagsmith credentials |
| 94 | + |
| 95 | +1. Log in to your [Flagsmith dashboard](https://app.flagsmith.com) |
| 96 | +2. Go to **Organisation Settings** > **API Keys** |
| 97 | +3. Create or copy your **Admin API Key** |
| 98 | +4. Find your **Project ID** and **Organisation ID** in the URL or project settings |
| 99 | + |
| 100 | +## Development |
| 101 | + |
| 102 | +### Prerequisites |
| 103 | + |
| 104 | +- Node.js 22+ (Node 24 has known ESM compatibility issues with Backstage) |
| 105 | +- Yarn |
| 106 | +- A Backstage application for testing |
| 107 | + |
| 108 | +### Local Development Setup |
| 109 | + |
| 110 | +1. Clone the repository: |
| 111 | + |
| 112 | + ```bash |
| 113 | + git clone https://github.com/Flagsmith/flagsmith-backstage-plugin.git |
| 114 | + cd flagsmith-backstage-plugin |
| 115 | + ``` |
| 116 | + |
| 117 | +2. Install dependencies: |
| 118 | + |
| 119 | + ```bash |
| 120 | + yarn install |
| 121 | + ``` |
| 122 | + |
| 123 | +3. To test in a Backstage app, copy or link the plugin to your Backstage workspace's `plugins/` directory and add it as a workspace dependency. |
| 124 | + |
| 125 | +4. Create `app-config.local.yaml` with your Flagsmith credentials (this file is gitignored). |
| 126 | + |
| 127 | +5. Run the Backstage app: |
| 128 | + ```bash |
| 129 | + yarn start |
| 130 | + ``` |
| 131 | + |
| 132 | +### Available Scripts |
| 133 | + |
| 134 | +| Command | Description | |
| 135 | +| ------------ | ---------------------------- | |
| 136 | +| `yarn start` | Start the development server | |
| 137 | +| `yarn build` | Build for production | |
| 138 | +| `yarn test` | Run tests | |
| 139 | +| `yarn lint` | Lint the codebase | |
| 140 | + |
| 141 | +### Project Structure |
23 | 142 |
|
24 | 143 | ``` |
25 | | -# Backstage override configuration for your local development environment |
26 | | -flagsmith: |
27 | | - apiUrl: https://api.flagsmith.com |
28 | | - apiToken: yourApiToken |
| 144 | +src/ |
| 145 | +├── components/ # React components |
| 146 | +│ ├── FlagsTab.tsx |
| 147 | +│ ├── FlagsmithOverviewCard.tsx |
| 148 | +│ └── FlagsmithUsageCard.tsx |
| 149 | +├── api/ # API client (uses Backstage proxy) |
| 150 | +│ └── FlagsmithClient.ts |
| 151 | +├── plugin.ts # Frontend plugin definition |
| 152 | +└── index.ts # Package exports |
29 | 153 | ``` |
| 154 | +
|
| 155 | +## Contributing |
| 156 | +
|
| 157 | +Contributions are welcome! Please open an issue or submit a pull request. |
| 158 | +
|
| 159 | +## License |
| 160 | +
|
| 161 | +Apache-2.0 |
0 commit comments