mirror of https://github.com/docker/cli.git
vendor: github.com/docker/docker v24.0.0-rc.1.0.20230505222407-8d9a40a82034
This will be v24.0.0-rc.2 full diff: https://github.com/docker/docker/compare/v24.0.0-rc.1...8d9a40a820349860405e142249c55215aa4da8e3 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
0428418d6b
commit
4f97f55999
|
@ -3,7 +3,6 @@ package container
|
||||||
import (
|
import (
|
||||||
"github.com/docker/cli/cli/command/formatter"
|
"github.com/docker/cli/cli/command/formatter"
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/pkg/archive"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -23,7 +22,7 @@ func NewDiffFormat(source string) formatter.Format {
|
||||||
}
|
}
|
||||||
|
|
||||||
// DiffFormatWrite writes formatted diff using the Context
|
// DiffFormatWrite writes formatted diff using the Context
|
||||||
func DiffFormatWrite(ctx formatter.Context, changes []container.ContainerChangeResponseItem) error {
|
func DiffFormatWrite(ctx formatter.Context, changes []container.FilesystemChange) error {
|
||||||
render := func(format func(subContext formatter.SubContext) error) error {
|
render := func(format func(subContext formatter.SubContext) error) error {
|
||||||
for _, change := range changes {
|
for _, change := range changes {
|
||||||
if err := format(&diffContext{c: change}); err != nil {
|
if err := format(&diffContext{c: change}); err != nil {
|
||||||
|
@ -37,7 +36,7 @@ func DiffFormatWrite(ctx formatter.Context, changes []container.ContainerChangeR
|
||||||
|
|
||||||
type diffContext struct {
|
type diffContext struct {
|
||||||
formatter.HeaderContext
|
formatter.HeaderContext
|
||||||
c container.ContainerChangeResponseItem
|
c container.FilesystemChange
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDiffContext() *diffContext {
|
func newDiffContext() *diffContext {
|
||||||
|
@ -54,16 +53,7 @@ func (d *diffContext) MarshalJSON() ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *diffContext) Type() string {
|
func (d *diffContext) Type() string {
|
||||||
var kind string
|
return d.c.Kind.String()
|
||||||
switch d.c.Kind {
|
|
||||||
case archive.ChangeModify:
|
|
||||||
kind = "C"
|
|
||||||
case archive.ChangeAdd:
|
|
||||||
kind = "A"
|
|
||||||
case archive.ChangeDelete:
|
|
||||||
kind = "D"
|
|
||||||
}
|
|
||||||
return kind
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *diffContext) Path() string {
|
func (d *diffContext) Path() string {
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
|
|
||||||
"github.com/docker/cli/cli/command/formatter"
|
"github.com/docker/cli/cli/command/formatter"
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/pkg/archive"
|
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -41,10 +40,10 @@ D: /usr/app/old_app.js
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
diffs := []container.ContainerChangeResponseItem{
|
diffs := []container.FilesystemChange{
|
||||||
{Kind: archive.ChangeModify, Path: "/var/log/app.log"},
|
{Kind: container.ChangeModify, Path: "/var/log/app.log"},
|
||||||
{Kind: archive.ChangeAdd, Path: "/usr/app/app.js"},
|
{Kind: container.ChangeAdd, Path: "/usr/app/app.js"},
|
||||||
{Kind: archive.ChangeDelete, Path: "/usr/app/old_app.js"},
|
{Kind: container.ChangeDelete, Path: "/usr/app/old_app.js"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
|
|
|
@ -10,7 +10,7 @@ require (
|
||||||
github.com/containerd/containerd v1.6.21
|
github.com/containerd/containerd v1.6.21
|
||||||
github.com/creack/pty v1.1.18
|
github.com/creack/pty v1.1.18
|
||||||
github.com/docker/distribution v2.8.1+incompatible
|
github.com/docker/distribution v2.8.1+incompatible
|
||||||
github.com/docker/docker v24.0.0-rc.1+incompatible
|
github.com/docker/docker v24.0.0-rc.1.0.20230505222407-8d9a40a82034+incompatible
|
||||||
github.com/docker/docker-credential-helpers v0.7.0
|
github.com/docker/docker-credential-helpers v0.7.0
|
||||||
github.com/docker/go-connections v0.4.0
|
github.com/docker/go-connections v0.4.0
|
||||||
github.com/docker/go-units v0.5.0
|
github.com/docker/go-units v0.5.0
|
||||||
|
|
|
@ -96,8 +96,8 @@ github.com/denisenkom/go-mssqldb v0.0.0-20191128021309-1d7a30a10f73/go.mod h1:xb
|
||||||
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
|
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
|
||||||
github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68=
|
github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68=
|
||||||
github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
|
github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
|
||||||
github.com/docker/docker v24.0.0-rc.1+incompatible h1:xGLFfUFQ0mu4I22mzVJqGEdbWkdqDwIdloBIdr0rcJk=
|
github.com/docker/docker v24.0.0-rc.1.0.20230505222407-8d9a40a82034+incompatible h1:Y2oMmZDlVZhIkKzBUCeY48pi8ophHyEAoW04ABKn3DU=
|
||||||
github.com/docker/docker v24.0.0-rc.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
|
github.com/docker/docker v24.0.0-rc.1.0.20230505222407-8d9a40a82034+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
|
||||||
github.com/docker/docker-credential-helpers v0.7.0 h1:xtCHsjxogADNZcdv1pKUHXryefjlVRqWqIhk/uXJp0A=
|
github.com/docker/docker-credential-helpers v0.7.0 h1:xtCHsjxogADNZcdv1pKUHXryefjlVRqWqIhk/uXJp0A=
|
||||||
github.com/docker/docker-credential-helpers v0.7.0/go.mod h1:rETQfLdHNT3foU5kuNkFR1R1V12OJRRO5lzt2D1b5X0=
|
github.com/docker/docker-credential-helpers v0.7.0/go.mod h1:rETQfLdHNT3foU5kuNkFR1R1V12OJRRO5lzt2D1b5X0=
|
||||||
github.com/docker/go v1.5.1-1.0.20160303222718-d30aec9fd63c h1:lzqkGL9b3znc+ZUgi7FlLnqjQhcXxkNM/quxIjBVMD0=
|
github.com/docker/go v1.5.1-1.0.20160303222718-d30aec9fd63c h1:lzqkGL9b3znc+ZUgi7FlLnqjQhcXxkNM/quxIjBVMD0=
|
||||||
|
|
|
@ -976,6 +976,13 @@ definitions:
|
||||||
items:
|
items:
|
||||||
type: "integer"
|
type: "integer"
|
||||||
minimum: 0
|
minimum: 0
|
||||||
|
Annotations:
|
||||||
|
type: "object"
|
||||||
|
description: |
|
||||||
|
Arbitrary non-identifying metadata attached to container and
|
||||||
|
provided to the runtime when the container is started.
|
||||||
|
additionalProperties:
|
||||||
|
type: "string"
|
||||||
|
|
||||||
# Applicable to UNIX platforms
|
# Applicable to UNIX platforms
|
||||||
CapAdd:
|
CapAdd:
|
||||||
|
@ -1122,6 +1129,7 @@ definitions:
|
||||||
remapping option is enabled.
|
remapping option is enabled.
|
||||||
ShmSize:
|
ShmSize:
|
||||||
type: "integer"
|
type: "integer"
|
||||||
|
format: "int64"
|
||||||
description: |
|
description: |
|
||||||
Size of `/dev/shm` in bytes. If omitted, the system uses 64MB.
|
Size of `/dev/shm` in bytes. If omitted, the system uses 64MB.
|
||||||
minimum: 0
|
minimum: 0
|
||||||
|
@ -1610,6 +1618,34 @@ definitions:
|
||||||
"WorkDir": "/var/lib/docker/overlay2/ef749362d13333e65fc95c572eb525abbe0052e16e086cb64bc3b98ae9aa6d74/work"
|
"WorkDir": "/var/lib/docker/overlay2/ef749362d13333e65fc95c572eb525abbe0052e16e086cb64bc3b98ae9aa6d74/work"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FilesystemChange:
|
||||||
|
description: |
|
||||||
|
Change in the container's filesystem.
|
||||||
|
type: "object"
|
||||||
|
required: [Path, Kind]
|
||||||
|
properties:
|
||||||
|
Path:
|
||||||
|
description: |
|
||||||
|
Path to file or directory that has changed.
|
||||||
|
type: "string"
|
||||||
|
x-nullable: false
|
||||||
|
Kind:
|
||||||
|
$ref: "#/definitions/ChangeType"
|
||||||
|
|
||||||
|
ChangeType:
|
||||||
|
description: |
|
||||||
|
Kind of change
|
||||||
|
|
||||||
|
Can be one of:
|
||||||
|
|
||||||
|
- `0`: Modified ("C")
|
||||||
|
- `1`: Added ("A")
|
||||||
|
- `2`: Deleted ("D")
|
||||||
|
type: "integer"
|
||||||
|
format: "uint8"
|
||||||
|
enum: [0, 1, 2]
|
||||||
|
x-nullable: false
|
||||||
|
|
||||||
ImageInspect:
|
ImageInspect:
|
||||||
description: |
|
description: |
|
||||||
Information about an image in the local image cache.
|
Information about an image in the local image cache.
|
||||||
|
@ -6873,9 +6909,9 @@ paths:
|
||||||
Returns which files in a container's filesystem have been added, deleted,
|
Returns which files in a container's filesystem have been added, deleted,
|
||||||
or modified. The `Kind` of modification can be one of:
|
or modified. The `Kind` of modification can be one of:
|
||||||
|
|
||||||
- `0`: Modified
|
- `0`: Modified ("C")
|
||||||
- `1`: Added
|
- `1`: Added ("A")
|
||||||
- `2`: Deleted
|
- `2`: Deleted ("D")
|
||||||
operationId: "ContainerChanges"
|
operationId: "ContainerChanges"
|
||||||
produces: ["application/json"]
|
produces: ["application/json"]
|
||||||
responses:
|
responses:
|
||||||
|
@ -6884,22 +6920,7 @@ paths:
|
||||||
schema:
|
schema:
|
||||||
type: "array"
|
type: "array"
|
||||||
items:
|
items:
|
||||||
type: "object"
|
$ref: "#/definitions/FilesystemChange"
|
||||||
x-go-name: "ContainerChangeResponseItem"
|
|
||||||
title: "ContainerChangeResponseItem"
|
|
||||||
description: "change item in response to ContainerChanges operation"
|
|
||||||
required: [Path, Kind]
|
|
||||||
properties:
|
|
||||||
Path:
|
|
||||||
description: "Path to file that has changed"
|
|
||||||
type: "string"
|
|
||||||
x-nullable: false
|
|
||||||
Kind:
|
|
||||||
description: "Kind of change"
|
|
||||||
type: "integer"
|
|
||||||
format: "uint8"
|
|
||||||
enum: [0, 1, 2]
|
|
||||||
x-nullable: false
|
|
||||||
examples:
|
examples:
|
||||||
application/json:
|
application/json:
|
||||||
- Path: "/dev"
|
- Path: "/dev"
|
||||||
|
|
6
vendor/github.com/docker/docker/api/types/container/change_response_deprecated.go
generated
vendored
Normal file
6
vendor/github.com/docker/docker/api/types/container/change_response_deprecated.go
generated
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
package container
|
||||||
|
|
||||||
|
// ContainerChangeResponseItem change item in response to ContainerChanges operation
|
||||||
|
//
|
||||||
|
// Deprecated: use [FilesystemChange].
|
||||||
|
type ContainerChangeResponseItem = FilesystemChange
|
15
vendor/github.com/docker/docker/api/types/container/change_type.go
generated
vendored
Normal file
15
vendor/github.com/docker/docker/api/types/container/change_type.go
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package container
|
||||||
|
|
||||||
|
// This file was generated by the swagger tool.
|
||||||
|
// Editing this file might prove futile when you re-run the swagger generate command
|
||||||
|
|
||||||
|
// ChangeType Kind of change
|
||||||
|
//
|
||||||
|
// Can be one of:
|
||||||
|
//
|
||||||
|
// - `0`: Modified ("C")
|
||||||
|
// - `1`: Added ("A")
|
||||||
|
// - `2`: Deleted ("D")
|
||||||
|
//
|
||||||
|
// swagger:model ChangeType
|
||||||
|
type ChangeType uint8
|
23
vendor/github.com/docker/docker/api/types/container/change_types.go
generated
vendored
Normal file
23
vendor/github.com/docker/docker/api/types/container/change_types.go
generated
vendored
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
package container
|
||||||
|
|
||||||
|
const (
|
||||||
|
// ChangeModify represents the modify operation.
|
||||||
|
ChangeModify ChangeType = 0
|
||||||
|
// ChangeAdd represents the add operation.
|
||||||
|
ChangeAdd ChangeType = 1
|
||||||
|
// ChangeDelete represents the delete operation.
|
||||||
|
ChangeDelete ChangeType = 2
|
||||||
|
)
|
||||||
|
|
||||||
|
func (ct ChangeType) String() string {
|
||||||
|
switch ct {
|
||||||
|
case ChangeModify:
|
||||||
|
return "C"
|
||||||
|
case ChangeAdd:
|
||||||
|
return "A"
|
||||||
|
case ChangeDelete:
|
||||||
|
return "D"
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,20 +0,0 @@
|
||||||
package container // import "github.com/docker/docker/api/types/container"
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Code generated by `swagger generate operation`. DO NOT EDIT.
|
|
||||||
//
|
|
||||||
// See hack/generate-swagger-api.sh
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// ContainerChangeResponseItem change item in response to ContainerChanges operation
|
|
||||||
// swagger:model ContainerChangeResponseItem
|
|
||||||
type ContainerChangeResponseItem struct {
|
|
||||||
|
|
||||||
// Kind of change
|
|
||||||
// Required: true
|
|
||||||
Kind uint8 `json:"Kind"`
|
|
||||||
|
|
||||||
// Path to file that has changed
|
|
||||||
// Required: true
|
|
||||||
Path string `json:"Path"`
|
|
||||||
}
|
|
19
vendor/github.com/docker/docker/api/types/container/filesystem_change.go
generated
vendored
Normal file
19
vendor/github.com/docker/docker/api/types/container/filesystem_change.go
generated
vendored
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
package container
|
||||||
|
|
||||||
|
// This file was generated by the swagger tool.
|
||||||
|
// Editing this file might prove futile when you re-run the swagger generate command
|
||||||
|
|
||||||
|
// FilesystemChange Change in the container's filesystem.
|
||||||
|
//
|
||||||
|
// swagger:model FilesystemChange
|
||||||
|
type FilesystemChange struct {
|
||||||
|
|
||||||
|
// kind
|
||||||
|
// Required: true
|
||||||
|
Kind ChangeType `json:"Kind"`
|
||||||
|
|
||||||
|
// Path to file or directory that has changed.
|
||||||
|
//
|
||||||
|
// Required: true
|
||||||
|
Path string `json:"Path"`
|
||||||
|
}
|
|
@ -126,7 +126,12 @@ func CheckRedirect(req *http.Request, via []*http.Request) error {
|
||||||
// client.WithAPIVersionNegotiation(),
|
// client.WithAPIVersionNegotiation(),
|
||||||
// )
|
// )
|
||||||
func NewClientWithOpts(ops ...Opt) (*Client, error) {
|
func NewClientWithOpts(ops ...Opt) (*Client, error) {
|
||||||
client, err := defaultHTTPClient(DefaultDockerHost)
|
hostURL, err := ParseHostURL(DefaultDockerHost)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := defaultHTTPClient(hostURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -134,8 +139,8 @@ func NewClientWithOpts(ops ...Opt) (*Client, error) {
|
||||||
host: DefaultDockerHost,
|
host: DefaultDockerHost,
|
||||||
version: api.DefaultVersion,
|
version: api.DefaultVersion,
|
||||||
client: client,
|
client: client,
|
||||||
proto: defaultProto,
|
proto: hostURL.Scheme,
|
||||||
addr: defaultAddr,
|
addr: hostURL.Host,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, op := range ops {
|
for _, op := range ops {
|
||||||
|
@ -161,13 +166,12 @@ func NewClientWithOpts(ops ...Opt) (*Client, error) {
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultHTTPClient(host string) (*http.Client, error) {
|
func defaultHTTPClient(hostURL *url.URL) (*http.Client, error) {
|
||||||
hostURL, err := ParseHostURL(host)
|
transport := &http.Transport{}
|
||||||
|
err := sockets.ConfigureTransport(transport, hostURL.Scheme, hostURL.Host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
transport := &http.Transport{}
|
|
||||||
_ = sockets.ConfigureTransport(transport, hostURL.Scheme, hostURL.Host)
|
|
||||||
return &http.Client{
|
return &http.Client{
|
||||||
Transport: transport,
|
Transport: transport,
|
||||||
CheckRedirect: CheckRedirect,
|
CheckRedirect: CheckRedirect,
|
||||||
|
|
|
@ -6,6 +6,3 @@ package client // import "github.com/docker/docker/client"
|
||||||
// DefaultDockerHost defines OS-specific default host if the DOCKER_HOST
|
// DefaultDockerHost defines OS-specific default host if the DOCKER_HOST
|
||||||
// (EnvOverrideHost) environment variable is unset or empty.
|
// (EnvOverrideHost) environment variable is unset or empty.
|
||||||
const DefaultDockerHost = "unix:///var/run/docker.sock"
|
const DefaultDockerHost = "unix:///var/run/docker.sock"
|
||||||
|
|
||||||
const defaultProto = "unix"
|
|
||||||
const defaultAddr = "/var/run/docker.sock"
|
|
||||||
|
|
|
@ -3,6 +3,3 @@ package client // import "github.com/docker/docker/client"
|
||||||
// DefaultDockerHost defines OS-specific default host if the DOCKER_HOST
|
// DefaultDockerHost defines OS-specific default host if the DOCKER_HOST
|
||||||
// (EnvOverrideHost) environment variable is unset or empty.
|
// (EnvOverrideHost) environment variable is unset or empty.
|
||||||
const DefaultDockerHost = "npipe:////./pipe/docker_engine"
|
const DefaultDockerHost = "npipe:////./pipe/docker_engine"
|
||||||
|
|
||||||
const defaultProto = "npipe"
|
|
||||||
const defaultAddr = "//./pipe/docker_engine"
|
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContainerDiff shows differences in a container filesystem since it was started.
|
// ContainerDiff shows differences in a container filesystem since it was started.
|
||||||
func (cli *Client) ContainerDiff(ctx context.Context, containerID string) ([]container.ContainerChangeResponseItem, error) {
|
func (cli *Client) ContainerDiff(ctx context.Context, containerID string) ([]container.FilesystemChange, error) {
|
||||||
var changes []container.ContainerChangeResponseItem
|
var changes []container.FilesystemChange
|
||||||
|
|
||||||
serverResp, err := cli.get(ctx, "/containers/"+containerID+"/changes", url.Values{}, nil)
|
serverResp, err := cli.get(ctx, "/containers/"+containerID+"/changes", url.Values{}, nil)
|
||||||
defer ensureReaderClosed(serverResp)
|
defer ensureReaderClosed(serverResp)
|
||||||
|
|
|
@ -48,7 +48,7 @@ type ContainerAPIClient interface {
|
||||||
ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error)
|
ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error)
|
||||||
ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.IDResponse, error)
|
ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.IDResponse, error)
|
||||||
ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *specs.Platform, containerName string) (container.CreateResponse, error)
|
ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *specs.Platform, containerName string) (container.CreateResponse, error)
|
||||||
ContainerDiff(ctx context.Context, container string) ([]container.ContainerChangeResponseItem, error)
|
ContainerDiff(ctx context.Context, container string) ([]container.FilesystemChange, error)
|
||||||
ContainerExecAttach(ctx context.Context, execID string, config types.ExecStartCheck) (types.HijackedResponse, error)
|
ContainerExecAttach(ctx context.Context, execID string, config types.ExecStartCheck) (types.HijackedResponse, error)
|
||||||
ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error)
|
ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error)
|
||||||
ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error)
|
ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error)
|
||||||
|
|
|
@ -16,8 +16,8 @@ import (
|
||||||
// ensure the formatted time isalways the same number of characters.
|
// ensure the formatted time isalways the same number of characters.
|
||||||
const RFC3339NanoFixed = "2006-01-02T15:04:05.000000000Z07:00"
|
const RFC3339NanoFixed = "2006-01-02T15:04:05.000000000Z07:00"
|
||||||
|
|
||||||
// JSONError wraps a concrete Code and Message, `Code` is
|
// JSONError wraps a concrete Code and Message, Code is
|
||||||
// is an integer error code, `Message` is the error message.
|
// an integer error code, Message is the error message.
|
||||||
type JSONError struct {
|
type JSONError struct {
|
||||||
Code int `json:"code,omitempty"`
|
Code int `json:"code,omitempty"`
|
||||||
Message string `json:"message,omitempty"`
|
Message string `json:"message,omitempty"`
|
||||||
|
@ -27,20 +27,28 @@ func (e *JSONError) Error() string {
|
||||||
return e.Message
|
return e.Message
|
||||||
}
|
}
|
||||||
|
|
||||||
// JSONProgress describes a Progress. terminalFd is the fd of the current terminal,
|
// JSONProgress describes a progress message in a JSON stream.
|
||||||
// Start is the initial value for the operation. Current is the current status and
|
|
||||||
// value of the progress made towards Total. Total is the end value describing when
|
|
||||||
// we made 100% progress for an operation.
|
|
||||||
type JSONProgress struct {
|
type JSONProgress struct {
|
||||||
|
// Current is the current status and value of the progress made towards Total.
|
||||||
|
Current int64 `json:"current,omitempty"`
|
||||||
|
// Total is the end value describing when we made 100% progress for an operation.
|
||||||
|
Total int64 `json:"total,omitempty"`
|
||||||
|
// Start is the initial value for the operation.
|
||||||
|
Start int64 `json:"start,omitempty"`
|
||||||
|
// HideCounts. if true, hides the progress count indicator (xB/yB).
|
||||||
|
HideCounts bool `json:"hidecounts,omitempty"`
|
||||||
|
// Units is the unit to print for progress. It defaults to "bytes" if empty.
|
||||||
|
Units string `json:"units,omitempty"`
|
||||||
|
|
||||||
|
// terminalFd is the fd of the current terminal, if any. It is used
|
||||||
|
// to get the terminal width.
|
||||||
terminalFd uintptr
|
terminalFd uintptr
|
||||||
Current int64 `json:"current,omitempty"`
|
|
||||||
Total int64 `json:"total,omitempty"`
|
// nowFunc is used to override the current time in tests.
|
||||||
Start int64 `json:"start,omitempty"`
|
nowFunc func() time.Time
|
||||||
// If true, don't show xB/yB
|
|
||||||
HideCounts bool `json:"hidecounts,omitempty"`
|
// winSize is used to override the terminal width in tests.
|
||||||
Units string `json:"units,omitempty"`
|
winSize int
|
||||||
nowFunc func() time.Time
|
|
||||||
winSize int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *JSONProgress) String() string {
|
func (p *JSONProgress) String() string {
|
||||||
|
@ -56,8 +64,7 @@ func (p *JSONProgress) String() string {
|
||||||
if p.Total <= 0 {
|
if p.Total <= 0 {
|
||||||
switch p.Units {
|
switch p.Units {
|
||||||
case "":
|
case "":
|
||||||
current := units.HumanSize(float64(p.Current))
|
return fmt.Sprintf("%8v", units.HumanSize(float64(p.Current)))
|
||||||
return fmt.Sprintf("%8v", current)
|
|
||||||
default:
|
default:
|
||||||
return fmt.Sprintf("%d %s", p.Current, p.Units)
|
return fmt.Sprintf("%d %s", p.Current, p.Units)
|
||||||
}
|
}
|
||||||
|
@ -110,17 +117,17 @@ func (p *JSONProgress) String() string {
|
||||||
return pbBox + numbersBox + timeLeftBox
|
return pbBox + numbersBox + timeLeftBox
|
||||||
}
|
}
|
||||||
|
|
||||||
// shim for testing
|
// now returns the current time in UTC, but can be overridden in tests
|
||||||
|
// by setting JSONProgress.nowFunc to a custom function.
|
||||||
func (p *JSONProgress) now() time.Time {
|
func (p *JSONProgress) now() time.Time {
|
||||||
if p.nowFunc == nil {
|
if p.nowFunc != nil {
|
||||||
p.nowFunc = func() time.Time {
|
return p.nowFunc()
|
||||||
return time.Now().UTC()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return p.nowFunc()
|
return time.Now().UTC()
|
||||||
}
|
}
|
||||||
|
|
||||||
// shim for testing
|
// width returns the current terminal's width, but can be overridden
|
||||||
|
// in tests by setting JSONProgress.winSize to a non-zero value.
|
||||||
func (p *JSONProgress) width() int {
|
func (p *JSONProgress) width() int {
|
||||||
if p.winSize != 0 {
|
if p.winSize != 0 {
|
||||||
return p.winSize
|
return p.winSize
|
||||||
|
@ -164,13 +171,11 @@ func cursorDown(out io.Writer, l uint) {
|
||||||
fmt.Fprint(out, aec.Down(l))
|
fmt.Fprint(out, aec.Down(l))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display displays the JSONMessage to `out`. If `isTerminal` is true, it will erase the
|
// Display prints the JSONMessage to out. If isTerminal is true, it erases
|
||||||
// entire current line when displaying the progressbar.
|
// the entire current line when displaying the progressbar. It returns an
|
||||||
|
// error if the [JSONMessage.Error] field is non-nil.
|
||||||
func (jm *JSONMessage) Display(out io.Writer, isTerminal bool) error {
|
func (jm *JSONMessage) Display(out io.Writer, isTerminal bool) error {
|
||||||
if jm.Error != nil {
|
if jm.Error != nil {
|
||||||
if jm.Error.Code == 401 {
|
|
||||||
return fmt.Errorf("authentication is required")
|
|
||||||
}
|
|
||||||
return jm.Error
|
return jm.Error
|
||||||
}
|
}
|
||||||
var endl string
|
var endl string
|
||||||
|
@ -204,9 +209,22 @@ func (jm *JSONMessage) Display(out io.Writer, isTerminal bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DisplayJSONMessagesStream displays a json message stream from `in` to `out`, `isTerminal`
|
// DisplayJSONMessagesStream reads a JSON message stream from in, and writes
|
||||||
// describes if `out` is a terminal. If this is the case, it will print `\n` at the end of
|
// each [JSONMessage] to out. It returns an error if an invalid JSONMessage
|
||||||
// each line and move the cursor while displaying.
|
// is received, or if a JSONMessage containers a non-zero [JSONMessage.Error].
|
||||||
|
//
|
||||||
|
// Presentation of the JSONMessage depends on whether a terminal is attached,
|
||||||
|
// and on the terminal width. Progress bars ([JSONProgress]) are suppressed
|
||||||
|
// on narrower terminals (< 110 characters).
|
||||||
|
//
|
||||||
|
// - isTerminal describes if out is a terminal, in which case it prints
|
||||||
|
// a newline ("\n") at the end of each line and moves the cursor while
|
||||||
|
// displaying.
|
||||||
|
// - terminalFd is the fd of the current terminal (if any), and used
|
||||||
|
// to get the terminal width.
|
||||||
|
// - auxCallback allows handling the [JSONMessage.Aux] field. It is
|
||||||
|
// called if a JSONMessage contains an Aux field, in which case
|
||||||
|
// DisplayJSONMessagesStream does not present the JSONMessage.
|
||||||
func DisplayJSONMessagesStream(in io.Reader, out io.Writer, terminalFd uintptr, isTerminal bool, auxCallback func(JSONMessage)) error {
|
func DisplayJSONMessagesStream(in io.Reader, out io.Writer, terminalFd uintptr, isTerminal bool, auxCallback func(JSONMessage)) error {
|
||||||
var (
|
var (
|
||||||
dec = json.NewDecoder(in)
|
dec = json.NewDecoder(in)
|
||||||
|
|
|
@ -40,7 +40,7 @@ github.com/docker/distribution/registry/client/transport
|
||||||
github.com/docker/distribution/registry/storage/cache
|
github.com/docker/distribution/registry/storage/cache
|
||||||
github.com/docker/distribution/registry/storage/cache/memory
|
github.com/docker/distribution/registry/storage/cache/memory
|
||||||
github.com/docker/distribution/uuid
|
github.com/docker/distribution/uuid
|
||||||
# github.com/docker/docker v24.0.0-rc.1+incompatible
|
# github.com/docker/docker v24.0.0-rc.1.0.20230505222407-8d9a40a82034+incompatible
|
||||||
## explicit
|
## explicit
|
||||||
github.com/docker/docker/api
|
github.com/docker/docker/api
|
||||||
github.com/docker/docker/api/types
|
github.com/docker/docker/api/types
|
||||||
|
|
Loading…
Reference in New Issue