Skip to content

Commit ce43b8a

Browse files
committed
new surface
1 parent 10d278d commit ce43b8a

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

cmd/crane/cmd/serve.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ func newCmdRegistry() *cobra.Command {
3838

3939
func newCmdServe() *cobra.Command {
4040
var address, disk string
41+
var blobs_to_disk bool
4142
cmd := &cobra.Command{
4243
Use: "serve",
43-
Short: "Serve an in-memory registry implementation",
44-
Long: `This sub-command serves an in-memory registry implementation on an automatically chosen port (:0), $PORT or --address
44+
Short: "Serve a registry implementation",
45+
Long: `This sub-command serves a registry implementation on an automatically chosen port (:0), $PORT or --address
4546
4647
The command blocks while the server accepts pushes and pulls.
4748
48-
Contents are only stored in memory, and when the process exits, pushed data is lost.`,
49+
Contents are can be stored in memory (when the process exits, pushed data is lost.), and disk (--disk).`,
4950
Args: cobra.NoArgs,
5051
RunE: func(cmd *cobra.Command, _ []string) error {
5152
ctx := cmd.Context()
@@ -67,14 +68,23 @@ Contents are only stored in memory, and when the process exits, pushed data is l
6768
port = fmt.Sprintf("%d", porti)
6869

6970
bh := registry.NewInMemoryBlobHandler()
71+
72+
diskp := disk
7073
if cmd.Flags().Changed("blobs-to-disk") {
71-
path := os.TempDir()
72-
if disk != "" && disk != " " {
73-
path = disk
74+
if disk != "" {
75+
return fmt.Errorf("--disk and --blobs-to-disk can't be used together")
76+
}
77+
diskp, err = os.MkdirTemp(os.TempDir(), "craneregistry*")
78+
if err != nil {
79+
return err
7480
}
75-
log.Printf("storing blobs in %s", path)
76-
bh = registry.NewDiskBlobHandler(path)
7781
}
82+
83+
if diskp != "" {
84+
log.Printf("storing blobs in %s", diskp)
85+
bh = registry.NewDiskBlobHandler(diskp)
86+
}
87+
7888
s := &http.Server{
7989
ReadHeaderTimeout: 5 * time.Second, // prevent slowloris, quiet linter
8090
Handler: registry.New(registry.WithBlobHandler(bh)),
@@ -96,10 +106,11 @@ Contents are only stored in memory, and when the process exits, pushed data is l
96106
return nil
97107
},
98108
}
99-
cmd.Flags().StringVarP(&disk, "blobs-to-disk", "", "", "Store blobs on disk")
100-
// allow --blobs-to-disk to work without a value
101-
cmd.Flags().Lookup("blobs-to-disk").NoOptDefVal = " "
109+
// TODO: remove --blobs-to-disk in a future release.
110+
cmd.Flags().BoolVarP(&blobs_to_disk, "blobs-to-disk", "", false, "Store blobs on disk on tmpdir")
102111
cmd.Flags().MarkHidden("blobs-to-disk")
112+
cmd.Flags().MarkDeprecated("blobs-to-disk", "and will stop working in a future release. use --disk=$(mktemp -d) instead.")
113+
cmd.Flags().StringVarP(&disk, "disk", "", "", "Path to a directory where blobs will be stored")
103114
cmd.Flags().StringVar(&address, "address", "", "Address to listen on")
104115

105116
return cmd

0 commit comments

Comments
 (0)