Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 39fb743

Browse files
committed
use docker v1.10 to manage docker images and container
Signed-off-by: Gao feng <[email protected]>
1 parent 17ea238 commit 39fb743

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+3788
-3345
lines changed

Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ else
1111
LIBVIRT_BUILD_TAG=
1212
endif
1313

14-
HYPER_BULD_TAGS=$(XEN_BUILD_TAG) $(LIBVIRT_BUILD_TAG) libdm_no_deferred_remove
14+
HYPER_BULD_TAGS=$(XEN_BUILD_TAG) $(LIBVIRT_BUILD_TAG) libdm_no_deferred_remove exclude_graphdriver_btrfs
1515
if ON_DARWIN
1616
SUBDIRS=mac_installer
1717
endif

client/build.go

+58-24
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ import (
1111
"strings"
1212

1313
"github.com/docker/docker/api"
14-
"github.com/docker/docker/graph/tags"
14+
"github.com/docker/docker/builder/dockerignore"
1515
"github.com/docker/docker/pkg/archive"
1616
"github.com/docker/docker/pkg/fileutils"
17-
"github.com/docker/docker/pkg/parsers"
18-
"github.com/docker/docker/pkg/progressreader"
17+
"github.com/docker/docker/pkg/progress"
1918
"github.com/docker/docker/pkg/streamformatter"
2019
"github.com/docker/docker/pkg/symlink"
21-
"github.com/docker/docker/registry"
22-
"github.com/docker/docker/utils"
20+
"github.com/docker/docker/reference"
2321
rand "github.com/hyperhq/hyper/utils"
2422

2523
gflag "github.com/jessevdk/go-flags"
@@ -114,13 +112,13 @@ func (cli *HyperClient) HyperCmdBuild(args ...string) error {
114112

115113
var excludes []string
116114
if err == nil {
117-
excludes, err = utils.ReadDockerIgnore(f)
115+
excludes, err = dockerignore.ReadAll(f)
118116
if err != nil {
119117
return err
120118
}
121119
}
122120

123-
if err := utils.ValidateContextDirectory(root, excludes); err != nil {
121+
if err := ValidateContextDirectory(root, excludes); err != nil {
124122
return fmt.Errorf("Error checking context: '%s'.", err)
125123
}
126124

@@ -136,7 +134,7 @@ func (cli *HyperClient) HyperCmdBuild(args ...string) error {
136134
includes = append(includes, ".dockerignore", opts.DockerfileName)
137135
}
138136

139-
if err := utils.ValidateContextDirectory(root, excludes); err != nil {
137+
if err := ValidateContextDirectory(root, excludes); err != nil {
140138
return fmt.Errorf("Error checking context: '%s'.", err)
141139
}
142140
options := &archive.TarOptions{
@@ -152,31 +150,21 @@ func (cli *HyperClient) HyperCmdBuild(args ...string) error {
152150
// Setup an upload progress bar
153151
// FIXME: ProgressReader shouldn't be this annoying to use
154152
if context != nil {
155-
sf := streamformatter.NewStreamFormatter()
156-
body = progressreader.New(progressreader.Config{
157-
In: context,
158-
Out: os.Stdout,
159-
Formatter: sf,
160-
NewLines: true,
161-
ID: "",
162-
Action: "Sending build context to Docker daemon",
163-
})
153+
var progBuff io.Writer = cli.out
154+
155+
progressOutput := streamformatter.NewStreamFormatter().NewProgressOutput(progBuff, true)
156+
157+
body = progress.NewProgressReader(context, progressOutput, 0, "", "Sending build context to Docker daemon")
164158
}
165159

166160
if opts.ImageName == "" {
167161
// set a image name
168162
name = rand.RandStr(10, "alphanum")
169163
} else {
170164
name = opts.ImageName
171-
repository, tag := parsers.ParseRepositoryTag(name)
172-
if err := registry.ValidateRepositoryName(repository); err != nil {
165+
if _, err := reference.ParseNamed(name); err != nil {
173166
return err
174167
}
175-
if len(tag) > 0 {
176-
if err := tags.ValidateTagName(tag); err != nil {
177-
return err
178-
}
179-
}
180168
}
181169
v := url.Values{}
182170
v.Set("name", name)
@@ -190,3 +178,49 @@ func (cli *HyperClient) HyperCmdBuild(args ...string) error {
190178
}
191179
return nil
192180
}
181+
182+
// validateContextDirectory checks if all the contents of the directory
183+
// can be read and returns an error if some files can't be read
184+
// symlinks which point to non-existing files don't trigger an error
185+
func ValidateContextDirectory(srcPath string, excludes []string) error {
186+
contextRoot := filepath.Join(srcPath, ".")
187+
188+
return filepath.Walk(contextRoot, func(filePath string, f os.FileInfo, err error) error {
189+
// skip this directory/file if it's not in the path, it won't get added to the context
190+
if relFilePath, err := filepath.Rel(contextRoot, filePath); err != nil {
191+
return err
192+
} else if skip, err := fileutils.Matches(relFilePath, excludes); err != nil {
193+
return err
194+
} else if skip {
195+
if f.IsDir() {
196+
return filepath.SkipDir
197+
}
198+
return nil
199+
}
200+
201+
if err != nil {
202+
if os.IsPermission(err) {
203+
return fmt.Errorf("can't stat '%s'", filePath)
204+
}
205+
if os.IsNotExist(err) {
206+
return nil
207+
}
208+
return err
209+
}
210+
211+
// skip checking if symlinks point to non-existing files, such symlinks can be useful
212+
// also skip named pipes, because they hanging on open
213+
if f.Mode()&(os.ModeSymlink|os.ModeNamedPipe) != 0 {
214+
return nil
215+
}
216+
217+
if !f.IsDir() {
218+
currentFile, err := os.Open(filePath)
219+
if err != nil && os.IsPermission(err) {
220+
return fmt.Errorf("no permission to read from '%s'", filePath)
221+
}
222+
currentFile.Close()
223+
}
224+
return nil
225+
})
226+
}

client/login.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import (
88
"os"
99
"strings"
1010

11-
"github.com/docker/docker/api/types"
12-
"github.com/docker/docker/cliconfig"
1311
"github.com/docker/docker/registry"
12+
"github.com/docker/engine-api/types"
1413
"github.com/hyperhq/runv/lib/term"
1514

1615
gflag "github.com/jessevdk/go-flags"
@@ -65,7 +64,7 @@ func (cli *HyperClient) HyperCmdLogin(args ...string) error {
6564

6665
authconfig, ok := cli.configFile.AuthConfigs[serverAddress]
6766
if !ok {
68-
authconfig = cliconfig.AuthConfig{}
67+
authconfig = types.AuthConfig{}
6968
}
7069

7170
if username == "" {

client/logs.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import (
66
"net/url"
77
"os"
88
"strings"
9-
"time"
109

11-
"github.com/docker/docker/pkg/timeutils"
1210
gflag "github.com/jessevdk/go-flags"
1311
)
1412

@@ -39,10 +37,7 @@ func (cli *HyperClient) HyperCmdLogs(args ...string) error {
3937
v.Set("container", args[0])
4038
v.Set("stdout", "yes")
4139
v.Set("stderr", "yes")
42-
43-
if opts.Since != "" {
44-
v.Set("since", timeutils.GetTimestamp(opts.Since, time.Now()))
45-
}
40+
v.Set("since", opts.Since)
4641

4742
if opts.Times {
4843
v.Set("timestamps", "yes")

client/pull.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"net/url"
66
"strings"
77

8-
"github.com/docker/docker/pkg/parsers"
8+
"github.com/docker/docker/reference"
99
"github.com/docker/docker/registry"
1010
"github.com/hyperhq/runv/hypervisor/pod"
1111

@@ -31,14 +31,23 @@ func (cli *HyperClient) HyperCmdPull(args ...string) error {
3131
}
3232

3333
func (cli *HyperClient) PullImage(imageName string) error {
34-
remote, _ := parsers.ParseRepositoryTag(imageName)
34+
distributionRef, err := reference.ParseNamed(imageName)
35+
if err != nil {
36+
return err
37+
}
38+
if reference.IsNameOnly(distributionRef) {
39+
distributionRef = reference.WithDefaultTag(distributionRef)
40+
fmt.Fprintf(cli.out, "Using default tag: %s\n", reference.DefaultTag)
41+
}
42+
3543
// Resolve the Repository name from fqn to RepositoryInfo
36-
repoInfo, err := registry.ParseRepositoryInfo(remote)
44+
repoInfo, err := registry.ParseRepositoryInfo(distributionRef)
3745
if err != nil {
3846
return err
3947
}
48+
4049
v := url.Values{}
41-
v.Set("imageName", imageName)
50+
v.Set("imageName", distributionRef.String())
4251
_, _, err = cli.clientRequestAttemptLogin("POST", "/image/create?"+v.Encode(), nil, cli.out, repoInfo.Index, "pull")
4352
return err
4453
}

client/push.go

+18-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"net/url"
66
"strings"
77

8-
"github.com/docker/docker/pkg/parsers"
8+
"github.com/docker/docker/reference"
99
"github.com/docker/docker/registry"
1010

1111
gflag "github.com/jessevdk/go-flags"
@@ -30,15 +30,27 @@ func (cli *HyperClient) HyperCmdPush(args ...string) error {
3030
return fmt.Errorf("\"push\" requires a minimum of 1 argument, please provide the image name.")
3131
}
3232
name := args[0]
33-
remote, tag := parsers.ParseRepositoryTag(name)
33+
34+
ref, err := reference.ParseNamed(name)
35+
if err != nil {
36+
return err
37+
}
38+
39+
var tag string
40+
switch x := ref.(type) {
41+
case reference.Canonical:
42+
return fmt.Errorf("cannot push a digest reference")
43+
case reference.NamedTagged:
44+
tag = x.Tag()
45+
}
3446

3547
// Resolve the Repository name from fqn to RepositoryInfo
36-
repoInfo, err := registry.ParseRepositoryInfo(remote)
48+
repoInfo, err := registry.ParseRepositoryInfo(ref)
3749
if err != nil {
3850
return err
3951
}
4052
// Resolve the Auth config relevant for this server
41-
authConfig := registry.ResolveAuthConfig(cli.configFile, repoInfo.Index)
53+
authConfig := registry.ResolveAuthConfig(cli.configFile.AuthConfigs, repoInfo.Index)
4254
// If we're not using a custom registry, we know the restrictions
4355
// applied to repository names and can warn the user in advance.
4456
// Custom repositories can have different rules, and we must also
@@ -48,12 +60,12 @@ func (cli *HyperClient) HyperCmdPush(args ...string) error {
4860
if username == "" {
4961
username = "<user>"
5062
}
51-
return fmt.Errorf("You cannot push a \"root\" repository. Please rename your repository to <user>/<repo> (ex: %s/%s)", username, repoInfo.LocalName)
63+
return fmt.Errorf("You cannot push a \"root\" repository. Please rename your repository to <user>/<repo> (ex: %s/%s)", username, ref.Name())
5264
}
5365

5466
v := url.Values{}
5567
v.Set("tag", tag)
56-
v.Set("remote", remote)
68+
v.Set("remote", repoInfo.String())
5769

5870
_, _, err = cli.clientRequestAttemptLogin("POST", "/image/push?"+v.Encode(), nil, cli.out, repoInfo.Index, "push")
5971
return err

client/utils.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ import (
1616
"strings"
1717
"syscall"
1818

19-
"github.com/docker/docker/cliconfig"
2019
"github.com/docker/docker/pkg/jsonmessage"
2120
"github.com/docker/docker/pkg/stdcopy"
2221
"github.com/docker/docker/registry"
22+
"github.com/docker/engine-api/types"
23+
registrytypes "github.com/docker/engine-api/types/registry"
24+
2325
"github.com/hyperhq/hyper/utils"
2426
"github.com/hyperhq/runv/hypervisor/pod"
2527
"github.com/hyperhq/runv/lib/term"
@@ -99,8 +101,8 @@ func (cli *HyperClient) clientRequest(method, path string, in io.Reader, headers
99101
return resp.Body, resp.Header.Get("Content-Type"), statusCode, nil
100102
}
101103

102-
func (cli *HyperClient) clientRequestAttemptLogin(method, path string, in io.Reader, out io.Writer, index *registry.IndexInfo, cmdName string) (io.ReadCloser, int, error) {
103-
cmdAttempt := func(authConfig cliconfig.AuthConfig) (io.ReadCloser, int, error) {
104+
func (cli *HyperClient) clientRequestAttemptLogin(method, path string, in io.Reader, out io.Writer, index *registrytypes.IndexInfo, cmdName string) (io.ReadCloser, int, error) {
105+
cmdAttempt := func(authConfig types.AuthConfig) (io.ReadCloser, int, error) {
104106
buf, err := json.Marshal(authConfig)
105107
if err != nil {
106108
return nil, -1, err
@@ -131,14 +133,14 @@ func (cli *HyperClient) clientRequestAttemptLogin(method, path string, in io.Rea
131133
}
132134

133135
// Resolve the Auth config relevant for this server
134-
authConfig := registry.ResolveAuthConfig(cli.configFile, index)
136+
authConfig := registry.ResolveAuthConfig(cli.configFile.AuthConfigs, index)
135137
body, statusCode, err := cmdAttempt(authConfig)
136138
if statusCode == http.StatusUnauthorized {
137139
fmt.Fprintf(cli.out, "\nPlease login prior to %s:\n", cmdName)
138-
if err = cli.HyperCmdLogin(index.GetAuthConfigKey()); err != nil {
140+
if err = cli.HyperCmdLogin(registry.GetAuthConfigKey(index)); err != nil {
139141
return nil, -1, err
140142
}
141-
authConfig = registry.ResolveAuthConfig(cli.configFile, index)
143+
authConfig = registry.ResolveAuthConfig(cli.configFile.AuthConfigs, index)
142144
return cmdAttempt(authConfig)
143145
}
144146
return body, statusCode, err
@@ -176,7 +178,7 @@ func (cli *HyperClient) streamBody(body io.ReadCloser, contentType string, setRa
176178
defer body.Close()
177179

178180
if utils.MatchesContentType(contentType, "application/json") {
179-
return jsonmessage.DisplayJSONMessagesStream(body, stdout, cli.outFd, cli.isTerminalOut)
181+
return jsonmessage.DisplayJSONMessagesStream(body, stdout, cli.outFd, cli.isTerminalOut, nil)
180182
}
181183
if stdout != nil || stderr != nil {
182184
// When TTY is ON, use regular copy

daemon/attach.go

+10-18
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,29 @@ package daemon
22

33
import (
44
"fmt"
5+
"io"
6+
57
"github.com/golang/glog"
6-
"github.com/hyperhq/hyper/engine"
78
"github.com/hyperhq/runv/hypervisor/types"
89
)
910

10-
func (daemon *Daemon) CmdAttach(job *engine.Job) (err error) {
11-
if len(job.Args) == 0 {
12-
return fmt.Errorf("Can not execute 'attach' command without any container/pod ID!")
13-
}
14-
if len(job.Args) == 1 {
15-
return fmt.Errorf("Can not execute 'attach' command without any command!")
16-
}
17-
typeKey := job.Args[0]
18-
typeVal := job.Args[1]
19-
tag := job.Args[2]
20-
21-
var podId, container string
11+
func (daemon *Daemon) Attach(stdin io.ReadCloser, stdout io.WriteCloser, key, id, tag string) error {
12+
var podId, vmId, container string
13+
var err error
2214

2315
// We need find the vm id which running POD, and stop it
24-
if typeKey == "pod" {
25-
podId = typeVal
16+
if key == "pod" {
17+
podId = id
2618
container = ""
2719
} else {
28-
container = typeVal
20+
container = id
2921
podId, err = daemon.GetPodByContainer(container)
3022
if err != nil {
3123
return err
3224
}
3325
}
3426

35-
vmId, err := daemon.GetVmByPodId(podId)
27+
vmId, err = daemon.GetVmByPodId(podId)
3628
if err != nil {
3729
return err
3830
}
@@ -43,7 +35,7 @@ func (daemon *Daemon) CmdAttach(job *engine.Job) (err error) {
4335
}
4436

4537
ttyCallback := make(chan *types.VmResponse, 1)
46-
err = vm.Attach(job.Stdin, job.Stdout, tag, container, ttyCallback, nil)
38+
err = vm.Attach(stdin, stdout, tag, container, ttyCallback, nil)
4739
if err != nil {
4840
return err
4941
}

0 commit comments

Comments
 (0)