Skip to content

Commit 5e3ee36

Browse files
Miaha CybersecMiaha Cybersec
Miaha Cybersec
authored and
Miaha Cybersec
committed
Add mock config
1 parent d18efa7 commit 5e3ee36

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

pkg/patch/patch.go

+33-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package patch
33
import (
44
"bytes"
55
"context"
6+
"encoding/json"
67
"errors"
78
"fmt"
89
"io"
@@ -11,20 +12,19 @@ import (
1112
"strings"
1213
"time"
1314

14-
"github.com/containerd/containerd/platforms"
15-
"github.com/docker/buildx/build"
1615
"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"
1921
"golang.org/x/sync/errgroup"
2022

23+
"github.com/containerd/containerd/platforms"
2124
"github.com/distribution/reference"
22-
"github.com/moby/buildkit/client"
2325
"github.com/moby/buildkit/client/llb"
2426
"github.com/moby/buildkit/exporter/containerimage/exptypes"
2527
gwclient "github.com/moby/buildkit/frontend/gateway/client"
26-
"github.com/moby/buildkit/session"
27-
"github.com/moby/buildkit/session/auth/authprovider"
2828
"github.com/moby/buildkit/util/progress/progressui"
2929
"github.com/project-copacetic/copacetic/pkg/buildkit"
3030
"github.com/project-copacetic/copacetic/pkg/pkgmgr"
@@ -33,6 +33,8 @@ import (
3333
"github.com/project-copacetic/copacetic/pkg/utils"
3434
"github.com/project-copacetic/copacetic/pkg/vex"
3535
"github.com/quay/claircore/osrelease"
36+
log "github.com/sirupsen/logrus"
37+
"golang.org/x/exp/slices"
3638
)
3739

3840
const (
@@ -42,6 +44,18 @@ const (
4244
defaultTag = "latest"
4345
)
4446

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+
4559
// Patch command applies package updates to an OCI image given a vulnerability report.
4660
func Patch(ctx context.Context, timeout time.Duration, image, reportFile, patchedTag, workingFolder, scanner, format, output string, ignoreError bool, bkOpts buildkit.Opts) error {
4761
timeoutCtx, cancel := context.WithTimeout(ctx, timeout)
@@ -140,6 +154,16 @@ func patchWithContext(ctx context.Context, ch chan error, image, reportFile, pat
140154
}
141155
defer bkClient.Close()
142156

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+
143167
pipeR, pipeW := io.Pipe()
144168
dockerConfig := config.LoadDefaultConfigFile(os.Stderr)
145169
attachable := []session.Attachable{authprovider.NewDockerAuthProvider(dockerConfig, nil)}
@@ -148,7 +172,8 @@ func patchWithContext(ctx context.Context, ch chan error, image, reportFile, pat
148172
{
149173
Type: client.ExporterDocker,
150174
Attrs: map[string]string{
151-
"name": patchedImageName,
175+
"name": patchedImageName,
176+
"containerimage.config": string(configStr),
152177
},
153178
Output: func(_ map[string]string) (io.WriteCloser, error) {
154179
return pipeW, nil

0 commit comments

Comments
 (0)