@@ -38,14 +38,15 @@ func newCmdRegistry() *cobra.Command {
38
38
39
39
func newCmdServe () * cobra.Command {
40
40
var address , disk string
41
+ var blobs_to_disk bool
41
42
cmd := & cobra.Command {
42
43
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
45
46
46
47
The command blocks while the server accepts pushes and pulls.
47
48
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) .` ,
49
50
Args : cobra .NoArgs ,
50
51
RunE : func (cmd * cobra.Command , _ []string ) error {
51
52
ctx := cmd .Context ()
@@ -67,14 +68,23 @@ Contents are only stored in memory, and when the process exits, pushed data is l
67
68
port = fmt .Sprintf ("%d" , porti )
68
69
69
70
bh := registry .NewInMemoryBlobHandler ()
71
+
72
+ diskp := disk
70
73
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
74
80
}
75
- log .Printf ("storing blobs in %s" , path )
76
- bh = registry .NewDiskBlobHandler (path )
77
81
}
82
+
83
+ if diskp != "" {
84
+ log .Printf ("storing blobs in %s" , diskp )
85
+ bh = registry .NewDiskBlobHandler (diskp )
86
+ }
87
+
78
88
s := & http.Server {
79
89
ReadHeaderTimeout : 5 * time .Second , // prevent slowloris, quiet linter
80
90
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
96
106
return nil
97
107
},
98
108
}
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" )
102
111
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" )
103
114
cmd .Flags ().StringVar (& address , "address" , "" , "Address to listen on" )
104
115
105
116
return cmd
0 commit comments