Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ Create an API key from the [Kernel dashboard](https://dashboard.onkernel.com).

- `kernel deploy history [app_name]` - Show deployment history
- `--all` - Show deployment history for all applications
- `--limit <n>` - Max rows to return (default: 100; 0 = all)
- `--offset <n>` - Number of rows to skip from the start

### App Management

Expand All @@ -133,6 +135,8 @@ 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 rows to return (default: 100; 0 = all)
- `--offset <n>` - Number of rows to skip from the start

### Logs

Expand Down
20 changes: 20 additions & 0 deletions cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ 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 rows to return (default 100)")
appHistoryCmd.Flags().Int("offset", 0, "Number of rows to skip from the start")
}

func runAppList(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -109,6 +113,8 @@ 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")
offset, _ := cmd.Flags().GetInt("offset")

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

Expand All @@ -132,7 +138,15 @@ func runAppHistory(cmd *cobra.Command, args []string) error {
{"Deployment ID", "Created At", "Region", "Status", "Entrypoint", "Reason"},
}

rows := 0
seen := 0
for _, dep := range *deployments {
// apply offset before collecting
if offset > 0 && seen < offset {
seen++
continue
}

created := util.FormatLocal(dep.CreatedAt)
status := string(dep.Status)

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

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

printTableNoPad(tableData, true)
Expand Down
22 changes: 19 additions & 3 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func init() {
deployCmd.AddCommand(deployLogsCmd)

deployHistoryCmd.Flags().Bool("all", false, "Show deployment history for all applications")
deployHistoryCmd.Flags().Int("limit", 100, "Max rows to return (default 100)")
deployHistoryCmd.Flags().Int("offset", 0, "Number of rows to skip from the start")
deployCmd.AddCommand(deployHistoryCmd)
}

Expand Down Expand Up @@ -259,6 +261,8 @@ func runDeployHistory(cmd *cobra.Command, args []string) error {
client := getKernelClient(cmd)

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

var appNames []string
if len(args) == 1 {
Expand All @@ -273,13 +277,13 @@ 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
Expand All @@ -288,7 +292,10 @@ func runDeployHistory(cmd *cobra.Command, args []string) error {
return nil
}

rows := 0
seen := 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 @@ -298,6 +305,10 @@ func runDeployHistory(cmd *cobra.Command, args []string) error {
continue
}
for _, dep := range *deployments {
if offset > 0 && seen < offset {
seen++
continue
}
created := dep.CreatedAt.Format(time.RFC3339)
status := string(dep.Status)
table = append(table, []string{
Expand All @@ -308,6 +319,11 @@ func runDeployHistory(cmd *cobra.Command, args []string) error {
dep.EntrypointRelPath,
dep.StatusReason,
})
rows++
seen++
if lim > 0 && rows >= lim {
break AppsLoop
}
}
}
if len(table) == 1 {
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ require (
golang.org/x/text v0.24.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/onkernel/kernel-go-sdk => github.com/onkernel/kernel-go-sdk v0.11.0
3 changes: 1 addition & 2 deletions scripts/go-mod-replace-kernel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,4 @@ go mod edit -dropreplace=github.com/onkernel/kernel-go-sdk 2>/dev/null || true
go mod edit -replace=github.com/onkernel/kernel-go-sdk=github.com/stainless-sdks/kernel-go@"$gomod_version"
go mod tidy

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

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