-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolver: add config support for mirrors/plainhttp
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
- Loading branch information
1 parent
a9fe50a
commit 7dfe724
Showing
12 changed files
with
130 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package resolver | ||
|
||
import ( | ||
"math/rand" | ||
|
||
"github.com/containerd/containerd/remotes/docker" | ||
"github.com/docker/distribution/reference" | ||
"github.com/moby/buildkit/util/tracing" | ||
) | ||
|
||
type RegistryConf struct { | ||
Mirrors []string | ||
PlainHTTP bool | ||
} | ||
|
||
type ResolveOptionsFunc func(string) docker.ResolverOptions | ||
|
||
func NewResolveOptionsFunc(m map[string]RegistryConf) ResolveOptionsFunc { | ||
return func(ref string) docker.ResolverOptions { | ||
def := docker.ResolverOptions{ | ||
Client: tracing.DefaultClient, | ||
} | ||
|
||
parsed, err := reference.ParseNormalizedNamed(ref) | ||
if err != nil { | ||
return def | ||
} | ||
host := reference.Domain(parsed) | ||
|
||
c, ok := m[host] | ||
if !ok { | ||
return def | ||
} | ||
|
||
if len(c.Mirrors) > 0 { | ||
def.Host = func(string) (string, error) { | ||
return c.Mirrors[rand.Intn(len(c.Mirrors))], nil | ||
} | ||
} | ||
|
||
def.PlainHTTP = c.PlainHTTP | ||
|
||
return def | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters