Skip to content

Commit

Permalink
Merge pull request #28 from docker/shorter-tag
Browse files Browse the repository at this point in the history
Add tag alias using 7-character hash
  • Loading branch information
errordeveloper authored Oct 3, 2023
2 parents 95719e6 + 9ac3281 commit ef2cb99
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions oci/artefact.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,13 @@ func (c *Client) PushArtefact(ctx context.Context, destinationRef, sourceDir str
return "", fmt.Errorf("failed to serialise attestations: %w", err)
}

ref := destinationRef + ":" + manifestTypes.ConfigImageTagPrefix + hex.EncodeToString(c.hash.Sum(nil))
tag, err := name.ParseReference(ref)
repo, err := name.NewRepository(destinationRef)
if err != nil {
return "", fmt.Errorf("invalid URL: %w", err)
}
hash := hex.EncodeToString(c.hash.Sum(nil))
tag := repo.Tag(manifestTypes.ConfigImageTagPrefix + hash)
tagAlias := tag.Context().Tag(manifestTypes.ConfigImageTagPrefix + hash[:7])

if timestamp == nil {
timestamp = new(time.Time)
Expand Down Expand Up @@ -339,7 +341,11 @@ func (c *Client) PushArtefact(ctx context.Context, destinationRef, sourceDir str
return "", fmt.Errorf("pushing index failed: %w", err)
}

return ref + "@" + digest.String(), err
if err := remote.Tag(tagAlias, index, c.remoteWithContext(ctx)...); err != nil {
return "", fmt.Errorf("adding alias tagging failed: %w", err)
}

return tagAlias.String() + "@" + digest.String(), err
}

func makeDescriptorWithPlatform() Descriptor {
Expand Down

0 comments on commit ef2cb99

Please sign in to comment.