-
Notifications
You must be signed in to change notification settings - Fork 24
Add babylon CLI #3210
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
Open
fridim
wants to merge
36
commits into
main
Choose a base branch
from
cli
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add babylon CLI #3210
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
6b79bd1
Add cli-redirect endpoint for babylon CLI
fridim ee22a88
Add babylon CLI
fridim 5da4502
chore: add .worktrees to gitignore
fridim cfdad82
refactor(cli): extract shared helpers from service_order.go
fridim bc000de
feat(cli): add workshop parent command
fridim 30a7484
feat(cli): add Workshop and WorkshopProvision types
fridim c971629
feat(cli): add workshop API functions
fridim 57b805c
feat(cli): add workshop delete command
fridim d06b59b
feat(cli): add workshop list command
fridim 75416bc
feat(cli): add workshop create command
fridim 11201dd
fix(cli): include workshop name in provision failure error
fridim 6c809d6
feat(cli): add workshop status command
fridim b9f2190
feat(cli): add --watch flag to workshop status
fridim 56e2e0c
feat(cli): show provisioning timestamps from AnarchySubject towerJobs
fridim a330f29
fix(cli): always serialize bool fields in WorkshopSpec
fridim 7c67c10
fix: add default: false to Workshop CRD boolean fields
fridim 5fb99e4
Revert "fix: add default: false to Workshop CRD boolean fields"
fridim 735a03e
feat(cli): add cross-compilation support and version command
fridim f5d031c
feat(cli): enrich service status with provision data and tower jobs
fridim 9d276e6
feat(cli): add 'services' alias for service command
fridim 27869da
feat(cli): clarify login help text and --server flag description
fridim b1c6df2
fix(cli): skip 403 namespaces when searching catalog items
fridim 2198c9a
feat(cli): show per-request timing in --debug output
fridim 4598c9a
fix(cli): only store OAuth proxy cookie during login
fridim 367284b
feat(cli): show tower job URLs in service status
fridim 762de47
fix(cli): prepend https:// to tower job URLs when missing
fridim 7803397
fix(cli): reorder service status output for readability
fridim 9160762
feat(cli): use tree connectors for tower jobs in service status
fridim 763c9cb
feat(cli): show human-readable duration for lifespan end
fridim c8c9f81
Add cli/build to .gitignore
fridim 8793adf
fix(cli): catalog describe searches catalog namespaces, not user name…
fridim 1225a3a
feat(cli): add GitHub Action for cross-platform release builds
fridim b564dae
ci: temporarily trigger cli build on cli branch push
fridim eb2f7bd
Add gh suggestion
fridim 540280c
ci: bump GitHub Actions to Node.js 24 compatible versions
fridim 6594594
fix(cli): preserve HTTP method on redirects
fridim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| --- | ||
| name: cli-release | ||
| on: | ||
| push: | ||
| branches: | ||
| - cli # temporary: remove after testing | ||
| tags: | ||
| - "cli-v[0-9]*" | ||
| workflow_dispatch: | ||
| inputs: | ||
| version: | ||
| description: "Version (e.g. v0.1.0)" | ||
| required: true | ||
| type: string | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| env: | ||
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| include: | ||
| - goos: linux | ||
| goarch: amd64 | ||
| - goos: linux | ||
| goarch: arm64 | ||
| - goos: darwin | ||
| goarch: amd64 | ||
| - goos: darwin | ||
| goarch: arm64 | ||
| - goos: windows | ||
| goarch: amd64 | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v5 | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v6 | ||
| with: | ||
| go-version-file: cli/go.mod | ||
|
|
||
| - name: Get version | ||
| id: version | ||
| run: | | ||
| if [[ -n "${{ github.event.inputs.version }}" ]]; then | ||
| echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "VERSION=${GITHUB_REF#refs/tags/cli-}" >> $GITHUB_OUTPUT | ||
| fi | ||
|
|
||
| - name: Build | ||
| working-directory: cli | ||
| env: | ||
| CGO_ENABLED: "0" | ||
| GOOS: ${{ matrix.goos }} | ||
| GOARCH: ${{ matrix.goarch }} | ||
| run: | | ||
| EXT="" | ||
| if [[ "${{ matrix.goos }}" == "windows" ]]; then EXT=".exe"; fi | ||
| OUTPUT="babylon-${{ matrix.goos }}-${{ matrix.goarch }}${EXT}" | ||
| go build \ | ||
| -ldflags="-X 'main.version=${{ steps.version.outputs.VERSION }}' -X 'main.buildCommit=${{ github.sha }}' -X 'main.buildTime=$(date -u)'" \ | ||
| -o "../build/${OUTPUT}" . | ||
| cd ../build && sha256sum "${OUTPUT}" > "${OUTPUT}.sha256" | ||
|
|
||
| - name: Upload artifact | ||
| uses: actions/upload-artifact@v5 | ||
| with: | ||
| name: babylon-${{ matrix.goos }}-${{ matrix.goarch }} | ||
| path: build/babylon-* | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,5 @@ notifier/values.yaml | |
| *.swp | ||
| __pycache__ | ||
| .vscode | ||
| .worktrees | ||
| /cli/build | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| SHELL = /bin/sh | ||
| VERSION ?= $(shell git describe --tags 2>/dev/null || echo development) | ||
| COMMIT ?= $(shell git rev-parse HEAD 2>/dev/null) | ||
| DATE ?= $(shell date -u) | ||
| export CGO_ENABLED=0 | ||
|
|
||
| CLI_LDFLAGS = -X 'main.version=$(VERSION)' -X 'main.buildCommit=$(COMMIT)' -X 'main.buildTime=$(DATE)' | ||
| CLI_PLATFORMS ?= linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64 | ||
|
|
||
| babylon: | ||
| go build -ldflags="$(CLI_LDFLAGS)" -o build/babylon . | ||
|
|
||
| babylon-cross: | ||
| @mkdir -p build | ||
| @for platform in $(CLI_PLATFORMS); do \ | ||
| os=$${platform%/*}; \ | ||
| arch=$${platform#*/}; \ | ||
| output=build/babylon-$${os}-$${arch}; \ | ||
| if [ "$$os" = "windows" ]; then output=$${output}.exe; fi; \ | ||
| echo "Building $$output ..."; \ | ||
| GOOS=$$os GOARCH=$$arch go build -ldflags="$(CLI_LDFLAGS)" -o $$output . || exit 1; \ | ||
| done | ||
| @echo "Done. Binaries:" | ||
| @ls -lh build/babylon-* | ||
| @echo sha256sums: | ||
| @echo '```' | ||
| @cd build && sha256sum babylon-* | ||
| @echo '```' | ||
|
|
||
| clean: | ||
| rm -f build/babylon* | ||
|
|
||
| .PHONY: babylon babylon-cross clean |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package cmd | ||
|
|
||
| import "github.com/spf13/cobra" | ||
|
|
||
| var catalogCmd = &cobra.Command{ | ||
| Use: "catalog", | ||
| Short: "Browse and inspect the service catalog", | ||
| Long: "Commands for listing and describing available catalog items.", | ||
| } | ||
|
|
||
| func init() { | ||
| rootCmd.AddCommand(catalogCmd) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io" | ||
| "strings" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/redhat-gpte/babylon/cli/pkg/output" | ||
| "github.com/redhat-gpte/babylon/cli/pkg/types" | ||
| ) | ||
|
|
||
| var catalogDescribeCmd = &cobra.Command{ | ||
| Use: "describe <catalog-item-name>", | ||
| Short: "Show details of a catalog item", | ||
| Args: cobra.ExactArgs(1), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| name := args[0] | ||
|
|
||
| var ci *types.CatalogItem | ||
| var err error | ||
|
|
||
| // Only use explicit -n flag for catalog lookups, not the default | ||
| // service namespace (which would always 403). | ||
| if cmd.Flags().Changed("namespace") { | ||
| ci, err = apiClient.GetCatalogItem(namespace, name) | ||
| } else { | ||
| ci, err = apiClient.FindCatalogItem(name) | ||
| } | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return output.Print(getOutputFormat(), ci, func(w io.Writer) { | ||
| printCatalogItemDetails(w, ci) | ||
| }) | ||
| }, | ||
| } | ||
|
|
||
| func printCatalogItemDetails(w io.Writer, ci *types.CatalogItem) { | ||
| fmt.Fprintf(w, "Name: %s\n", ci.Metadata.Name) | ||
| fmt.Fprintf(w, "Namespace: %s\n", ci.Metadata.Namespace) | ||
| if ci.Spec.DisplayName != "" { | ||
| fmt.Fprintf(w, "Display: %s\n", ci.Spec.DisplayName) | ||
| } | ||
| if ci.Spec.Category != "" { | ||
| fmt.Fprintf(w, "Category: %s\n", ci.Spec.Category) | ||
| } | ||
|
|
||
| if ci.Spec.Description != nil && ci.Spec.Description.Content != "" { | ||
| desc := stripTags(ci.Spec.Description.Content) | ||
| if len(desc) > 200 { | ||
| desc = desc[:200] + "..." | ||
| } | ||
| fmt.Fprintf(w, "Description: %s\n", desc) | ||
| } | ||
|
|
||
| if ci.Spec.ProvisionTimeEstimate != "" { | ||
| fmt.Fprintf(w, "Provision: ~%s\n", ci.Spec.ProvisionTimeEstimate) | ||
| } | ||
|
|
||
| if ci.Spec.Lifespan != nil { | ||
| parts := []string{} | ||
| if ci.Spec.Lifespan.Default != "" { | ||
| parts = append(parts, "default="+ci.Spec.Lifespan.Default) | ||
| } | ||
| if ci.Spec.Lifespan.Maximum != "" { | ||
| parts = append(parts, "max="+ci.Spec.Lifespan.Maximum) | ||
| } | ||
| if len(parts) > 0 { | ||
| fmt.Fprintf(w, "Lifespan: %s\n", strings.Join(parts, ", ")) | ||
| } | ||
| } | ||
|
|
||
| if ci.Spec.Runtime != nil { | ||
| parts := []string{} | ||
| if ci.Spec.Runtime.Default != "" { | ||
| parts = append(parts, "default="+ci.Spec.Runtime.Default) | ||
| } | ||
| if ci.Spec.Runtime.Maximum != "" { | ||
| parts = append(parts, "max="+ci.Spec.Runtime.Maximum) | ||
| } | ||
| if len(parts) > 0 { | ||
| fmt.Fprintf(w, "Runtime: %s\n", strings.Join(parts, ", ")) | ||
| } | ||
| } | ||
|
|
||
| if len(ci.Spec.Keywords) > 0 { | ||
| fmt.Fprintf(w, "Keywords: %s\n", strings.Join(ci.Spec.Keywords, ", ")) | ||
| } | ||
|
|
||
| if ci.Status != nil && ci.Status.Rating > 0 { | ||
| fmt.Fprintf(w, "Rating: %.1f/5\n", ci.Status.Rating) | ||
| } | ||
|
|
||
| if len(ci.Spec.Parameters) > 0 { | ||
| fmt.Fprintf(w, "\nParameters:\n") | ||
| pt := output.NewTable("NAME", "LABEL", "REQUIRED", "DESCRIPTION") | ||
| for _, p := range ci.Spec.Parameters { | ||
| label := p.FormLabel | ||
| if label == "" { | ||
| label = p.Name | ||
| } | ||
| req := "" | ||
| if p.Required { | ||
| req = "yes" | ||
| } | ||
| pt.AddRow(p.Name, label, req, p.Description) | ||
| } | ||
| pt.Render(w) | ||
| } | ||
| } | ||
|
|
||
| func stripTags(s string) string { | ||
| var result strings.Builder | ||
| inTag := false | ||
| for _, r := range s { | ||
| if r == '<' { | ||
| inTag = true | ||
| continue | ||
| } | ||
| if r == '>' { | ||
| inTag = false | ||
| continue | ||
| } | ||
| if !inTag { | ||
| result.WriteRune(r) | ||
| } | ||
| } | ||
| return result.String() | ||
| } | ||
|
|
||
| func init() { | ||
| catalogCmd.AddCommand(catalogDescribeCmd) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io" | ||
| "strings" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/redhat-gpte/babylon/cli/pkg/output" | ||
| "github.com/redhat-gpte/babylon/cli/pkg/types" | ||
| ) | ||
|
|
||
| var catalogListCategory string | ||
|
|
||
| var catalogListCmd = &cobra.Command{ | ||
| Use: "list", | ||
| Short: "List available catalog items", | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| namespaces := apiClient.CatalogNamespaces() | ||
| if cmd.Flags().Changed("namespace") { | ||
| namespaces = []string{namespace} | ||
| } | ||
|
|
||
| items, err := apiClient.ListAllCatalogItems(namespaces) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Filter by category if specified | ||
| if catalogListCategory != "" { | ||
| filtered := make([]types.CatalogItem, 0) | ||
| for _, item := range items { | ||
| if strings.EqualFold(item.Spec.Category, catalogListCategory) { | ||
| filtered = append(filtered, item) | ||
| } | ||
| } | ||
| items = filtered | ||
| } | ||
|
|
||
| return output.Print(getOutputFormat(), items, func(w io.Writer) { | ||
| if len(items) == 0 { | ||
| output.PrintMessage(w, "No catalog items found.") | ||
| return | ||
| } | ||
| t := output.NewTable("NAME", "DISPLAY NAME", "CATEGORY", "NAMESPACE") | ||
| for _, item := range items { | ||
| displayName := item.Spec.DisplayName | ||
| if displayName == "" { | ||
| displayName = item.Metadata.Name | ||
| } | ||
| t.AddRow( | ||
| item.Metadata.Name, | ||
| displayName, | ||
| item.Spec.Category, | ||
| item.Metadata.Namespace, | ||
| ) | ||
| } | ||
| t.Render(w) | ||
| fmt.Fprintf(w, "\n%d catalog item(s)\n", len(items)) | ||
| }) | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| catalogCmd.AddCommand(catalogListCmd) | ||
| catalogListCmd.Flags().StringVar(&catalogListCategory, "category", "", "filter by category") | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.