Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Create an API key from the [Kernel dashboard](https://dashboard.onkernel.com).
- `--with-timestamps`, `-t` - Include timestamps in each log line

- `kernel deploy history [app_name]` - Show deployment history
- `--all` - Show deployment history for all applications
- `--limit <n>` - Max deployments to return (default: 100; 0 = all)

### App Management

Expand All @@ -133,6 +133,7 @@ Create an API key from the [Kernel dashboard](https://dashboard.onkernel.com).
- `--version <version>` - Filter by version

- `kernel app history <app_name>` - Show deployment history for an app
- `--limit <n>` - Max deployments to return (default: 100; 0 = all)

### Logs

Expand Down
14 changes: 12 additions & 2 deletions cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ func init() {
// Add optional filters for list
appListCmd.Flags().String("name", "", "Filter by application name")
appListCmd.Flags().String("version", "", "Filter by version label")

// Limit rows returned for app history (0 = all)
appHistoryCmd.Flags().Int("limit", 100, "Max deployments to return (default 100)")
}

func runAppList(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -109,6 +112,7 @@ func runAppList(cmd *cobra.Command, args []string) error {
func runAppHistory(cmd *cobra.Command, args []string) error {
client := getKernelClient(cmd)
appName := args[0]
lim, _ := cmd.Flags().GetInt("limit")

pterm.Debug.Printf("Fetching deployment history for app '%s'...\n", appName)

Expand All @@ -123,7 +127,7 @@ func runAppHistory(cmd *cobra.Command, args []string) error {
return nil
}

if deployments == nil || len(*deployments) == 0 {
if deployments == nil || len(deployments.Items) == 0 {
pterm.Info.Println("No deployments found for this application")
return nil
}
Expand All @@ -132,7 +136,8 @@ func runAppHistory(cmd *cobra.Command, args []string) error {
{"Deployment ID", "Created At", "Region", "Status", "Entrypoint", "Reason"},
}

for _, dep := range *deployments {
rows := 0
for _, dep := range deployments.Items {
created := util.FormatLocal(dep.CreatedAt)
status := string(dep.Status)

Expand All @@ -144,6 +149,11 @@ func runAppHistory(cmd *cobra.Command, args []string) error {
dep.EntrypointRelPath,
dep.StatusReason,
})

rows++
if lim > 0 && rows >= lim {
break
}
}

printTableNoPad(tableData, true)
Expand Down
25 changes: 14 additions & 11 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func init() {
deployLogsCmd.Flags().BoolP("with-timestamps", "t", false, "Include timestamps in each log line")
deployCmd.AddCommand(deployLogsCmd)

deployHistoryCmd.Flags().Bool("all", false, "Show deployment history for all applications")
deployHistoryCmd.Flags().Int("limit", 100, "Max deployments to return (default 100)")
deployCmd.AddCommand(deployHistoryCmd)
}

Expand Down Expand Up @@ -258,12 +258,12 @@ func runDeployLogs(cmd *cobra.Command, args []string) error {
func runDeployHistory(cmd *cobra.Command, args []string) error {
client := getKernelClient(cmd)

all, _ := cmd.Flags().GetBool("all")
lim, _ := cmd.Flags().GetInt("limit")

var appNames []string
if len(args) == 1 {
appNames = []string{args[0]}
} else if all {
} else {
apps, err := client.Apps.List(cmd.Context(), kernel.AppListParams{})
if err != nil {
pterm.Error.Printf("Failed to list applications: %v\n", err)
Expand All @@ -273,22 +273,21 @@ func runDeployHistory(cmd *cobra.Command, args []string) error {
appNames = append(appNames, a.AppName)
}
// de-duplicate app names
seen := map[string]struct{}{}
seenApps := map[string]struct{}{}
uniq := make([]string, 0, len(appNames))
for _, n := range appNames {
if _, ok := seen[n]; ok {
if _, ok := seenApps[n]; ok {
continue
}
seen[n] = struct{}{}
seenApps[n] = struct{}{}
uniq = append(uniq, n)
}
appNames = uniq
} else {
pterm.Error.Println("Either provide an app name or use --all")
return nil
}

rows := 0
table := pterm.TableData{{"Deployment ID", "Created At", "Region", "Status", "Entrypoint", "Reason"}}
AppsLoop:
for _, appName := range appNames {
params := kernel.DeploymentListParams{AppName: kernel.Opt(appName)}
pterm.Debug.Printf("Listing deployments for app '%s'...\n", appName)
Expand All @@ -297,8 +296,8 @@ func runDeployHistory(cmd *cobra.Command, args []string) error {
pterm.Error.Printf("Failed to list deployments for '%s': %v\n", appName, err)
continue
}
for _, dep := range *deployments {
created := dep.CreatedAt.Format(time.RFC3339)
for _, dep := range deployments.Items {
created := util.FormatLocal(dep.CreatedAt)
status := string(dep.Status)
table = append(table, []string{
dep.ID,
Expand All @@ -308,6 +307,10 @@ func runDeployHistory(cmd *cobra.Command, args []string) error {
dep.EntrypointRelPath,
dep.StatusReason,
})
rows++
if lim > 0 && rows >= lim {
break AppsLoop
}
}
}
if len(table) == 1 {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/charmbracelet/fang v0.2.0
github.com/golang-jwt/jwt/v5 v5.2.2
github.com/joho/godotenv v1.5.1
github.com/onkernel/kernel-go-sdk v0.11.0
github.com/onkernel/kernel-go-sdk v0.11.1
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
github.com/pterm/pterm v0.12.80
github.com/samber/lo v1.51.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ github.com/muesli/roff v0.1.0 h1:YD0lalCotmYuF5HhZliKWlIx7IEhiXeSfq7hNjFqGF8=
github.com/muesli/roff v0.1.0/go.mod h1:pjAHQM9hdUUwm/krAfrLGgJkXJ+YuhtsfZ42kieB2Ig=
github.com/onkernel/kernel-go-sdk v0.11.0 h1:7KUKHiz5t4jdnNCwA8NM1dTtEYdk/AV/RIe8T/HjJwg=
github.com/onkernel/kernel-go-sdk v0.11.0/go.mod h1:q7wsAf+yjpY+w8jbAMciWCtCM0ZUxiw/5o2MSPTZS9E=
github.com/onkernel/kernel-go-sdk v0.11.1 h1:gTxhXtsXrJcrM7KEobEVXa8mPPtRFMlxQwNqkyoCrDI=
github.com/onkernel/kernel-go-sdk v0.11.1/go.mod h1:q7wsAf+yjpY+w8jbAMciWCtCM0ZUxiw/5o2MSPTZS9E=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
1 change: 0 additions & 1 deletion scripts/go-mod-replace-kernel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,3 @@ go mod edit -replace=github.com/onkernel/kernel-go-sdk=github.com/stainless-sdks
go mod tidy

echo "go.mod updated to use github.com/stainless-sdks/kernel-go @ $gomod_version"