mirror of https://github.com/docker/cli.git
Compare commits
8 Commits
2867b555c8
...
6aa76111d9
Author | SHA1 | Date |
---|---|---|
Sebastiaan van Stijn | 6aa76111d9 | |
Sebastiaan van Stijn | a5fb752ecf | |
Laura Brehm | 4e64c59d64 | |
Jonathan A. Sternberg | 3472bbc28a | |
Laura Brehm | 649e564ee0 | |
Sebastiaan van Stijn | e1213edcc6 | |
Jonathan A. Sternberg | b1956f5073 | |
Sebastiaan van Stijn | ced6336804 |
|
@ -67,7 +67,7 @@ jobs:
|
||||||
name: Update Go
|
name: Update Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.21'
|
go-version: 1.22.7
|
||||||
-
|
-
|
||||||
name: Initialize CodeQL
|
name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v3
|
uses: github/codeql-action/init@v3
|
||||||
|
|
|
@ -758,6 +758,10 @@ func TestParseRestartPolicy(t *testing.T) {
|
||||||
Name: container.RestartPolicyDisabled,
|
Name: container.RestartPolicyDisabled,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
input: "no:1",
|
||||||
|
expectedErr: "invalid restart policy: maximum retry count can only be used with 'on-failure'",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
input: ":1",
|
input: ":1",
|
||||||
expectedErr: "invalid restart policy format: no policy provided before colon",
|
expectedErr: "invalid restart policy format: no policy provided before colon",
|
||||||
|
@ -769,11 +773,8 @@ func TestParseRestartPolicy(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
input: "always:1",
|
input: "always:1",
|
||||||
expected: container.RestartPolicy{
|
expectedErr: "invalid restart policy: maximum retry count can only be used with 'on-failure'",
|
||||||
Name: container.RestartPolicyAlways,
|
|
||||||
MaximumRetryCount: 1,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
input: "always:2:3",
|
input: "always:2:3",
|
||||||
|
@ -796,6 +797,10 @@ func TestParseRestartPolicy(t *testing.T) {
|
||||||
Name: container.RestartPolicyUnlessStopped,
|
Name: container.RestartPolicyUnlessStopped,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
input: "unless-stopped:1",
|
||||||
|
expectedErr: "invalid restart policy: maximum retry count can only be used with 'on-failure'",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
input: "unless-stopped:invalid",
|
input: "unless-stopped:invalid",
|
||||||
expectedErr: "invalid restart policy format: maximum retry count must be an integer",
|
expectedErr: "invalid restart policy format: maximum retry count must be an integer",
|
||||||
|
|
|
@ -180,7 +180,7 @@ func toWslPath(s string) string {
|
||||||
if !ok {
|
if !ok {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("mnt/%s%s", drive, p)
|
return fmt.Sprintf("mnt/%s%s", strings.ToLower(drive), p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseUNCPath(s string) (drive, p string, ok bool) {
|
func parseUNCPath(s string) (drive, p string, ok bool) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package command
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/fs"
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
"testing/fstest"
|
"testing/fstest"
|
||||||
|
@ -9,21 +10,48 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWslSocketPath(t *testing.T) {
|
func TestWslSocketPath(t *testing.T) {
|
||||||
u, err := url.Parse("unix:////./c:/my/file/path")
|
testCases := []struct {
|
||||||
assert.NilError(t, err)
|
doc string
|
||||||
|
fs fs.FS
|
||||||
// Ensure host is empty.
|
url string
|
||||||
assert.Equal(t, u.Host, "")
|
expected string
|
||||||
|
}{
|
||||||
// Use a filesystem where the WSL path exists.
|
{
|
||||||
fs := fstest.MapFS{
|
doc: "filesystem where WSL path does not exist",
|
||||||
"mnt/c/my/file/path": {},
|
fs: fstest.MapFS{
|
||||||
|
"my/file/path": {},
|
||||||
|
},
|
||||||
|
url: "unix:////./c:/my/file/path",
|
||||||
|
expected: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
doc: "filesystem where WSL path exists",
|
||||||
|
fs: fstest.MapFS{
|
||||||
|
"mnt/c/my/file/path": {},
|
||||||
|
},
|
||||||
|
url: "unix:////./c:/my/file/path",
|
||||||
|
expected: "/mnt/c/my/file/path",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
doc: "filesystem where WSL path exists uppercase URL",
|
||||||
|
fs: fstest.MapFS{
|
||||||
|
"mnt/c/my/file/path": {},
|
||||||
|
},
|
||||||
|
url: "unix:////./C:/my/file/path",
|
||||||
|
expected: "/mnt/c/my/file/path",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
assert.Equal(t, wslSocketPath(u.Path, fs), "/mnt/c/my/file/path")
|
|
||||||
|
|
||||||
// Use a filesystem where the WSL path doesn't exist.
|
for _, tc := range testCases {
|
||||||
fs = fstest.MapFS{
|
t.Run(tc.doc, func(t *testing.T) {
|
||||||
"my/file/path": {},
|
u, err := url.Parse(tc.url)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
// Ensure host is empty.
|
||||||
|
assert.Equal(t, u.Host, "")
|
||||||
|
|
||||||
|
result := wslSocketPath(u.Path, tc.fs)
|
||||||
|
|
||||||
|
assert.Equal(t, result, tc.expected)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
assert.Equal(t, wslSocketPath(u.Path, fs), "")
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/docker/cli/cli/version"
|
"github.com/docker/cli/cli/version"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"go.opentelemetry.io/otel"
|
||||||
"go.opentelemetry.io/otel/attribute"
|
"go.opentelemetry.io/otel/attribute"
|
||||||
"go.opentelemetry.io/otel/metric"
|
"go.opentelemetry.io/otel/metric"
|
||||||
)
|
)
|
||||||
|
@ -94,7 +95,9 @@ func startCobraCommandTimer(mp metric.MeterProvider, attrs []attribute.KeyValue)
|
||||||
metric.WithAttributes(cmdStatusAttrs...),
|
metric.WithAttributes(cmdStatusAttrs...),
|
||||||
)
|
)
|
||||||
if mp, ok := mp.(MeterProvider); ok {
|
if mp, ok := mp.(MeterProvider); ok {
|
||||||
mp.ForceFlush(ctx)
|
if err := mp.ForceFlush(ctx); err != nil {
|
||||||
|
otel.Handle(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,8 +79,7 @@ func Service(
|
||||||
return swarm.ServiceSpec{}, err
|
return swarm.ServiceSpec{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
restartPolicy, err := convertRestartPolicy(
|
restartPolicy, err := convertRestartPolicy(service.Restart, service.Deploy.RestartPolicy)
|
||||||
service.Restart, service.Deploy.RestartPolicy)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return swarm.ServiceSpec{}, err
|
return swarm.ServiceSpec{}, err
|
||||||
}
|
}
|
||||||
|
@ -494,7 +493,7 @@ func convertRestartPolicy(restart string, source *composetypes.RestartPolicy) (*
|
||||||
MaxAttempts: &attempts,
|
MaxAttempts: &attempts,
|
||||||
}, nil
|
}, nil
|
||||||
default:
|
default:
|
||||||
return nil, errors.Errorf("unknown restart policy: %s", restart)
|
return nil, errors.Errorf("invalid restart policy: unknown policy '%s'", restart)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ func TestConvertRestartPolicyFromNone(t *testing.T) {
|
||||||
|
|
||||||
func TestConvertRestartPolicyFromUnknown(t *testing.T) {
|
func TestConvertRestartPolicyFromUnknown(t *testing.T) {
|
||||||
_, err := convertRestartPolicy("unknown", nil)
|
_, err := convertRestartPolicy("unknown", nil)
|
||||||
assert.Error(t, err, "unknown restart policy: unknown")
|
assert.Error(t, err, "invalid restart policy: unknown policy 'unknown'; use one of 'no', 'always', 'on-failure', or 'unless-stopped'")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertRestartPolicyFromAlways(t *testing.T) {
|
func TestConvertRestartPolicyFromAlways(t *testing.T) {
|
||||||
|
|
|
@ -358,7 +358,9 @@ func runDocker(ctx context.Context, dockerCli *command.DockerCli) error {
|
||||||
|
|
||||||
mp := dockerCli.MeterProvider()
|
mp := dockerCli.MeterProvider()
|
||||||
if mp, ok := mp.(command.MeterProvider); ok {
|
if mp, ok := mp.(command.MeterProvider); ok {
|
||||||
defer mp.Shutdown(ctx)
|
if err := mp.Shutdown(ctx); err != nil {
|
||||||
|
otel.Handle(err)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprint(dockerCli.Err(), "Warning: Unexpected OTEL error, metrics may not be flushed")
|
fmt.Fprint(dockerCli.Err(), "Warning: Unexpected OTEL error, metrics may not be flushed")
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,5 +92,8 @@ func ParseRestartPolicy(policy string) (container.RestartPolicy, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Name = container.RestartPolicyMode(k)
|
p.Name = container.RestartPolicyMode(k)
|
||||||
|
if err := container.ValidateRestartPolicy(p); err != nil {
|
||||||
|
return container.RestartPolicy{}, err
|
||||||
|
}
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue