@@ -3,6 +3,7 @@ package patch
3
3
import (
4
4
"bytes"
5
5
"context"
6
+ "encoding/json"
6
7
"errors"
7
8
"fmt"
8
9
"io"
@@ -11,20 +12,19 @@ import (
11
12
"strings"
12
13
"time"
13
14
14
- "github.com/containerd/containerd/platforms"
15
- "github.com/docker/buildx/build"
16
15
"github.com/docker/cli/cli/config"
17
- log "github.com/sirupsen/logrus"
18
- "golang.org/x/exp/slices"
16
+
17
+ "github.com/docker/buildx/build"
18
+ "github.com/moby/buildkit/client"
19
+ "github.com/moby/buildkit/session"
20
+ "github.com/moby/buildkit/session/auth/authprovider"
19
21
"golang.org/x/sync/errgroup"
20
22
23
+ "github.com/containerd/containerd/platforms"
21
24
"github.com/distribution/reference"
22
- "github.com/moby/buildkit/client"
23
25
"github.com/moby/buildkit/client/llb"
24
26
"github.com/moby/buildkit/exporter/containerimage/exptypes"
25
27
gwclient "github.com/moby/buildkit/frontend/gateway/client"
26
- "github.com/moby/buildkit/session"
27
- "github.com/moby/buildkit/session/auth/authprovider"
28
28
"github.com/moby/buildkit/util/progress/progressui"
29
29
"github.com/project-copacetic/copacetic/pkg/buildkit"
30
30
"github.com/project-copacetic/copacetic/pkg/pkgmgr"
@@ -33,6 +33,8 @@ import (
33
33
"github.com/project-copacetic/copacetic/pkg/utils"
34
34
"github.com/project-copacetic/copacetic/pkg/vex"
35
35
"github.com/quay/claircore/osrelease"
36
+ log "github.com/sirupsen/logrus"
37
+ "golang.org/x/exp/slices"
36
38
)
37
39
38
40
const (
@@ -42,6 +44,18 @@ const (
42
44
defaultTag = "latest"
43
45
)
44
46
47
+ type Config struct {
48
+ Cmd []string `json:"Cmd"`
49
+ WorkingDir string `json:"WorkingDir"`
50
+ ExposedPorts map [string ]struct {} `json:"ExposedPorts"`
51
+ Env []string `json:"Env"`
52
+ Labels map [string ]string `json:"Labels"`
53
+ }
54
+
55
+ type ImgConfig struct {
56
+ Config Config `json:"Config"`
57
+ }
58
+
45
59
// Patch command applies package updates to an OCI image given a vulnerability report.
46
60
func Patch (ctx context.Context , timeout time.Duration , image , reportFile , patchedTag , workingFolder , scanner , format , output string , ignoreError bool , bkOpts buildkit.Opts ) error {
47
61
timeoutCtx , cancel := context .WithTimeout (ctx , timeout )
@@ -140,6 +154,16 @@ func patchWithContext(ctx context.Context, ch chan error, image, reportFile, pat
140
154
}
141
155
defer bkClient .Close ()
142
156
157
+ mockConfig := Config {
158
+ Labels : map [string ]string {"org.opencontainers.image.base.name" : "test" },
159
+ }
160
+
161
+ imgConfig := ImgConfig {
162
+ Config : mockConfig ,
163
+ }
164
+
165
+ configStr , _ := json .Marshal (imgConfig )
166
+
143
167
pipeR , pipeW := io .Pipe ()
144
168
dockerConfig := config .LoadDefaultConfigFile (os .Stderr )
145
169
attachable := []session.Attachable {authprovider .NewDockerAuthProvider (dockerConfig , nil )}
@@ -148,7 +172,8 @@ func patchWithContext(ctx context.Context, ch chan error, image, reportFile, pat
148
172
{
149
173
Type : client .ExporterDocker ,
150
174
Attrs : map [string ]string {
151
- "name" : patchedImageName ,
175
+ "name" : patchedImageName ,
176
+ "containerimage.config" : string (configStr ),
152
177
},
153
178
Output : func (_ map [string ]string ) (io.WriteCloser , error ) {
154
179
return pipeW , nil
0 commit comments