@@ -20,6 +20,7 @@ import (
20
20
"fmt"
21
21
"io"
22
22
"os"
23
+ "strings"
23
24
"time"
24
25
25
26
"github.com/containerd/containerd"
@@ -81,15 +82,19 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
81
82
prefix := context .String ("base-name" )
82
83
if prefix == "" {
83
84
prefix = fmt .Sprintf ("import-%s" , time .Now ().Format ("2006-01-02" ))
85
+ opts = append (opts , containerd .WithImageRefTranslator (docker .RefTranslator (prefix , false )))
86
+ } else {
87
+ // When provided, filter out references which do not match
88
+ opts = append (opts , containerd .WithImageRefTranslator (docker .RefTranslator (prefix , true )))
84
89
}
85
90
86
91
switch format := context .String ("format" ); format {
87
92
case "" , "docker" , "docker.v1.1" , "docker.v1.2" :
88
- opts = append (opts , containerd .WithImporter (& docker.V1Importer {}))
89
- opts = append (opts , containerd .WithImageRefTranslator (docker .RefTranslator (prefix , context .String ("base-name" ) != "" )))
93
+ opts = append (opts , containerd .WithImporter (& docker.V1Importer {
94
+ SkipOCI : strings .HasPrefix (format , "docker" ),
95
+ }))
90
96
case "oci" , "oci.v1" :
91
97
opts = append (opts , containerd .WithImporter (& oci.V1Importer {}))
92
- opts = append (opts , containerd .WithImageRefTranslator (oci .RefTranslator (prefix )))
93
98
default :
94
99
return fmt .Errorf ("unknown format %s" , format )
95
100
}
0 commit comments