Skip to content

Commit

Permalink
fix: replace current platform image with the new one when it already …
Browse files Browse the repository at this point in the history
…have existed in the image index (#1077)
  • Loading branch information
SparkYuan committed Apr 28, 2024
1 parent 82c7c9a commit b25fafb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/cmd/mod/mod_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (o *PushModOptions) Run() error {

// Copy to temp module dir and push artifact to OCI repository
err = ioutil.CopyDir(targetDir, o.ModulePath, func(path string) bool {
skipDirs := []string{filepath.Join(o.ModulePath, ".git"), filepath.Join(o.ModulePath, "src")}
skipDirs := []string{filepath.Join(o.ModulePath, ".git"), filepath.Join(o.ModulePath, ".idea"), filepath.Join(o.ModulePath, "src")}

// skip files in skipDirs
for _, dir := range skipDirs {
Expand Down Expand Up @@ -354,7 +354,7 @@ func (o *PushModOptions) buildModule() (string, error) {
func buildBinary(goBin, operatingSystem, arch, srcDirectory, outfile string, ioStreams genericiooptions.IOStreams) (string, error) {
if outfile == "" {
// If no outfile is supplied, write the Go binary to a temporary file.
f, err := os.CreateTemp("", "generator.*")
f, err := os.CreateTemp("", "module.*")
if err != nil {
return "", fmt.Errorf("unable to create go program temp file: %w", err)
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/oci/client/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/empty"
"github.com/google/go-containerregistry/pkg/v1/match"
"github.com/google/go-containerregistry/pkg/v1/mutate"
"github.com/google/go-containerregistry/pkg/v1/partial"
"github.com/google/go-containerregistry/pkg/v1/remote"
Expand Down Expand Up @@ -147,7 +148,10 @@ func (c *Client) Push(
Add: image,
Descriptor: *newDesc,
}
idx := mutate.AppendManifests(base, addendum)

// replace current platform image with the new one
// remove is removed before adds
idx := mutate.AppendManifests(mutate.RemoveManifests(base, match.Platforms(*newDesc.Platform)), addendum)
idxDigest, err := idx.Digest()
if err != nil {
return "", "", fmt.Errorf("parsing index digest failed: %w", err)
Expand Down

0 comments on commit b25fafb

Please sign in to comment.