Skip to content

Commit d4b9dad

Browse files
committed
Updates oci image config to support upstream ArgsEscaped
ArgsEscaped has now been merged into upstream OCI image spec. This change removes the workaround we were doing in containerd to deserialize the extra json outside of the spec and instead just uses the formal spec types. Signed-off-by: Justin Terry <[email protected]>
1 parent 31f9d13 commit d4b9dad

14 files changed

Lines changed: 95 additions & 73 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ require (
4444
github.com/moby/sys/signal v0.7.0
4545
github.com/moby/sys/symlink v0.2.0
4646
github.com/opencontainers/go-digest v1.0.0
47-
github.com/opencontainers/image-spec v1.0.3-0.20220303224323-02efb9a75ee1
47+
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b
4848
github.com/opencontainers/runc v1.1.4
4949
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
5050
github.com/opencontainers/selinux v1.10.1

go.sum

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -759,8 +759,8 @@ github.com/opencontainers/image-spec v1.0.0/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zM
759759
github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
760760
github.com/opencontainers/image-spec v1.0.2-0.20211117181255-693428a734f5/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
761761
github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
762-
github.com/opencontainers/image-spec v1.0.3-0.20220303224323-02efb9a75ee1 h1:9iFHD5Kt9hkOfeawBNiEeEaV7bmC4/Z5wJp8E9BptMs=
763-
github.com/opencontainers/image-spec v1.0.3-0.20220303224323-02efb9a75ee1/go.mod h1:K/JAU0m27RFhDRX4PcFdIKntROP6y5Ed6O91aZYDQfs=
762+
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b h1:YWuSjZCQAPM8UUBLkYUk1e+rZcvWHJmFb6i6rM44Xs8=
763+
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b/go.mod h1:3OVijpioIKYWTqjiG0zfF6wvoJ4fAXGbjdZuI2NgsRQ=
764764
github.com/opencontainers/runc v0.0.0-20190115041553-12f6a991201f/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U=
765765
github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U=
766766
github.com/opencontainers/runc v1.0.0-rc8.0.20190926000215-3e425f80a8c9/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U=
@@ -846,7 +846,6 @@ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6So
846846
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
847847
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
848848
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
849-
github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY=
850849
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
851850
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
852851
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=

integration/client/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/containerd/typeurl v1.0.3-0.20220422153119-7f6e6d160d67
1313
github.com/gogo/protobuf v1.3.2 // indirect
1414
github.com/opencontainers/go-digest v1.0.0
15-
github.com/opencontainers/image-spec v1.0.3-0.20220303224323-02efb9a75ee1
15+
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b
1616
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
1717
github.com/sirupsen/logrus v1.8.1
1818
github.com/stretchr/testify v1.8.0

integration/client/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,8 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
530530
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
531531
github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
532532
github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
533-
github.com/opencontainers/image-spec v1.0.3-0.20220303224323-02efb9a75ee1 h1:9iFHD5Kt9hkOfeawBNiEeEaV7bmC4/Z5wJp8E9BptMs=
534-
github.com/opencontainers/image-spec v1.0.3-0.20220303224323-02efb9a75ee1/go.mod h1:K/JAU0m27RFhDRX4PcFdIKntROP6y5Ed6O91aZYDQfs=
533+
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b h1:YWuSjZCQAPM8UUBLkYUk1e+rZcvWHJmFb6i6rM44Xs8=
534+
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b/go.mod h1:3OVijpioIKYWTqjiG0zfF6wvoJ4fAXGbjdZuI2NgsRQ=
535535
github.com/opencontainers/runc v1.0.2/go.mod h1:aTaHFFwQXuA71CiyxOdFFIorAoemI04suvGRQFzWTD0=
536536
github.com/opencontainers/runc v1.0.3/go.mod h1:aTaHFFwQXuA71CiyxOdFFIorAoemI04suvGRQFzWTD0=
537537
github.com/opencontainers/runc v1.1.2/go.mod h1:Tj1hFw6eFWp/o33uxGf5yF2BX5yz2Z6iptFpuvbbKqc=

oci/spec_opts.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -406,22 +406,6 @@ func WithImageConfigArgs(image Image, args []string) SpecOpts {
406406
// even if there is no specified user in the image config
407407
return WithAdditionalGIDs("root")(ctx, client, c, s)
408408
} else if s.Windows != nil {
409-
// imageExtended is a superset of the oci Image struct that changes
410-
// the Config type to be imageConfigExtended in order to add the
411-
// ability to deserialize `ArgsEscaped` which is not an OCI field,
412-
// but is supported by Docker built images.
413-
type imageExtended struct {
414-
Config struct {
415-
ArgsEscaped bool `json:"ArgsEscaped,omitempty"`
416-
}
417-
}
418-
// Deserialize the extended image format for Windows.
419-
var ociImageExtended imageExtended
420-
if err := json.Unmarshal(imageConfigBytes, &ociImageExtended); err != nil {
421-
return err
422-
}
423-
argsEscaped := ociImageExtended.Config.ArgsEscaped
424-
425409
s.Process.Env = replaceOrAppendEnvValues(config.Env, s.Process.Env)
426410

427411
// To support Docker ArgsEscaped on Windows we need to combine the
@@ -462,7 +446,7 @@ func WithImageConfigArgs(image Image, args []string) SpecOpts {
462446
return errors.New("no arguments specified")
463447
}
464448

465-
if argsEscaped && (len(config.Entrypoint) > 0 || cmdFromImage) {
449+
if config.ArgsEscaped && (len(config.Entrypoint) > 0 || cmdFromImage) {
466450
s.Process.Args = nil
467451
s.Process.CommandLine = cmd[0]
468452
if len(cmd) > 1 {

oci/spec_opts_windows_test.go

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ package oci
1818

1919
import (
2020
"context"
21-
"encoding/json"
2221
"testing"
2322

2423
"github.com/containerd/containerd/containers"
2524
"github.com/containerd/containerd/namespaces"
2625

27-
"github.com/opencontainers/go-digest"
2826
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2927
"github.com/opencontainers/runtime-spec/specs-go"
3028
)
@@ -114,36 +112,6 @@ func TestWithWindowNetworksAllowUnqualifiedDNSQuery(t *testing.T) {
114112
}
115113
}
116114

117-
func newFakeArgsEscapedImage(config ocispec.ImageConfig) (Image, error) {
118-
type imageExtended struct {
119-
Config struct {
120-
ocispec.ImageConfig
121-
ArgsEscaped bool `json:"ArgsEscaped,omitempty"`
122-
}
123-
}
124-
125-
// Copy to extended format.
126-
configExtended := imageExtended{}
127-
configExtended.Config.ImageConfig = config
128-
configExtended.Config.ArgsEscaped = true
129-
130-
configBlob, err := json.Marshal(configExtended)
131-
if err != nil {
132-
return nil, err
133-
}
134-
configDescriptor := ocispec.Descriptor{
135-
MediaType: ocispec.MediaTypeImageConfig,
136-
Digest: digest.NewDigestFromBytes(digest.SHA256, configBlob),
137-
}
138-
139-
return fakeImage{
140-
config: configDescriptor,
141-
blobs: map[string]blob{
142-
configDescriptor.Digest.String(): configBlob,
143-
},
144-
}, nil
145-
}
146-
147115
// TestWithProcessArgsOverwritesWithImage verifies that when calling
148116
// WithImageConfig followed by WithProcessArgs when `ArgsEscaped==false` that
149117
// the process args overwrite the image args.
@@ -152,8 +120,9 @@ func TestWithProcessArgsOverwritesWithImage(t *testing.T) {
152120

153121
img, err := newFakeImage(ocispec.Image{
154122
Config: ocispec.ImageConfig{
155-
Entrypoint: []string{"powershell.exe", "-Command", "Write-Host Hello"},
156-
Cmd: []string{"cmd.exe", "/S", "/C", "echo Hello"},
123+
Entrypoint: []string{"powershell.exe", "-Command", "Write-Host Hello"},
124+
Cmd: []string{"cmd.exe", "/S", "/C", "echo Hello"},
125+
ArgsEscaped: false,
157126
},
158127
})
159128
if err != nil {
@@ -192,9 +161,12 @@ func TestWithProcessArgsOverwritesWithImage(t *testing.T) {
192161
func TestWithProcessArgsOverwritesWithImageArgsEscaped(t *testing.T) {
193162
t.Parallel()
194163

195-
img, err := newFakeArgsEscapedImage(ocispec.ImageConfig{
196-
Entrypoint: []string{`powershell.exe -Command "C:\My Data\MyExe.exe" -arg1 "-arg2 value2"`},
197-
Cmd: []string{`cmd.exe /S /C "C:\test path\test.exe"`},
164+
img, err := newFakeImage(ocispec.Image{
165+
Config: ocispec.ImageConfig{
166+
Entrypoint: []string{`powershell.exe -Command "C:\My Data\MyExe.exe" -arg1 "-arg2 value2"`},
167+
Cmd: []string{`cmd.exe /S /C "C:\test path\test.exe"`},
168+
ArgsEscaped: true,
169+
},
198170
})
199171
if err != nil {
200172
t.Fatal(err)
@@ -274,9 +246,12 @@ func TestWithImageOverwritesWithProcessArgs(t *testing.T) {
274246
func TestWithImageArgsEscapedOverwritesWithProcessArgs(t *testing.T) {
275247
t.Parallel()
276248

277-
img, err := newFakeArgsEscapedImage(ocispec.ImageConfig{
278-
Entrypoint: []string{`powershell.exe -Command "C:\My Data\MyExe.exe" -arg1 "-arg2 value2"`},
279-
Cmd: []string{`cmd.exe /S /C "C:\test path\test.exe"`},
249+
img, err := newFakeImage(ocispec.Image{
250+
Config: ocispec.ImageConfig{
251+
Entrypoint: []string{`powershell.exe -Command "C:\My Data\MyExe.exe" -arg1 "-arg2 value2"`},
252+
Cmd: []string{`cmd.exe /S /C "C:\test path\test.exe"`},
253+
ArgsEscaped: true,
254+
},
280255
})
281256
if err != nil {
282257
t.Fatal(err)
@@ -510,9 +485,12 @@ func TestWithImageConfigArgsEscapedWindows(t *testing.T) {
510485
}
511486
for _, tc := range testcases {
512487
t.Run(tc.name, func(t *testing.T) {
513-
img, err := newFakeArgsEscapedImage(ocispec.ImageConfig{
514-
Entrypoint: tc.entrypoint,
515-
Cmd: tc.cmd,
488+
img, err := newFakeImage(ocispec.Image{
489+
Config: ocispec.ImageConfig{
490+
Entrypoint: tc.entrypoint,
491+
Cmd: tc.cmd,
492+
ArgsEscaped: true,
493+
},
516494
})
517495
if err != nil {
518496
t.Fatal(err)

vendor/github.com/opencontainers/image-spec/specs-go/v1/annotations.go

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/opencontainers/image-spec/specs-go/v1/artifact.go

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/opencontainers/image-spec/specs-go/v1/config.go

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/opencontainers/image-spec/specs-go/v1/descriptor.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)