Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
58 changes: 45 additions & 13 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 @@ -117,13 +123,13 @@ func runAppHistory(cmd *cobra.Command, args []string) error {
params.AppName = kernel.Opt(appName)
}

deployments, err := client.Deployments.List(cmd.Context(), params)
page, err := client.Deployments.List(cmd.Context(), params)
if err != nil {
pterm.Error.Printf("Failed to list deployments: %v\n", err)
return nil
}

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

for _, dep := range *deployments {
created := dep.CreatedAt.Format(time.RFC3339)
status := string(dep.Status)
rows := 0
seen := 0
stop := false
for page != nil && !stop {
for _, dep := range page.Items {
// apply offset before collecting
if offset > 0 && seen < offset {
seen++
continue
}

tableData = append(tableData, []string{
dep.ID,
created,
string(dep.Region),
status,
dep.EntrypointRelPath,
dep.StatusReason,
})
created := dep.CreatedAt.Format(time.RFC3339)
status := string(dep.Status)

tableData = append(tableData, []string{
dep.ID,
created,
string(dep.Region),
status,
dep.EntrypointRelPath,
dep.StatusReason,
})

rows++
seen++
if lim > 0 && rows >= lim {
stop = true
break
}
}
if stop {
break
}
page, err = page.GetNextPage()
if err != nil {
pterm.Error.Printf("Failed to fetch next page: %v\n", err)
break
}
}

printTableNoPad(tableData, true)
Expand Down
53 changes: 38 additions & 15 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,26 +292,45 @@ 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)
deployments, err := client.Deployments.List(cmd.Context(), params)
page, err := client.Deployments.List(cmd.Context(), params)
if err != nil {
pterm.Error.Printf("Failed to list deployments for '%s': %v\n", appName, err)
continue
}
for _, dep := range *deployments {
created := dep.CreatedAt.Format(time.RFC3339)
status := string(dep.Status)
table = append(table, []string{
dep.ID,
created,
string(dep.Region),
status,
dep.EntrypointRelPath,
dep.StatusReason,
})
for page != nil {
for _, dep := range page.Items {
if offset > 0 && seen < offset {
seen++
continue
}
created := dep.CreatedAt.Format(time.RFC3339)
status := string(dep.Status)
table = append(table, []string{
dep.ID,
created,
string(dep.Region),
status,
dep.EntrypointRelPath,
dep.StatusReason,
})
rows++
seen++
if lim > 0 && rows >= lim {
break AppsLoop
}
}
page, err = page.GetNextPage()
if err != nil {
pterm.Error.Printf("Failed to fetch next page for '%s': %v\n", appName, err)
break
}
}
}
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.0.0-20250905180042-8cd5228e682b
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ github.com/muesli/mango-pflag v0.1.0 h1:UADqbYgpUyRoBja3g6LUL+3LErjpsOwaC9ywvBWe
github.com/muesli/mango-pflag v0.1.0/go.mod h1:YEQomTxaCUp8PrbhFh10UfbhbQrM/xJ4i2PB8VTLLW0=
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.10.1-0.20250827184402-40919678c68e h1:5z9iNVA+zyzJZMRn4UGJkhP/ibPZr+/9pxoUK9KqgKk=
github.com/onkernel/kernel-go-sdk v0.10.1-0.20250827184402-40919678c68e/go.mod h1:q7wsAf+yjpY+w8jbAMciWCtCM0ZUxiw/5o2MSPTZS9E=
github.com/onkernel/kernel-go-sdk v0.0.0-20250905180042-8cd5228e682b h1:Nz8Zfkns0AcuujajJlltOrhs2SxnYoWjMCHkMbcC49g=
github.com/onkernel/kernel-go-sdk v0.0.0-20250905180042-8cd5228e682b/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
8 changes: 4 additions & 4 deletions scripts/go-mod-replace-kernel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ ref="$1"
commit=""
tmp_dir="/tmp/kernel-go"

# Clone the stainless-sdks/kernel-go repo at the provided commit (shallow clone for speed)
# Clone the onkernel/kernel-go-sdk repo at the provided commit (shallow clone for speed)
rm -rf "$tmp_dir"
git clone --filter=blob:none --quiet git@github.com:stainless-sdks/kernel-go "$tmp_dir"
git clone --filter=blob:none --quiet git@github.com:onkernel/kernel-go-sdk.git "$tmp_dir"

# Determine the commit hash corresponding to the provided ref (commit hash or branch name)
pushd "$tmp_dir" >/dev/null
Expand Down Expand Up @@ -63,8 +63,8 @@ fi
# Remove any existing replace directive for the SDK (ignore error if it doesn't exist)
# Then add the new replace directive pointing at the desired commit
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 edit -replace=github.com/onkernel/kernel-go-sdk=github.com/onkernel/kernel-go-sdk@"$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/onkernel/kernel-go-sdk @ $gomod_version"