Skip to content

Commit 91375c9

Browse files
refactor copa
1 parent 1fb12cf commit 91375c9

File tree

4 files changed

+46
-409
lines changed

4 files changed

+46
-409
lines changed

pkg/copa/main.go

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@ package copa
33
import (
44
"context"
55
"fmt"
6-
76
"log"
87
"log/slog"
8+
"os/exec"
99
"strings"
10-
"time"
1110

12-
"github.com/aquasecurity/trivy/pkg/fanal/types"
1311
v1 "github.com/google/go-containerregistry/pkg/v1"
1412
v1_spec "github.com/opencontainers/image-spec/specs-go/v1"
15-
"github.com/project-copacetic/copacetic/pkg/buildkit"
1613
"oras.land/oras-go/v2"
1714
"oras.land/oras-go/v2/content/oci"
1815
"oras.land/oras-go/v2/registry/remote"
@@ -73,13 +70,35 @@ func (o PatchOption) Run(ctx context.Context, reportFilePaths map[*image.Image]s
7370
// make sure we don't parse again
7471
seenImages = append(seenImages, *i)
7572

76-
if err := Patch(ctx, 30*time.Minute, ref, reportFilePaths[i], i.Tag, "", "trivy", "openvex", "", o.IgnoreErrors, buildkit.Opts{
77-
Addr: o.Buildkit.Addr,
78-
CACertPath: o.Buildkit.CACertPath,
79-
CertPath: o.Buildkit.CertPath,
80-
KeyPath: o.Buildkit.KeyPath,
81-
}, outFilePaths[i]); err != nil {
82-
return fmt.Errorf("error patching image %s :: %w ", ref, err)
73+
cmdArgs := []string{"patch", "--timeout", "30m", "--image", ref, "--report", reportFilePaths[i], "--tag", i.Tag}
74+
// TODO: Figure out if we need to remove this and associated config in viper
75+
// if o.IgnoreErrors {
76+
// cmdArgs = append(cmdArgs, "--ignore-errors")
77+
// }
78+
if o.Buildkit.Addr != "" {
79+
cmdArgs = append(cmdArgs, "--addr", o.Buildkit.Addr)
80+
}
81+
if o.Buildkit.CACertPath != "" {
82+
cmdArgs = append(cmdArgs, "--cacert", o.Buildkit.CACertPath)
83+
}
84+
if o.Buildkit.CertPath != "" {
85+
cmdArgs = append(cmdArgs, "--cert", o.Buildkit.CertPath)
86+
}
87+
if o.Buildkit.KeyPath != "" {
88+
cmdArgs = append(cmdArgs, "--key", o.Buildkit.KeyPath)
89+
}
90+
91+
cmd := exec.CommandContext(ctx, "copa", cmdArgs...)
92+
output, err := cmd.CombinedOutput()
93+
if err != nil {
94+
return fmt.Errorf("error patching image %s :: %w :: %s", ref, err, string(output))
95+
}
96+
97+
// Save the patched image to a tar file
98+
cmd = exec.CommandContext(ctx, "docker", "save", "-o", outFilePaths[i], ref)
99+
output, err = cmd.CombinedOutput()
100+
if err != nil {
101+
return fmt.Errorf("error saving image %s to tar :: %w :: %s", i.Tag, err, string(output))
83102
}
84103

85104
_ = bar.Add(1)
@@ -162,16 +181,3 @@ func (o PatchOption) Run(ctx context.Context, reportFilePaths map[*image.Image]s
162181

163182
return nil
164183
}
165-
166-
func SupportedOS(os *types.OS) bool {
167-
if os == nil {
168-
return true
169-
}
170-
171-
switch os.Family {
172-
case "photon":
173-
return false
174-
default:
175-
return true
176-
}
177-
}

0 commit comments

Comments
 (0)