Skip to content

chore(coder plugin): make template names optional #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
17fd4d3
wip: update type definitions and parsing logic for config values
Parkreiner Apr 1, 2024
a95a44b
refactor: update some code for clarity
Parkreiner Apr 1, 2024
18e80f0
fix: update property names in top-level config
Parkreiner Apr 1, 2024
3cfc7c5
wip: commit progress on link update
Parkreiner Apr 1, 2024
ec1e794
chore: finish updates for CreateWorkspaceLink
Parkreiner Apr 1, 2024
50ad128
chore: add new test case for disabled state
Parkreiner Apr 1, 2024
bbcdaf7
fix: cleanup markup and text for EntityDataReminder
Parkreiner Apr 1, 2024
730e979
chore: add readEntityData as context value
Parkreiner Apr 1, 2024
cd804f6
refactor: rename DataEntityReminder to ReminderAcoordionItem
Parkreiner Apr 1, 2024
9e541c2
chore: extract core accordion item logic to parent
Parkreiner Apr 1, 2024
f445df4
chore: finish initial version of ReminderAccordion
Parkreiner Apr 1, 2024
f841d1a
wip: commit test stubs for ReminderAccordion
Parkreiner Apr 1, 2024
98a94c8
chore: rename isReadingEntityData prop
Parkreiner Apr 1, 2024
d2ac1ac
chore: update mock context values in tests
Parkreiner Apr 1, 2024
b415ce5
wip: commit test stub for hiding cta button when there is no repo URL
Parkreiner Apr 1, 2024
604c7a4
chore: hide CTA button when there is no repo URL
Parkreiner Apr 1, 2024
8635663
chore: rename AccordionItem to Disclosure
Parkreiner Apr 2, 2024
233d255
chore: update tests for Disclosure
Parkreiner Apr 2, 2024
badd8ee
chore: remove needless hasAssertions calls
Parkreiner Apr 2, 2024
e87e41e
fix: update conditional logic for ReminderAccordion
Parkreiner Apr 2, 2024
52a2731
fix: more accordion bug fixes
Parkreiner Apr 2, 2024
c45e132
chore: finish another test case
Parkreiner Apr 2, 2024
0680934
chore: add another accordion test case
Parkreiner Apr 2, 2024
7ba9fce
refactor: rename props for clarity
Parkreiner Apr 2, 2024
14c4d86
refactor: simplify condition for entity reminder
Parkreiner Apr 2, 2024
8f5081e
refactor: update prop for Disclosure
Parkreiner Apr 2, 2024
11b7b81
chore: finish all tests for accordion
Parkreiner Apr 2, 2024
cb2664e
refactor: update type definition for mock config
Parkreiner Apr 2, 2024
41d6f20
refactor: polish up accordion tests
Parkreiner Apr 2, 2024
b3b83f0
chore: finish up all tests
Parkreiner Apr 2, 2024
b6c8dec
fix: add missing property to mock setup to help compiler pass
Parkreiner Apr 2, 2024
ff531b8
refactor: move isReadingEntityData property to workspaces config
Parkreiner Apr 2, 2024
352352f
fix: add overflow-y and max height behavior to accordion
Parkreiner Apr 2, 2024
53ba23e
chore: polish styling for accordion
Parkreiner Apr 2, 2024
90d6f9d
fix: add reminder accordion as exported plugin component
Parkreiner Apr 2, 2024
9e07fd5
refactor: rename imported component to reduce visual noise when reading
Parkreiner Apr 4, 2024
4389f84
fix: make no-link message more clear for button
Parkreiner Apr 4, 2024
f8a4576
fix: update text to account for new tooltip
Parkreiner Apr 4, 2024
5677de6
docs: add page about catalog-info
Parkreiner Apr 4, 2024
b591977
docs: finish all docs updates for coder plugin
Parkreiner Apr 4, 2024
cab06c4
docs: add docs section for ReminderAccordion
Parkreiner Apr 4, 2024
a640738
fix: update link for documentation in UI
Parkreiner Apr 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/app/src/components/catalog/EntityPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ const coderAppConfig: CoderAppConfig = {
},

workspaces: {
templateName: 'devcontainers',
mode: 'manual',
defaultTemplateName: 'devcontainers',
defaultMode: 'manual',
repoUrlParamKeys: ['custom_repo', 'repo_url'],
params: {
repo: 'custom',
Expand Down
52 changes: 41 additions & 11 deletions plugins/backstage-plugin-coder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,23 @@ the Dev Container.
yarn --cwd packages/app add @coder/backstage-plugin-coder
```

1. Add the proxy key to your `app-config.yaml`:
2. Add the proxy key to your `app-config.yaml`:

```yaml
proxy:
endpoints:
'/coder':
# Replace with your Coder deployment access URL and a trailing /
# Replace with your Coder deployment access URL (add a trailing slash)
target: 'https://coder.example.com/'

changeOrigin: true
allowedMethods: ['GET']
allowedMethods: ['GET'] # Additional methods will be supported soon!
allowedHeaders: ['Authorization', 'Coder-Session-Token']
headers:
X-Custom-Source: backstage
```

1. Add the `CoderProvider` to the application:
3. Add the `CoderProvider` to the application:

```tsx
// In packages/app/src/App.tsx
Expand All @@ -58,14 +59,16 @@ the Dev Container.
},

// Set the default template (and parameters) for
// catalog items. This can be overridden in the
// catalog-info.yaml for specific items.
// catalog items. Individual properties can be overridden
// by a repo's catalog-info.yaml file
workspaces: {
templateName: 'devcontainers',
mode: 'manual',
// This parameter is used to filter Coder workspaces
// by a repo URL parameter.
defaultTemplateName: 'devcontainers',
defaultMode: 'manual',

// This property defines which parameters in your Coder
// workspace templates are used to store repository links
repoUrlParamKeys: ['custom_repo', 'repo_url'],

params: {
repo: 'custom',
region: 'eu-helsinki',
Expand All @@ -88,7 +91,7 @@ the Dev Container.

**Note:** You can also wrap a single page or component with `CoderProvider` if you only need Coder in a specific part of your app. See our [API reference](./docs/README.md) (particularly the section on [the `CoderProvider` component](./docs/components.md#coderprovider)) for more details.

1. Add the `CoderWorkspacesCard` card to the entity page in your app:
4. Add the `CoderWorkspacesCard` card to the entity page in your app:

```tsx
// In packages/app/src/components/catalog/EntityPage.tsx
Expand All @@ -101,6 +104,33 @@ the Dev Container.
</Grid>;
```

### `app-config.yaml` files

In addition to the above, you can define additional properties on your specific repo's `catalog-info.yaml` file.

Example:

```yaml
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: python-project
spec:
type: other
lifecycle: unknown
owner: pms

# Properties for the Coder plugin are placed here
coder:
templateName: 'devcontainers'
mode: 'auto'
params:
repo: 'custom'
region: 'us-pittsburgh'
```

You can find more information about what properties are available (and how they're applied) in our [`catalog-info.yaml` file documentation](./docs/catalog-info.md).

## Roadmap

This plugin is in active development. The following features are planned:
Expand Down
4 changes: 2 additions & 2 deletions plugins/backstage-plugin-coder/dev/DevPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const appConfig: CoderAppConfig = {
},

workspaces: {
templateName: 'devcontainers',
mode: 'manual',
defaultTemplateName: 'devcontainers',
defaultMode: 'manual',
repoUrlParamKeys: ['custom_repo', 'repo_url'],
params: {
repo: 'custom',
Expand Down
59 changes: 59 additions & 0 deletions plugins/backstage-plugin-coder/docs/catalog-info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# `catalog-info.yaml` files

This file provides documentation for all properties that the Coder plugin recognizes from Backstage's [`catalog-info.yaml` files](https://backstage.io/docs/features/software-catalog/descriptor-format/).

## Example file

```yaml
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: python-project
spec:
type: other
lifecycle: unknown
owner: pms

# Properties for the Coder plugin are placed here
coder:
templateName: 'devcontainers'
mode: 'auto'
params:
repo: 'custom'
region: 'us-pittsburgh'
```

All config properties are placed under the `spec.coder` property.

## Where these properties are used

At present, there are two main areas where these values are used:

- [`CoderWorkspacesCard`](./components.md#coderworkspacescard) (and all sub-components)
- [`useCoderWorkspacesConfig`](./hooks.md#usecoderworkspacesconfig)

## Property listing

### `templateName`

**Type:** Optional `string`

This defines the name of the Coder template you would like to use when creating new workspaces from Backstage.

**Note:** This value has overlap with the `defaultTemplateName` property defined in [`CoderAppConfig`](types.md#coderappconfig). In the event that both values are present, the YAML file's `templateName` property will always be used instead.

### `templateName`

**Type:** Optional union of `manual` or `auto`

This defines the workspace creation mode that will be embedded as a URL parameter in any outgoing links to make new workspaces in your Coder deployment. (e.g.,`useCoderWorkspacesConfig`'s `creationUrl` property)

**Note:** This value has overlap with the `defaultMode` property defined in [`CoderAppConfig`](types.md#coderappconfig). In the event that both values are present, the YAML file's `mode` property will always be used instead.

### `params`

**Type:** Optional JSON object of string values (equivalent to TypeScript's `Record<string, string | undefined>`)

This allows you to define additional Coder workspace parameter values that should be passed along to any outgoing URLs for making new workspaces in your Coder deployment. These values are fully dynamic, and unfortunately, cannot have much type safety.

**Note:** The properties from the `params` property are automatically merged with the properties defined via `CoderAppConfig`'s `params` property. In the event of any key conflicts, the params from `catalog-info.yaml` will always win.
Loading