Skip to content

Commit

Permalink
Avoid race when mutating annotations (#1368)
Browse files Browse the repository at this point in the history
This is a quick fix to a race condition we're hitting when building
multi-arch images. The ImageConfiguration struct gets passed around by
value, but the collections (e.g. annotations) don't get copied, so if
multiple architectures attempt to set an annotation at the same time,
we'll hit a race. This creates a defensive copy to avoid that.

Signed-off-by: Jon Johnson <[email protected]>
  • Loading branch information
jonjohnsonjr authored Oct 24, 2024
1 parent f60d40e commit 46d530a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/build/oci/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,15 @@ import (
"chainguard.dev/apko/pkg/options"
)

func BuildImageFromLayer(ctx context.Context, baseImage v1.Image, layer v1.Layer, ic types.ImageConfiguration, created time.Time, arch types.Architecture) (oci.SignedImage, error) {
func BuildImageFromLayer(ctx context.Context, baseImage v1.Image, layer v1.Layer, oic types.ImageConfiguration, created time.Time, arch types.Architecture) (oci.SignedImage, error) {
log := clog.FromContext(ctx)

// Create a copy to avoid modifying the original ImageConfiguration.
ic := &types.ImageConfiguration{}
if err := oic.MergeInto(ic); err != nil {
return nil, err
}

mediaType, err := layer.MediaType()
if err != nil {
return nil, fmt.Errorf("accessing layer MediaType: %w", err)
Expand Down

0 comments on commit 46d530a

Please sign in to comment.