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
14 changes: 7 additions & 7 deletions cmd/root/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ func (f *apiFlags) runAPICommand(cmd *cobra.Command, args []string) error {
}()

// Start recording proxy if --record is specified
if _, recordCleanup, err := setupRecordingProxy(f.recordPath, &f.runConfig); err != nil {
_, recordCleanup, err := setupRecordingProxy(f.recordPath, &f.runConfig)
if err != nil {
return err
} else {
defer func() {
if err := recordCleanup(); err != nil {
slog.Error("Failed to cleanup recording proxy", "error", err)
}
}()
}
defer func() {
if err := recordCleanup(); err != nil {
slog.Error("Failed to cleanup recording proxy", "error", err)
}
}()

if f.pullIntervalMins > 0 && !config.IsOCIReference(agentsPath) {
return fmt.Errorf("--pull-interval flag can only be used with OCI references, not local files")
Expand Down
6 changes: 2 additions & 4 deletions cmd/root/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"

"github.com/docker/cli/cli"
"github.com/spf13/cobra"

"github.com/docker/cagent/pkg/config"
Expand Down Expand Up @@ -64,10 +65,7 @@ func runInSandbox(cmd *cobra.Command, runConfig *config.RuntimeConfig, template

if err := dockerCmd.Run(); err != nil {
if exitErr, ok := errors.AsType[*exec.ExitError](err); ok {
// Clean up the token writer before exiting so the temp
// file is removed (defers won't run after os.Exit).
stopTokenWriter()
os.Exit(exitErr.ExitCode()) //nolint:gocritic // intentional exit to propagate sandbox exit code
return cli.StatusError{StatusCode: exitErr.ExitCode()}
}
return fmt.Errorf("docker sandbox exec failed: %w", err)
}
Expand Down
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package main

import (
"context"
"errors"
"os"
"os/signal"
"syscall"

"github.com/docker/cli/cli"

"github.com/docker/cagent/cmd/root"
)

Expand All @@ -14,6 +17,9 @@ func main() {

if err := root.Execute(ctx, os.Stdin, os.Stdout, os.Stderr, os.Args[1:]...); err != nil {
cancel()
if statusErr, ok := errors.AsType[cli.StatusError](err); ok {
os.Exit(statusErr.StatusCode)
}
os.Exit(1)
} else {
cancel()
Expand Down