mirror of
https://github.com/containers/skopeo.git
synced 2025-09-14 13:59:44 +00:00
20
vendor/github.com/docker/distribution/manifests.go
generated
vendored
20
vendor/github.com/docker/distribution/manifests.go
generated
vendored
@@ -2,7 +2,7 @@ package distribution
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"mime"
|
||||
|
||||
"github.com/docker/distribution/context"
|
||||
"github.com/docker/distribution/digest"
|
||||
@@ -84,19 +84,23 @@ var mappings = make(map[string]UnmarshalFunc, 0)
|
||||
// UnmarshalManifest looks up manifest unmarshall functions based on
|
||||
// MediaType
|
||||
func UnmarshalManifest(ctHeader string, p []byte) (Manifest, Descriptor, error) {
|
||||
// Need to look up by the actual content type, not the raw contents of
|
||||
// Need to look up by the actual media type, not the raw contents of
|
||||
// the header. Strip semicolons and anything following them.
|
||||
var mediatype string
|
||||
semicolonIndex := strings.Index(ctHeader, ";")
|
||||
if semicolonIndex != -1 {
|
||||
mediatype = ctHeader[:semicolonIndex]
|
||||
} else {
|
||||
mediatype = ctHeader
|
||||
if ctHeader != "" {
|
||||
var err error
|
||||
mediatype, _, err = mime.ParseMediaType(ctHeader)
|
||||
if err != nil {
|
||||
return nil, Descriptor{}, err
|
||||
}
|
||||
}
|
||||
|
||||
unmarshalFunc, ok := mappings[mediatype]
|
||||
if !ok {
|
||||
return nil, Descriptor{}, fmt.Errorf("unsupported manifest mediatype: %s", mediatype)
|
||||
unmarshalFunc, ok = mappings[""]
|
||||
if !ok {
|
||||
return nil, Descriptor{}, fmt.Errorf("unsupported manifest mediatype and no default available: %s", mediatype)
|
||||
}
|
||||
}
|
||||
|
||||
return unmarshalFunc(p)
|
||||
|
2
vendor/github.com/docker/distribution/reference/reference.go
generated
vendored
2
vendor/github.com/docker/distribution/reference/reference.go
generated
vendored
@@ -6,7 +6,7 @@
|
||||
// reference := repository [ ":" tag ] [ "@" digest ]
|
||||
// name := [hostname '/'] component ['/' component]*
|
||||
// hostname := hostcomponent ['.' hostcomponent]* [':' port-number]
|
||||
// hostcomponent := /([a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])/
|
||||
// hostcomponent := /([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])/
|
||||
// port-number := /[0-9]+/
|
||||
// component := alpha-numeric [separator alpha-numeric]*
|
||||
// alpha-numeric := /[a-z0-9]+/
|
||||
|
2
vendor/github.com/docker/distribution/reference/regexp.go
generated
vendored
2
vendor/github.com/docker/distribution/reference/regexp.go
generated
vendored
@@ -22,7 +22,7 @@ var (
|
||||
// hostnameComponentRegexp restricts the registry hostname component of a
|
||||
// repository name to start with a component as defined by hostnameRegexp
|
||||
// and followed by an optional port.
|
||||
hostnameComponentRegexp = match(`(?:[a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])`)
|
||||
hostnameComponentRegexp = match(`(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])`)
|
||||
|
||||
// hostnameRegexp defines the structure of potential hostname components
|
||||
// that may be part of image names. This is purposely a subset of what is
|
||||
|
2
vendor/github.com/docker/docker/api/common.go
generated
vendored
2
vendor/github.com/docker/docker/api/common.go
generated
vendored
@@ -18,7 +18,7 @@ import (
|
||||
// Common constants for daemon and client.
|
||||
const (
|
||||
// Version of Current REST API
|
||||
DefaultVersion version.Version = "1.23"
|
||||
DefaultVersion version.Version = "1.22"
|
||||
|
||||
// MinVersion represents Minimum REST API version supported
|
||||
MinVersion version.Version = "1.12"
|
||||
|
16
vendor/github.com/docker/docker/distribution/pull_v2.go
generated
vendored
16
vendor/github.com/docker/docker/distribution/pull_v2.go
generated
vendored
@@ -171,6 +171,10 @@ func (ld *v2LayerDescriptor) Download(ctx context.Context, progressOutput progre
|
||||
|
||||
_, err = io.Copy(tmpFile, io.TeeReader(reader, verifier))
|
||||
if err != nil {
|
||||
tmpFile.Close()
|
||||
if err := os.Remove(tmpFile.Name()); err != nil {
|
||||
logrus.Errorf("Failed to remove temp file: %s", tmpFile.Name())
|
||||
}
|
||||
return nil, 0, retryOnError(err)
|
||||
}
|
||||
|
||||
@@ -179,8 +183,9 @@ func (ld *v2LayerDescriptor) Download(ctx context.Context, progressOutput progre
|
||||
if !verifier.Verified() {
|
||||
err = fmt.Errorf("filesystem layer verification failed for digest %s", ld.digest)
|
||||
logrus.Error(err)
|
||||
|
||||
tmpFile.Close()
|
||||
if err := os.RemoveAll(tmpFile.Name()); err != nil {
|
||||
if err := os.Remove(tmpFile.Name()); err != nil {
|
||||
logrus.Errorf("Failed to remove temp file: %s", tmpFile.Name())
|
||||
}
|
||||
|
||||
@@ -191,7 +196,14 @@ func (ld *v2LayerDescriptor) Download(ctx context.Context, progressOutput progre
|
||||
|
||||
logrus.Debugf("Downloaded %s to tempfile %s", ld.ID(), tmpFile.Name())
|
||||
|
||||
tmpFile.Seek(0, 0)
|
||||
_, err = tmpFile.Seek(0, os.SEEK_SET)
|
||||
if err != nil {
|
||||
tmpFile.Close()
|
||||
if err := os.Remove(tmpFile.Name()); err != nil {
|
||||
logrus.Errorf("Failed to remove temp file: %s", tmpFile.Name())
|
||||
}
|
||||
return nil, 0, xfer.DoNotRetry{Err: err}
|
||||
}
|
||||
return ioutils.NewReadCloserWrapper(tmpFile, tmpFileCloser(tmpFile)), size, nil
|
||||
}
|
||||
|
||||
|
12
vendor/github.com/docker/docker/distribution/push.go
generated
vendored
12
vendor/github.com/docker/docker/distribution/push.go
generated
vendored
@@ -171,7 +171,14 @@ func Push(ctx context.Context, ref reference.Named, imagePushConfig *ImagePushCo
|
||||
// argument so that it can be used with httpBlobWriter's ReadFrom method.
|
||||
// Using httpBlobWriter's Write method would send a PATCH request for every
|
||||
// Write call.
|
||||
func compress(in io.Reader) io.ReadCloser {
|
||||
//
|
||||
// The second return value is a channel that gets closed when the goroutine
|
||||
// is finished. This allows the caller to make sure the goroutine finishes
|
||||
// before it releases any resources connected with the reader that was
|
||||
// passed in.
|
||||
func compress(in io.Reader) (io.ReadCloser, chan struct{}) {
|
||||
compressionDone := make(chan struct{})
|
||||
|
||||
pipeReader, pipeWriter := io.Pipe()
|
||||
// Use a bufio.Writer to avoid excessive chunking in HTTP request.
|
||||
bufWriter := bufio.NewWriterSize(pipeWriter, compressionBufSize)
|
||||
@@ -190,7 +197,8 @@ func compress(in io.Reader) io.ReadCloser {
|
||||
} else {
|
||||
pipeWriter.Close()
|
||||
}
|
||||
close(compressionDone)
|
||||
}()
|
||||
|
||||
return pipeReader
|
||||
return pipeReader, compressionDone
|
||||
}
|
||||
|
7
vendor/github.com/docker/docker/distribution/push_v2.go
generated
vendored
7
vendor/github.com/docker/docker/distribution/push_v2.go
generated
vendored
@@ -345,8 +345,11 @@ func (pd *v2PushDescriptor) Upload(ctx context.Context, progressOutput progress.
|
||||
size, _ := pd.layer.DiffSize()
|
||||
|
||||
reader := progress.NewProgressReader(ioutils.NewCancelReadCloser(ctx, arch), progressOutput, size, pd.ID(), "Pushing")
|
||||
defer reader.Close()
|
||||
compressedReader := compress(reader)
|
||||
compressedReader, compressionDone := compress(reader)
|
||||
defer func() {
|
||||
reader.Close()
|
||||
<-compressionDone
|
||||
}()
|
||||
|
||||
digester := digest.Canonical.New()
|
||||
tee := io.TeeReader(compressedReader, digester.Hash())
|
||||
|
75
vendor/github.com/docker/docker/distribution/xfer/transfer.go
generated
vendored
75
vendor/github.com/docker/docker/distribution/xfer/transfer.go
generated
vendored
@@ -1,6 +1,7 @@
|
||||
package xfer
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
"github.com/docker/docker/pkg/progress"
|
||||
@@ -38,7 +39,7 @@ type Transfer interface {
|
||||
Watch(progressOutput progress.Output) *Watcher
|
||||
Release(*Watcher)
|
||||
Context() context.Context
|
||||
Cancel()
|
||||
Close()
|
||||
Done() <-chan struct{}
|
||||
Released() <-chan struct{}
|
||||
Broadcast(masterProgressChan <-chan progress.Progress)
|
||||
@@ -61,11 +62,14 @@ type transfer struct {
|
||||
|
||||
// running remains open as long as the transfer is in progress.
|
||||
running chan struct{}
|
||||
// hasWatchers stays open until all watchers release the transfer.
|
||||
hasWatchers chan struct{}
|
||||
// released stays open until all watchers release the transfer and
|
||||
// the transfer is no longer tracked by the transfer manager.
|
||||
released chan struct{}
|
||||
|
||||
// broadcastDone is true if the master progress channel has closed.
|
||||
broadcastDone bool
|
||||
// closed is true if Close has been called
|
||||
closed bool
|
||||
// broadcastSyncChan allows watchers to "ping" the broadcasting
|
||||
// goroutine to wait for it for deplete its input channel. This ensures
|
||||
// a detaching watcher won't miss an event that was sent before it
|
||||
@@ -78,7 +82,7 @@ func NewTransfer() Transfer {
|
||||
t := &transfer{
|
||||
watchers: make(map[chan struct{}]*Watcher),
|
||||
running: make(chan struct{}),
|
||||
hasWatchers: make(chan struct{}),
|
||||
released: make(chan struct{}),
|
||||
broadcastSyncChan: make(chan struct{}),
|
||||
}
|
||||
|
||||
@@ -144,13 +148,13 @@ func (t *transfer) Watch(progressOutput progress.Output) *Watcher {
|
||||
running: make(chan struct{}),
|
||||
}
|
||||
|
||||
t.watchers[w.releaseChan] = w
|
||||
|
||||
if t.broadcastDone {
|
||||
close(w.running)
|
||||
return w
|
||||
}
|
||||
|
||||
t.watchers[w.releaseChan] = w
|
||||
|
||||
go func() {
|
||||
defer func() {
|
||||
close(w.running)
|
||||
@@ -202,8 +206,19 @@ func (t *transfer) Release(watcher *Watcher) {
|
||||
delete(t.watchers, watcher.releaseChan)
|
||||
|
||||
if len(t.watchers) == 0 {
|
||||
close(t.hasWatchers)
|
||||
t.cancel()
|
||||
if t.closed {
|
||||
// released may have been closed already if all
|
||||
// watchers were released, then another one was added
|
||||
// while waiting for a previous watcher goroutine to
|
||||
// finish.
|
||||
select {
|
||||
case <-t.released:
|
||||
default:
|
||||
close(t.released)
|
||||
}
|
||||
} else {
|
||||
t.cancel()
|
||||
}
|
||||
}
|
||||
t.mu.Unlock()
|
||||
|
||||
@@ -223,9 +238,9 @@ func (t *transfer) Done() <-chan struct{} {
|
||||
}
|
||||
|
||||
// Released returns a channel which is closed once all watchers release the
|
||||
// transfer.
|
||||
// transfer AND the transfer is no longer tracked by the transfer manager.
|
||||
func (t *transfer) Released() <-chan struct{} {
|
||||
return t.hasWatchers
|
||||
return t.released
|
||||
}
|
||||
|
||||
// Context returns the context associated with the transfer.
|
||||
@@ -233,9 +248,15 @@ func (t *transfer) Context() context.Context {
|
||||
return t.ctx
|
||||
}
|
||||
|
||||
// Cancel cancels the context associated with the transfer.
|
||||
func (t *transfer) Cancel() {
|
||||
t.cancel()
|
||||
// Close is called by the transfer manager when the transfer is no longer
|
||||
// being tracked.
|
||||
func (t *transfer) Close() {
|
||||
t.mu.Lock()
|
||||
t.closed = true
|
||||
if len(t.watchers) == 0 {
|
||||
close(t.released)
|
||||
}
|
||||
t.mu.Unlock()
|
||||
}
|
||||
|
||||
// DoFunc is a function called by the transfer manager to actually perform
|
||||
@@ -280,10 +301,33 @@ func (tm *transferManager) Transfer(key string, xferFunc DoFunc, progressOutput
|
||||
tm.mu.Lock()
|
||||
defer tm.mu.Unlock()
|
||||
|
||||
if xfer, present := tm.transfers[key]; present {
|
||||
for {
|
||||
xfer, present := tm.transfers[key]
|
||||
if !present {
|
||||
break
|
||||
}
|
||||
// Transfer is already in progress.
|
||||
watcher := xfer.Watch(progressOutput)
|
||||
return xfer, watcher
|
||||
|
||||
select {
|
||||
case <-xfer.Context().Done():
|
||||
// We don't want to watch a transfer that has been cancelled.
|
||||
// Wait for it to be removed from the map and try again.
|
||||
xfer.Release(watcher)
|
||||
tm.mu.Unlock()
|
||||
// The goroutine that removes this transfer from the
|
||||
// map is also waiting for xfer.Done(), so yield to it.
|
||||
// This could be avoided by adding a Closed method
|
||||
// to Transfer to allow explicitly waiting for it to be
|
||||
// removed the map, but forcing a scheduling round in
|
||||
// this very rare case seems better than bloating the
|
||||
// interface definition.
|
||||
runtime.Gosched()
|
||||
<-xfer.Done()
|
||||
tm.mu.Lock()
|
||||
default:
|
||||
return xfer, watcher
|
||||
}
|
||||
}
|
||||
|
||||
start := make(chan struct{})
|
||||
@@ -318,6 +362,7 @@ func (tm *transferManager) Transfer(key string, xferFunc DoFunc, progressOutput
|
||||
}
|
||||
delete(tm.transfers, key)
|
||||
tm.mu.Unlock()
|
||||
xfer.Close()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
3
vendor/github.com/docker/docker/image/store.go
generated
vendored
3
vendor/github.com/docker/docker/image/store.go
generated
vendored
@@ -231,6 +231,9 @@ func (is *store) SetParent(id, parent ID) error {
|
||||
if parentMeta == nil {
|
||||
return fmt.Errorf("unknown parent image ID %s", parent.String())
|
||||
}
|
||||
if parent, err := is.GetParent(id); err == nil && is.images[parent] != nil {
|
||||
delete(is.images[parent].children, id)
|
||||
}
|
||||
parentMeta.children[id] = struct{}{}
|
||||
return is.fs.SetMetadata(id, "parent", []byte(parent))
|
||||
}
|
||||
|
2
vendor/github.com/docker/docker/layer/migration.go
generated
vendored
2
vendor/github.com/docker/docker/layer/migration.go
generated
vendored
@@ -32,7 +32,7 @@ func (ls *layerStore) CreateRWLayerByGraphID(name string, graphID string, parent
|
||||
}
|
||||
|
||||
if !ls.driver.Exists(graphID) {
|
||||
return errors.New("graph ID does not exist")
|
||||
return fmt.Errorf("graph ID does not exist: %q", graphID)
|
||||
}
|
||||
|
||||
var p *roLayer
|
||||
|
49
vendor/github.com/docker/docker/layer/ro_layer.go
generated
vendored
49
vendor/github.com/docker/docker/layer/ro_layer.go
generated
vendored
@@ -1,6 +1,11 @@
|
||||
package layer
|
||||
|
||||
import "io"
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/docker/distribution/digest"
|
||||
)
|
||||
|
||||
type roLayer struct {
|
||||
chainID ChainID
|
||||
@@ -29,7 +34,11 @@ func (rl *roLayer) TarStream() (io.ReadCloser, error) {
|
||||
pw.Close()
|
||||
}
|
||||
}()
|
||||
return pr, nil
|
||||
rc, err := newVerifiedReadCloser(pr, digest.Digest(rl.diffID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rc, nil
|
||||
}
|
||||
|
||||
func (rl *roLayer) ChainID() ChainID {
|
||||
@@ -117,3 +126,39 @@ func storeLayer(tx MetadataTransaction, layer *roLayer) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func newVerifiedReadCloser(rc io.ReadCloser, dgst digest.Digest) (io.ReadCloser, error) {
|
||||
verifier, err := digest.NewDigestVerifier(dgst)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &verifiedReadCloser{
|
||||
rc: rc,
|
||||
dgst: dgst,
|
||||
verifier: verifier,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type verifiedReadCloser struct {
|
||||
rc io.ReadCloser
|
||||
dgst digest.Digest
|
||||
verifier digest.Verifier
|
||||
}
|
||||
|
||||
func (vrc *verifiedReadCloser) Read(p []byte) (n int, err error) {
|
||||
n, err = vrc.rc.Read(p)
|
||||
if n > 0 {
|
||||
if n, err := vrc.verifier.Write(p[:n]); err != nil {
|
||||
return n, err
|
||||
}
|
||||
}
|
||||
if err == io.EOF {
|
||||
if !vrc.verifier.Verified() {
|
||||
err = fmt.Errorf("could not verify layer data for: %s. This may be because internal files in the layer store were modified. Re-pulling or rebuilding this image may resolve the issue", vrc.dgst)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
func (vrc *verifiedReadCloser) Close() error {
|
||||
return vrc.rc.Close()
|
||||
}
|
||||
|
2
vendor/github.com/docker/docker/pkg/mflag/flag.go
generated
vendored
2
vendor/github.com/docker/docker/pkg/mflag/flag.go
generated
vendored
@@ -1163,7 +1163,7 @@ func (fs *FlagSet) ReportError(str string, withHelp bool) {
|
||||
str += ".\nSee '" + os.Args[0] + " " + fs.Name() + " --help'"
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(fs.Out(), "%s: %s.\n", os.Args[0], str)
|
||||
fmt.Fprintf(fs.Out(), "docker: %s.\n", str)
|
||||
}
|
||||
|
||||
// Parsed reports whether fs.Parse has been called.
|
||||
|
204
vendor/github.com/docker/docker/pkg/term/term_windows.go
generated
vendored
204
vendor/github.com/docker/docker/pkg/term/term_windows.go
generated
vendored
@@ -3,20 +3,21 @@
|
||||
package term
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/Azure/go-ansiterm/winterm"
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/pkg/system"
|
||||
"github.com/docker/docker/pkg/term/windows"
|
||||
)
|
||||
|
||||
// State holds the console mode for the terminal.
|
||||
type State struct {
|
||||
inMode, outMode uint32
|
||||
inHandle, outHandle syscall.Handle
|
||||
mode uint32
|
||||
}
|
||||
|
||||
// Winsize is used for window size.
|
||||
@@ -27,27 +28,17 @@ type Winsize struct {
|
||||
y uint16
|
||||
}
|
||||
|
||||
const (
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms683167(v=vs.85).aspx
|
||||
enableVirtualTerminalInput = 0x0200
|
||||
enableVirtualTerminalProcessing = 0x0004
|
||||
)
|
||||
|
||||
// usingNativeConsole is true if we are using the Windows native console
|
||||
var usingNativeConsole bool
|
||||
|
||||
// StdStreams returns the standard streams (stdin, stdout, stedrr).
|
||||
func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
|
||||
switch {
|
||||
case os.Getenv("ConEmuANSI") == "ON":
|
||||
// The ConEmu shell emulates ANSI well by default.
|
||||
return os.Stdin, os.Stdout, os.Stderr
|
||||
// The ConEmu terminal emulates ANSI on output streams well.
|
||||
return windows.ConEmuStreams()
|
||||
case os.Getenv("MSYSTEM") != "":
|
||||
// MSYS (mingw) does not emulate ANSI well.
|
||||
return windows.ConsoleStreams()
|
||||
default:
|
||||
if useNativeConsole() {
|
||||
usingNativeConsole = true
|
||||
return os.Stdin, os.Stdout, os.Stderr
|
||||
}
|
||||
return windows.ConsoleStreams()
|
||||
@@ -63,7 +54,7 @@ func useNativeConsole() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Native console is not available before major version 10
|
||||
// Native console is not available major version 10
|
||||
if osv.MajorVersion < 10 {
|
||||
return false
|
||||
}
|
||||
@@ -73,17 +64,6 @@ func useNativeConsole() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Get the console modes. If this fails, we can't use the native console
|
||||
state, err := getNativeConsole()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// Probe the console to see if it can be enabled.
|
||||
if nil != probeNativeConsole(state) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Environment variable override
|
||||
if e := os.Getenv("USE_NATIVE_CONSOLE"); e != "" {
|
||||
if e == "1" {
|
||||
@@ -92,86 +72,32 @@ func useNativeConsole() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// TODO Windows. The native emulator still has issues which
|
||||
// Get the handle to stdout
|
||||
stdOutHandle, err := syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// Get the console mode from the consoles stdout handle
|
||||
var mode uint32
|
||||
if err := syscall.GetConsoleMode(stdOutHandle, &mode); err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// Legacy mode does not have native ANSI emulation.
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms683167(v=vs.85).aspx
|
||||
const enableVirtualTerminalProcessing = 0x0004
|
||||
if mode&enableVirtualTerminalProcessing == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
// TODO Windows (Post TP4). The native emulator still has issues which
|
||||
// mean it shouldn't be enabled for everyone. Change this next line to true
|
||||
// to change the default to "enable if available". In the meantime, users
|
||||
// can still try it out by using USE_NATIVE_CONSOLE env variable.
|
||||
return false
|
||||
}
|
||||
|
||||
// getNativeConsole returns the console modes ('state') for the native Windows console
|
||||
func getNativeConsole() (State, error) {
|
||||
var (
|
||||
err error
|
||||
state State
|
||||
)
|
||||
|
||||
// Get the handle to stdout
|
||||
if state.outHandle, err = syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE); err != nil {
|
||||
return state, err
|
||||
}
|
||||
|
||||
// Get the console mode from the consoles stdout handle
|
||||
if err = syscall.GetConsoleMode(state.outHandle, &state.outMode); err != nil {
|
||||
return state, err
|
||||
}
|
||||
|
||||
// Get the handle to stdin
|
||||
if state.inHandle, err = syscall.GetStdHandle(syscall.STD_INPUT_HANDLE); err != nil {
|
||||
return state, err
|
||||
}
|
||||
|
||||
// Get the console mode from the consoles stdin handle
|
||||
if err = syscall.GetConsoleMode(state.inHandle, &state.inMode); err != nil {
|
||||
return state, err
|
||||
}
|
||||
|
||||
return state, nil
|
||||
}
|
||||
|
||||
// probeNativeConsole probes the console to determine if native can be supported,
|
||||
func probeNativeConsole(state State) error {
|
||||
if err := winterm.SetConsoleMode(uintptr(state.outHandle), state.outMode|enableVirtualTerminalProcessing); err != nil {
|
||||
return err
|
||||
}
|
||||
defer winterm.SetConsoleMode(uintptr(state.outHandle), state.outMode)
|
||||
|
||||
if err := winterm.SetConsoleMode(uintptr(state.inHandle), state.inMode|enableVirtualTerminalInput); err != nil {
|
||||
return err
|
||||
}
|
||||
defer winterm.SetConsoleMode(uintptr(state.inHandle), state.inMode)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// enableNativeConsole turns on native console mode
|
||||
func enableNativeConsole(state State) error {
|
||||
if err := winterm.SetConsoleMode(uintptr(state.outHandle), state.outMode|enableVirtualTerminalProcessing); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := winterm.SetConsoleMode(uintptr(state.inHandle), state.inMode|enableVirtualTerminalInput); err != nil {
|
||||
winterm.SetConsoleMode(uintptr(state.outHandle), state.outMode) // restore out if we can
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// disableNativeConsole turns off native console mode
|
||||
func disableNativeConsole(state *State) error {
|
||||
// Try and restore both in an out before error checking.
|
||||
errout := winterm.SetConsoleMode(uintptr(state.outHandle), state.outMode)
|
||||
errin := winterm.SetConsoleMode(uintptr(state.inHandle), state.inMode)
|
||||
if errout != nil {
|
||||
return errout
|
||||
}
|
||||
if errin != nil {
|
||||
return errin
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetFdInfo returns the file descriptor for an os.File and indicates whether the file represents a terminal.
|
||||
func GetFdInfo(in interface{}) (uintptr, bool) {
|
||||
return windows.GetHandleInfo(in)
|
||||
@@ -179,6 +105,7 @@ func GetFdInfo(in interface{}) (uintptr, bool) {
|
||||
|
||||
// GetWinsize returns the window size based on the specified file descriptor.
|
||||
func GetWinsize(fd uintptr) (*Winsize, error) {
|
||||
|
||||
info, err := winterm.GetConsoleScreenBufferInfo(fd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -190,9 +117,58 @@ func GetWinsize(fd uintptr) (*Winsize, error) {
|
||||
x: 0,
|
||||
y: 0}
|
||||
|
||||
// Note: GetWinsize is called frequently -- uncomment only for excessive details
|
||||
// logrus.Debugf("[windows] GetWinsize: Console(%v)", info.String())
|
||||
// logrus.Debugf("[windows] GetWinsize: Width(%v), Height(%v), x(%v), y(%v)", winsize.Width, winsize.Height, winsize.x, winsize.y)
|
||||
return winsize, nil
|
||||
}
|
||||
|
||||
// SetWinsize tries to set the specified window size for the specified file descriptor.
|
||||
func SetWinsize(fd uintptr, ws *Winsize) error {
|
||||
|
||||
// Ensure the requested dimensions are no larger than the maximum window size
|
||||
info, err := winterm.GetConsoleScreenBufferInfo(fd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if ws.Width == 0 || ws.Height == 0 || ws.Width > uint16(info.MaximumWindowSize.X) || ws.Height > uint16(info.MaximumWindowSize.Y) {
|
||||
return fmt.Errorf("Illegal window size: (%v,%v) -- Maximum allow: (%v,%v)",
|
||||
ws.Width, ws.Height, info.MaximumWindowSize.X, info.MaximumWindowSize.Y)
|
||||
}
|
||||
|
||||
// Narrow the sizes to that used by Windows
|
||||
width := winterm.SHORT(ws.Width)
|
||||
height := winterm.SHORT(ws.Height)
|
||||
|
||||
// Set the dimensions while ensuring they remain within the bounds of the backing console buffer
|
||||
// -- Shrinking will always succeed. Growing may push the edges past the buffer boundary. When that occurs,
|
||||
// shift the upper left just enough to keep the new window within the buffer.
|
||||
rect := info.Window
|
||||
if width < rect.Right-rect.Left+1 {
|
||||
rect.Right = rect.Left + width - 1
|
||||
} else if width > rect.Right-rect.Left+1 {
|
||||
rect.Right = rect.Left + width - 1
|
||||
if rect.Right >= info.Size.X {
|
||||
rect.Left = info.Size.X - width
|
||||
rect.Right = info.Size.X - 1
|
||||
}
|
||||
}
|
||||
|
||||
if height < rect.Bottom-rect.Top+1 {
|
||||
rect.Bottom = rect.Top + height - 1
|
||||
} else if height > rect.Bottom-rect.Top+1 {
|
||||
rect.Bottom = rect.Top + height - 1
|
||||
if rect.Bottom >= info.Size.Y {
|
||||
rect.Top = info.Size.Y - height
|
||||
rect.Bottom = info.Size.Y - 1
|
||||
}
|
||||
}
|
||||
logrus.Debugf("[windows] SetWinsize: Requested((%v,%v)) Actual(%v)", ws.Width, ws.Height, rect)
|
||||
|
||||
return winterm.SetConsoleWindowInfo(fd, true, rect)
|
||||
}
|
||||
|
||||
// IsTerminal returns true if the given file descriptor is a terminal.
|
||||
func IsTerminal(fd uintptr) bool {
|
||||
return windows.IsConsole(fd)
|
||||
@@ -201,36 +177,25 @@ func IsTerminal(fd uintptr) bool {
|
||||
// RestoreTerminal restores the terminal connected to the given file descriptor
|
||||
// to a previous state.
|
||||
func RestoreTerminal(fd uintptr, state *State) error {
|
||||
if usingNativeConsole {
|
||||
return disableNativeConsole(state)
|
||||
}
|
||||
return winterm.SetConsoleMode(fd, state.outMode)
|
||||
return winterm.SetConsoleMode(fd, state.mode)
|
||||
}
|
||||
|
||||
// SaveState saves the state of the terminal connected to the given file descriptor.
|
||||
func SaveState(fd uintptr) (*State, error) {
|
||||
if usingNativeConsole {
|
||||
state, err := getNativeConsole()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &state, nil
|
||||
}
|
||||
|
||||
mode, e := winterm.GetConsoleMode(fd)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
|
||||
return &State{outMode: mode}, nil
|
||||
return &State{mode}, nil
|
||||
}
|
||||
|
||||
// DisableEcho disables echo for the terminal connected to the given file descriptor.
|
||||
// -- See https://msdn.microsoft.com/en-us/library/windows/desktop/ms683462(v=vs.85).aspx
|
||||
func DisableEcho(fd uintptr, state *State) error {
|
||||
mode := state.inMode
|
||||
mode := state.mode
|
||||
mode &^= winterm.ENABLE_ECHO_INPUT
|
||||
mode |= winterm.ENABLE_PROCESSED_INPUT | winterm.ENABLE_LINE_INPUT
|
||||
|
||||
err := winterm.SetConsoleMode(fd, mode)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -262,17 +227,10 @@ func MakeRaw(fd uintptr) (*State, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mode := state.inMode
|
||||
if usingNativeConsole {
|
||||
if err := enableNativeConsole(*state); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mode |= enableVirtualTerminalInput
|
||||
}
|
||||
|
||||
// See
|
||||
// -- https://msdn.microsoft.com/en-us/library/windows/desktop/ms686033(v=vs.85).aspx
|
||||
// -- https://msdn.microsoft.com/en-us/library/windows/desktop/ms683462(v=vs.85).aspx
|
||||
mode := state.mode
|
||||
|
||||
// Disable these modes
|
||||
mode &^= winterm.ENABLE_ECHO_INPUT
|
||||
|
17
vendor/github.com/docker/docker/reference/reference.go
generated
vendored
17
vendor/github.com/docker/docker/reference/reference.go
generated
vendored
@@ -1,6 +1,7 @@
|
||||
package reference
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@@ -72,7 +73,10 @@ func ParseNamed(s string) (Named, error) {
|
||||
// WithName returns a named object representing the given string. If the input
|
||||
// is invalid ErrReferenceInvalidFormat will be returned.
|
||||
func WithName(name string) (Named, error) {
|
||||
name = normalize(name)
|
||||
name, err := normalize(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := validateName(name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -172,15 +176,18 @@ func splitHostname(name string) (hostname, remoteName string) {
|
||||
|
||||
// normalize returns a repository name in its normalized form, meaning it
|
||||
// will not contain default hostname nor library/ prefix for official images.
|
||||
func normalize(name string) string {
|
||||
func normalize(name string) (string, error) {
|
||||
host, remoteName := splitHostname(name)
|
||||
if strings.ToLower(remoteName) != remoteName {
|
||||
return "", errors.New("invalid reference format: repository name must be lowercase")
|
||||
}
|
||||
if host == DefaultHostname {
|
||||
if strings.HasPrefix(remoteName, DefaultRepoPrefix) {
|
||||
return strings.TrimPrefix(remoteName, DefaultRepoPrefix)
|
||||
return strings.TrimPrefix(remoteName, DefaultRepoPrefix), nil
|
||||
}
|
||||
return remoteName
|
||||
return remoteName, nil
|
||||
}
|
||||
return name
|
||||
return name, nil
|
||||
}
|
||||
|
||||
func validateName(name string) error {
|
||||
|
1
vendor/github.com/docker/docker/registry/registry.go
generated
vendored
1
vendor/github.com/docker/docker/registry/registry.go
generated
vendored
@@ -31,7 +31,6 @@ var (
|
||||
// ErrAlreadyExists is an error returned if an image being pushed
|
||||
// already exists on the remote side
|
||||
ErrAlreadyExists = errors.New("Image already exists")
|
||||
errLoginRequired = errors.New("Authentication is required.")
|
||||
)
|
||||
|
||||
// dockerUserAgent is the User-Agent the Docker client uses to identify itself.
|
||||
|
7
vendor/github.com/docker/docker/registry/session.go
generated
vendored
7
vendor/github.com/docker/docker/registry/session.go
generated
vendored
@@ -19,6 +19,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/distribution/registry/api/errcode"
|
||||
"github.com/docker/docker/pkg/httputils"
|
||||
"github.com/docker/docker/pkg/ioutils"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
@@ -213,7 +214,7 @@ func (r *Session) GetRemoteHistory(imgID, registry string) ([]string, error) {
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != 200 {
|
||||
if res.StatusCode == 401 {
|
||||
return nil, errLoginRequired
|
||||
return nil, errcode.ErrorCodeUnauthorized.WithArgs()
|
||||
}
|
||||
return nil, httputils.NewHTTPRequestError(fmt.Sprintf("Server error: %d trying to fetch remote history for %s", res.StatusCode, imgID), res)
|
||||
}
|
||||
@@ -427,7 +428,7 @@ func (r *Session) GetRepositoryData(name reference.Named) (*RepositoryData, erro
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode == 401 {
|
||||
return nil, errLoginRequired
|
||||
return nil, errcode.ErrorCodeUnauthorized.WithArgs()
|
||||
}
|
||||
// TODO: Right now we're ignoring checksums in the response body.
|
||||
// In the future, we need to use them to check image validity.
|
||||
@@ -661,7 +662,7 @@ func (r *Session) PushImageJSONIndex(remote reference.Named, imgList []*ImgData,
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode == 401 {
|
||||
return nil, errLoginRequired
|
||||
return nil, errcode.ErrorCodeUnauthorized.WithArgs()
|
||||
}
|
||||
|
||||
var tokens, endpoints []string
|
||||
|
3
vendor/github.com/docker/engine-api/types/client.go
generated
vendored
3
vendor/github.com/docker/engine-api/types/client.go
generated
vendored
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
"github.com/docker/engine-api/types/container"
|
||||
"github.com/docker/engine-api/types/filters"
|
||||
"github.com/docker/engine-api/types/image"
|
||||
"github.com/docker/go-units"
|
||||
)
|
||||
|
||||
@@ -127,7 +126,7 @@ type ImageBuildOptions struct {
|
||||
NoCache bool
|
||||
Remove bool
|
||||
ForceRemove bool
|
||||
PullParent image.PullBehavior
|
||||
PullParent bool
|
||||
IsolationLevel container.IsolationLevel
|
||||
CPUSetCPUs string
|
||||
CPUSetMems string
|
||||
|
8
vendor/github.com/docker/engine-api/types/container/host_config.go
generated
vendored
8
vendor/github.com/docker/engine-api/types/container/host_config.go
generated
vendored
@@ -151,11 +151,6 @@ func (rp *RestartPolicy) IsUnlessStopped() bool {
|
||||
return rp.Name == "unless-stopped"
|
||||
}
|
||||
|
||||
// IsSame compares two RestartPolicy to see if they are the same
|
||||
func (rp *RestartPolicy) IsSame(tp *RestartPolicy) bool {
|
||||
return rp.Name == tp.Name && rp.MaximumRetryCount == tp.MaximumRetryCount
|
||||
}
|
||||
|
||||
// LogConfig represents the logging configuration of the container.
|
||||
type LogConfig struct {
|
||||
Type string
|
||||
@@ -183,7 +178,7 @@ type Resources struct {
|
||||
KernelMemory int64 // Kernel memory limit (in bytes)
|
||||
Memory int64 // Memory limit (in bytes)
|
||||
MemoryReservation int64 // Memory soft limit (in bytes)
|
||||
MemorySwap int64 // Total memory usage (memory + swap); set `-1` to enable unlimited swap
|
||||
MemorySwap int64 // Total memory usage (memory + swap); set `-1` to disable swap
|
||||
MemorySwappiness *int64 // Tuning container memory swappiness behaviour
|
||||
OomKillDisable *bool // Whether to disable OOM Killer or not
|
||||
PidsLimit int64 // Setting pids limit for a container
|
||||
@@ -195,7 +190,6 @@ type Resources struct {
|
||||
type UpdateConfig struct {
|
||||
// Contains container's resources (cgroups, ulimits)
|
||||
Resources
|
||||
RestartPolicy RestartPolicy
|
||||
}
|
||||
|
||||
// HostConfig the non-portable Config structure of a container.
|
||||
|
41
vendor/github.com/docker/engine-api/types/image/pull_behavior.go
generated
vendored
41
vendor/github.com/docker/engine-api/types/image/pull_behavior.go
generated
vendored
@@ -1,41 +0,0 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// PullBehavior can be one of: never, always, or missing
|
||||
type PullBehavior int
|
||||
|
||||
// PullBehavior can be one of: never, always, or missing
|
||||
const (
|
||||
PullNever PullBehavior = iota
|
||||
PullAlways
|
||||
PullMissing
|
||||
)
|
||||
|
||||
// ParsePullBehavior validates and converts a string into a PullBehavior
|
||||
func ParsePullBehavior(pullVal string) (PullBehavior, error) {
|
||||
switch pullVal {
|
||||
case "never":
|
||||
return PullNever, nil
|
||||
case "always":
|
||||
return PullAlways, nil
|
||||
case "missing", "":
|
||||
return PullMissing, nil
|
||||
}
|
||||
return PullNever, fmt.Errorf("Invalid pull behavior '%s'", pullVal)
|
||||
}
|
||||
|
||||
// String returns a string representation of a PullBehavior
|
||||
func (p PullBehavior) String() string {
|
||||
switch p {
|
||||
case PullNever:
|
||||
return "never"
|
||||
case PullAlways:
|
||||
return "always"
|
||||
case PullMissing:
|
||||
return "missing"
|
||||
}
|
||||
return ""
|
||||
}
|
4
vendor/github.com/docker/engine-api/types/types.go
generated
vendored
4
vendor/github.com/docker/engine-api/types/types.go
generated
vendored
@@ -142,7 +142,6 @@ type Container struct {
|
||||
SizeRw int64 `json:",omitempty"`
|
||||
SizeRootFs int64 `json:",omitempty"`
|
||||
Labels map[string]string
|
||||
State string
|
||||
Status string
|
||||
HostConfig struct {
|
||||
NetworkMode string `json:",omitempty"`
|
||||
@@ -224,6 +223,8 @@ type Info struct {
|
||||
Architecture string
|
||||
IndexServerAddress string
|
||||
RegistryConfig *registry.ServiceConfig
|
||||
InitSha1 string
|
||||
InitPath string
|
||||
NCPU int
|
||||
MemTotal int64
|
||||
DockerRootDir string
|
||||
@@ -388,7 +389,6 @@ type NetworkResource struct {
|
||||
Scope string
|
||||
Driver string
|
||||
IPAM network.IPAM
|
||||
Internal bool
|
||||
Containers map[string]EndpointResource
|
||||
Options map[string]string
|
||||
}
|
||||
|
4
vendor/github.com/docker/go-connections/tlsconfig/config.go
generated
vendored
4
vendor/github.com/docker/go-connections/tlsconfig/config.go
generated
vendored
@@ -85,7 +85,7 @@ func certPool(caFile string) (*x509.CertPool, error) {
|
||||
func Client(options Options) (*tls.Config, error) {
|
||||
tlsConfig := ClientDefault
|
||||
tlsConfig.InsecureSkipVerify = options.InsecureSkipVerify
|
||||
if !options.InsecureSkipVerify {
|
||||
if !options.InsecureSkipVerify && options.CAFile != "" {
|
||||
CAs, err := certPool(options.CAFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -93,7 +93,7 @@ func Client(options Options) (*tls.Config, error) {
|
||||
tlsConfig.RootCAs = CAs
|
||||
}
|
||||
|
||||
if options.CertFile != "" && options.KeyFile != "" {
|
||||
if options.CertFile != "" || options.KeyFile != "" {
|
||||
tlsCert, err := tls.LoadX509KeyPair(options.CertFile, options.KeyFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Could not load X509 key pair: %v. Make sure the key is not encrypted", err)
|
||||
|
12
vendor/github.com/docker/go-units/size.go
generated
vendored
12
vendor/github.com/docker/go-units/size.go
generated
vendored
@@ -31,7 +31,7 @@ type unitMap map[string]int64
|
||||
var (
|
||||
decimalMap = unitMap{"k": KB, "m": MB, "g": GB, "t": TB, "p": PB}
|
||||
binaryMap = unitMap{"k": KiB, "m": MiB, "g": GiB, "t": TiB, "p": PiB}
|
||||
sizeRegex = regexp.MustCompile(`^(\d+)([kKmMgGtTpP])?[bB]?$`)
|
||||
sizeRegex = regexp.MustCompile(`^(\d+(\.\d+)*) ?([kKmMgGtTpP])?[bB]?$`)
|
||||
)
|
||||
|
||||
var decimapAbbrs = []string{"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}
|
||||
@@ -77,19 +77,19 @@ func RAMInBytes(size string) (int64, error) {
|
||||
// Parses the human-readable size string into the amount it represents.
|
||||
func parseSize(sizeStr string, uMap unitMap) (int64, error) {
|
||||
matches := sizeRegex.FindStringSubmatch(sizeStr)
|
||||
if len(matches) != 3 {
|
||||
if len(matches) != 4 {
|
||||
return -1, fmt.Errorf("invalid size: '%s'", sizeStr)
|
||||
}
|
||||
|
||||
size, err := strconv.ParseInt(matches[1], 10, 0)
|
||||
size, err := strconv.ParseFloat(matches[1], 64)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
|
||||
unitPrefix := strings.ToLower(matches[2])
|
||||
unitPrefix := strings.ToLower(matches[3])
|
||||
if mul, ok := uMap[unitPrefix]; ok {
|
||||
size *= mul
|
||||
size *= float64(mul)
|
||||
}
|
||||
|
||||
return size, nil
|
||||
return int64(size), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user