@@ -37,15 +37,16 @@ func NewCmdRegistry() *cobra.Command {
37
37
}
38
38
39
39
func newCmdServe () * cobra.Command {
40
- var disk bool
40
+ var address , disk string
41
+ var blobsToDisk 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 (or $PORT)
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 ()
@@ -54,18 +55,34 @@ Contents are only stored in memory, and when the process exits, pushed data is l
54
55
if port == "" {
55
56
port = "0"
56
57
}
57
- listener , err := net .Listen ("tcp" , ":" + port )
58
+ listenOn := ":" + port
59
+ if address != "" {
60
+ listenOn = address
61
+ }
62
+
63
+ listener , err := net .Listen ("tcp" , listenOn )
58
64
if err != nil {
59
65
log .Fatalln (err )
60
66
}
61
67
porti := listener .Addr ().(* net.TCPAddr ).Port
62
68
port = fmt .Sprintf ("%d" , porti )
63
69
64
70
bh := registry .NewInMemoryBlobHandler ()
65
- if disk {
66
- tmp := os .TempDir ()
67
- log .Printf ("storing blobs in %s" , tmp )
68
- bh = registry .NewDiskBlobHandler (tmp )
71
+
72
+ diskp := disk
73
+ if cmd .Flags ().Changed ("blobs-to-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
80
+ }
81
+ }
82
+
83
+ if diskp != "" {
84
+ log .Printf ("storing blobs in %s" , diskp )
85
+ bh = registry .NewDiskBlobHandler (diskp )
69
86
}
70
87
71
88
s := & http.Server {
@@ -89,7 +106,12 @@ Contents are only stored in memory, and when the process exits, pushed data is l
89
106
return nil
90
107
},
91
108
}
92
- cmd .Flags ().BoolVar (& disk , "blobs-to-disk" , false , "Store blobs on disk" )
109
+ // TODO: remove --blobs-to-disk in a future release.
110
+ cmd .Flags ().BoolVarP (& blobsToDisk , "blobs-to-disk" , "" , false , "Store blobs on disk on tmpdir" )
93
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" )
114
+ cmd .Flags ().StringVar (& address , "address" , "" , "Address to listen on" )
115
+
94
116
return cmd
95
117
}
0 commit comments