mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #13131 from Microsoft/10662-loadonwindows
Windows: Build load.go
This commit is contained in:
commit
3985f17812
10 changed files with 63 additions and 45 deletions
|
@ -19,7 +19,7 @@ import (
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/docker/api"
|
"github.com/docker/docker/api"
|
||||||
"github.com/docker/docker/graph"
|
"github.com/docker/docker/graph/tags"
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
"github.com/docker/docker/pkg/fileutils"
|
"github.com/docker/docker/pkg/fileutils"
|
||||||
"github.com/docker/docker/pkg/jsonmessage"
|
"github.com/docker/docker/pkg/jsonmessage"
|
||||||
|
@ -241,7 +241,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(tag) > 0 {
|
if len(tag) > 0 {
|
||||||
if err := graph.ValidateTagName(tag); err != nil {
|
if err := tags.ValidateTagName(tag); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/graph"
|
"github.com/docker/docker/graph/tags"
|
||||||
"github.com/docker/docker/pkg/parsers"
|
"github.com/docker/docker/pkg/parsers"
|
||||||
"github.com/docker/docker/registry"
|
"github.com/docker/docker/registry"
|
||||||
"github.com/docker/docker/runconfig"
|
"github.com/docker/docker/runconfig"
|
||||||
|
@ -26,7 +26,7 @@ func (cli *DockerCli) pullImageCustomOut(image string, out io.Writer) error {
|
||||||
repos, tag := parsers.ParseRepositoryTag(image)
|
repos, tag := parsers.ParseRepositoryTag(image)
|
||||||
// pull only the image tagged 'latest' if no tag was specified
|
// pull only the image tagged 'latest' if no tag was specified
|
||||||
if tag == "" {
|
if tag == "" {
|
||||||
tag = graph.DEFAULTTAG
|
tag = tags.DEFAULTTAG
|
||||||
}
|
}
|
||||||
v.Set("fromImage", repos)
|
v.Set("fromImage", repos)
|
||||||
v.Set("tag", tag)
|
v.Set("tag", tag)
|
||||||
|
@ -100,7 +100,7 @@ func (cli *DockerCli) createContainer(config *runconfig.Config, hostConfig *runc
|
||||||
if statusCode == 404 && strings.Contains(err.Error(), config.Image) {
|
if statusCode == 404 && strings.Contains(err.Error(), config.Image) {
|
||||||
repo, tag := parsers.ParseRepositoryTag(config.Image)
|
repo, tag := parsers.ParseRepositoryTag(config.Image)
|
||||||
if tag == "" {
|
if tag == "" {
|
||||||
tag = graph.DEFAULTTAG
|
tag = tags.DEFAULTTAG
|
||||||
}
|
}
|
||||||
fmt.Fprintf(cli.err, "Unable to find image '%s' locally\n", utils.ImageReference(repo, tag))
|
fmt.Fprintf(cli.err, "Unable to find image '%s' locally\n", utils.ImageReference(repo, tag))
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/docker/docker/graph"
|
"github.com/docker/docker/graph/tags"
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
flag "github.com/docker/docker/pkg/mflag"
|
||||||
"github.com/docker/docker/pkg/parsers"
|
"github.com/docker/docker/pkg/parsers"
|
||||||
"github.com/docker/docker/registry"
|
"github.com/docker/docker/registry"
|
||||||
|
@ -28,7 +28,7 @@ func (cli *DockerCli) CmdPull(args ...string) error {
|
||||||
)
|
)
|
||||||
taglessRemote, tag := parsers.ParseRepositoryTag(remote)
|
taglessRemote, tag := parsers.ParseRepositoryTag(remote)
|
||||||
if tag == "" && !*allTags {
|
if tag == "" && !*allTags {
|
||||||
newRemote = utils.ImageReference(taglessRemote, graph.DEFAULTTAG)
|
newRemote = utils.ImageReference(taglessRemote, tags.DEFAULTTAG)
|
||||||
}
|
}
|
||||||
if tag != "" && *allTags {
|
if tag != "" && *allTags {
|
||||||
return fmt.Errorf("tag can't be used with --all-tags/-a")
|
return fmt.Errorf("tag can't be used with --all-tags/-a")
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"github.com/docker/docker/builder/parser"
|
"github.com/docker/docker/builder/parser"
|
||||||
"github.com/docker/docker/cliconfig"
|
"github.com/docker/docker/cliconfig"
|
||||||
"github.com/docker/docker/daemon"
|
"github.com/docker/docker/daemon"
|
||||||
"github.com/docker/docker/graph"
|
"github.com/docker/docker/graph/tags"
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
"github.com/docker/docker/pkg/httputils"
|
"github.com/docker/docker/pkg/httputils"
|
||||||
"github.com/docker/docker/pkg/parsers"
|
"github.com/docker/docker/pkg/parsers"
|
||||||
|
@ -98,7 +98,7 @@ func Build(d *daemon.Daemon, buildConfig *Config) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(tag) > 0 {
|
if len(tag) > 0 {
|
||||||
if err := graph.ValidateTagName(tag); err != nil {
|
if err := tags.ValidateTagName(tag); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build linux
|
// +build linux windows
|
||||||
|
|
||||||
package graph
|
package graph
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build !linux
|
// +build !linux,!windows
|
||||||
|
|
||||||
package graph
|
package graph
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/docker/docker/daemon/events"
|
"github.com/docker/docker/daemon/events"
|
||||||
|
"github.com/docker/docker/graph/tags"
|
||||||
"github.com/docker/docker/image"
|
"github.com/docker/docker/image"
|
||||||
"github.com/docker/docker/pkg/parsers"
|
"github.com/docker/docker/pkg/parsers"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
|
@ -26,9 +27,8 @@ import (
|
||||||
const DEFAULTTAG = "latest"
|
const DEFAULTTAG = "latest"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
//FIXME these 2 regexes also exist in registry/v2/regexp.go
|
//FIXME this regex also exists in registry/v2/regexp.go
|
||||||
validTagName = regexp.MustCompile(`^[\w][\w.-]{0,127}$`)
|
validDigest = regexp.MustCompile(`[a-zA-Z0-9-_+.]+:[a-fA-F0-9]+`)
|
||||||
validDigest = regexp.MustCompile(`[a-zA-Z0-9-_+.]+:[a-fA-F0-9]+`)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type TagStore struct {
|
type TagStore struct {
|
||||||
|
@ -248,12 +248,12 @@ func (store *TagStore) SetLoad(repoName, tag, imageName string, force bool, out
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if tag == "" {
|
if tag == "" {
|
||||||
tag = DEFAULTTAG
|
tag = tags.DEFAULTTAG
|
||||||
}
|
}
|
||||||
if err := validateRepoName(repoName); err != nil {
|
if err := validateRepoName(repoName); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := ValidateTagName(tag); err != nil {
|
if err := tags.ValidateTagName(tag); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := store.reload(); err != nil {
|
if err := store.reload(); err != nil {
|
||||||
|
@ -384,17 +384,6 @@ func validateRepoName(name string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateTagName validates the name of a tag
|
|
||||||
func ValidateTagName(name string) error {
|
|
||||||
if name == "" {
|
|
||||||
return fmt.Errorf("tag name can't be empty")
|
|
||||||
}
|
|
||||||
if !validTagName.MatchString(name) {
|
|
||||||
return fmt.Errorf("Illegal tag name (%s): only [A-Za-z0-9_.-] are allowed, minimum 1, maximum 128 in length", name)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateDigest(dgst string) error {
|
func validateDigest(dgst string) error {
|
||||||
if dgst == "" {
|
if dgst == "" {
|
||||||
return errors.New("digest can't be empty")
|
return errors.New("digest can't be empty")
|
||||||
|
|
24
graph/tags/tags.go
Normal file
24
graph/tags/tags.go
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
package tags
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
)
|
||||||
|
|
||||||
|
const DEFAULTTAG = "latest"
|
||||||
|
|
||||||
|
var (
|
||||||
|
//FIXME this regex also exists in registry/v2/regexp.go
|
||||||
|
validTagName = regexp.MustCompile(`^[\w][\w.-]{0,127}$`)
|
||||||
|
)
|
||||||
|
|
||||||
|
// ValidateTagName validates the name of a tag
|
||||||
|
func ValidateTagName(name string) error {
|
||||||
|
if name == "" {
|
||||||
|
return fmt.Errorf("tag name can't be empty")
|
||||||
|
}
|
||||||
|
if !validTagName.MatchString(name) {
|
||||||
|
return fmt.Errorf("Illegal tag name (%s): only [A-Za-z0-9_.-] are allowed, minimum 1, maximum 128 in length", name)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
23
graph/tags/tags_unit_test.go
Normal file
23
graph/tags/tags_unit_test.go
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
package tags
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestValidTagName(t *testing.T) {
|
||||||
|
validTags := []string{"9", "foo", "foo-test", "bar.baz.boo"}
|
||||||
|
for _, tag := range validTags {
|
||||||
|
if err := ValidateTagName(tag); err != nil {
|
||||||
|
t.Errorf("'%s' should've been a valid tag", tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInvalidTagName(t *testing.T) {
|
||||||
|
validTags := []string{"-9", ".foo", "-test", ".", "-"}
|
||||||
|
for _, tag := range validTags {
|
||||||
|
if err := ValidateTagName(tag); err == nil {
|
||||||
|
t.Errorf("'%s' shouldn't have been a valid tag", tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -181,24 +181,6 @@ func TestLookupImage(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidTagName(t *testing.T) {
|
|
||||||
validTags := []string{"9", "foo", "foo-test", "bar.baz.boo"}
|
|
||||||
for _, tag := range validTags {
|
|
||||||
if err := ValidateTagName(tag); err != nil {
|
|
||||||
t.Errorf("'%s' should've been a valid tag", tag)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestInvalidTagName(t *testing.T) {
|
|
||||||
validTags := []string{"-9", ".foo", "-test", ".", "-"}
|
|
||||||
for _, tag := range validTags {
|
|
||||||
if err := ValidateTagName(tag); err == nil {
|
|
||||||
t.Errorf("'%s' shouldn't have been a valid tag", tag)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestValidateDigest(t *testing.T) {
|
func TestValidateDigest(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
input string
|
input string
|
||||||
|
|
Loading…
Reference in a new issue