Skip to content

Commit 0096a9f

Browse files
authored
Merge pull request #76 from clawfleet/fix/auto-pull-on-create
fix: auto-pull image on create if not found locally
2 parents a4ec7b1 + 8283555 commit 0096a9f

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

internal/cli/create.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var createCmd = &cobra.Command{
2828
}
2929

3030
func init() {
31-
createCmd.Flags().BoolVar(&pullFlag, "pull", false, "Force re-pull image even if found locally")
31+
createCmd.Flags().BoolVar(&pullFlag, "pull", false, "Force re-pull image from registry (even if already present locally)")
3232
createCmd.Flags().StringVar(&fromSnapshotFlag, "from-snapshot", "", "Create instance from a saved snapshot")
3333
}
3434

@@ -48,21 +48,21 @@ func runCreate(cmd *cobra.Command, args []string) error {
4848
return err
4949
}
5050

51-
// Check image exists
51+
// Check image exists; auto-pull if missing, force-pull if --pull flag set.
5252
exists, err := container.ImageExists(cli, cfg.ImageRef())
5353
if err != nil {
5454
return err
5555
}
56-
if !exists {
57-
if pullFlag {
56+
if !exists || pullFlag {
57+
if !exists {
5858
fmt.Printf("Image %s not found locally, pulling from registry...\n", cfg.ImageRef())
59-
if pullErr := container.PullImage(cli, cfg.Image.Name, cfg.Image.Tag, os.Stdout); pullErr != nil {
60-
return fmt.Errorf("pull failed: %v\nRun 'clawfleet build' to build it manually", pullErr)
61-
}
62-
fmt.Println("Image pulled successfully.")
6359
} else {
64-
return fmt.Errorf("Image %s not found. Run 'clawfleet build' or build via Dashboard.\nUse --pull to pull from the registry instead.", cfg.ImageRef())
60+
fmt.Printf("Pulling latest %s from registry...\n", cfg.ImageRef())
61+
}
62+
if pullErr := container.PullImage(cli, cfg.Image.Name, cfg.Image.Tag, os.Stdout); pullErr != nil {
63+
return fmt.Errorf("pull failed: %v\nRun 'clawfleet build' to build it manually", pullErr)
6564
}
65+
fmt.Println("Image pulled successfully.")
6666
}
6767

6868
// Ensure network

internal/web/handlers.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package web
33
import (
44
"encoding/json"
55
"fmt"
6+
"io"
67
"log"
78
"net/http"
89
"os"
@@ -105,9 +106,13 @@ func (s *Server) handleCreateInstances(w http.ResponseWriter, r *http.Request) {
105106
return
106107
}
107108
if !exists {
108-
writeError(w, http.StatusPreconditionFailed, fmt.Sprintf(
109-
"Image %s not found. Build the image via System → Image in the Dashboard, or run 'clawfleet build'.", cfg.ImageRef()))
110-
return
109+
log.Printf("Image %s not found locally, pulling from registry...", cfg.ImageRef())
110+
if err := container.PullImage(s.docker, cfg.Image.Name, cfg.Image.Tag, io.Discard); err != nil {
111+
writeError(w, http.StatusPreconditionFailed, fmt.Sprintf(
112+
"Image %s not found locally and pull failed: %v", cfg.ImageRef(), err))
113+
return
114+
}
115+
log.Printf("Image %s pulled successfully", cfg.ImageRef())
111116
}
112117

113118
if err := container.EnsureNetwork(s.docker); err != nil {

0 commit comments

Comments
 (0)