@@ -84,6 +84,7 @@ type buildParams struct {
8484 target string
8585 verbose bool
8686 annotations map [string ]string // OCI image annotations
87+ volumes map [string ]struct {}
8788}
8889
8990func main () {
@@ -92,6 +93,7 @@ func main() {
9293 gopaths = flag .String ("gopaths" , "" , "comma-separated list of go paths in src:dst form" )
9394 files = flag .String ("files" , "" , "comma-separated list of static files in src:dst form" )
9495 repos = flag .String ("repos" , "" , "comma-separated list of image registries" )
96+ volumes = flag .String ("volumes" , "" , "comma-separated list of volumes to add" )
9597 tagArg = flag .String ("tags" , "" , "comma-separated tags" )
9698 ldflagsArg = flag .String ("ldflags" , "" , "the --ldflags value to pass to go" )
9799 gotags = flag .String ("gotags" , "" , "the --tags value to pass to go" )
@@ -133,6 +135,13 @@ func main() {
133135 if len (paths ) == 0 && len (staticFiles ) == 0 {
134136 log .Fatal ("at least one of --files or --gopaths must be set" )
135137 }
138+ var vols map [string ]struct {}
139+ for vol := range strings .SplitSeq (* volumes , "," ) {
140+ if vols == nil {
141+ vols = make (map [string ]struct {})
142+ }
143+ vols [strings .TrimSpace (vol )] = struct {}{}
144+ }
136145
137146 bp := & buildParams {
138147 baseImage : * baseImage ,
@@ -145,6 +154,7 @@ func main() {
145154 target : * target ,
146155 verbose : * verbose ,
147156 annotations : parseAnnotations (* annotations ),
157+ volumes : vols ,
148158 }
149159
150160 if err := fetchAndBuild (bp ); err != nil {
@@ -304,7 +314,8 @@ func fetchAndBuild(bp *buildParams) error {
304314
305315 if args := flag .Args (); len (args ) > 0 {
306316 img , err = mutate .Config (img , v1.Config {
307- Cmd : args ,
317+ Cmd : args ,
318+ Volumes : bp .volumes ,
308319 })
309320 if err != nil {
310321 return err
0 commit comments