-
Notifications
You must be signed in to change notification settings - Fork 220
Fix inconsistent rebuild #2719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fix inconsistent rebuild #2719
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ import ( | |
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "sort" | ||
|
|
||
| "get.porter.sh/porter/pkg" | ||
| "get.porter.sh/porter/pkg/cnab" | ||
|
|
@@ -69,10 +70,31 @@ func (s Stamp) WriteManifest(cxt *portercontext.Context, path string) error { | |
| // MixinRecord contains information about a mixin used in a bundle | ||
| // For now it is a placeholder for data that we would like to include in the future. | ||
| type MixinRecord struct { | ||
| // Name of the mixin used in the bundle. This is used for sorting only, and | ||
| // should not be written to the Porter's stamp in bundle.json because we are | ||
| // storing these mixin records in a map, keyed by the mixin name. | ||
| Name string `json:"-"` | ||
|
|
||
| // Version of the mixin used in the bundle. | ||
| Version string `json:"version"` | ||
| } | ||
|
|
||
| type MixinRecords []MixinRecord | ||
|
|
||
| func (m MixinRecords) Len() int { | ||
| return len(m) | ||
| } | ||
|
|
||
| func (m MixinRecords) Less(i, j int) bool { | ||
| return m[i].Name < m[j].Name | ||
| } | ||
|
|
||
| func (m MixinRecords) Swap(i, j int) { | ||
| tmp := m[i] | ||
| m[i] = m[j] | ||
| m[j] = tmp | ||
| } | ||
|
|
||
| func (c *ManifestConverter) GenerateStamp(ctx context.Context) (Stamp, error) { | ||
| log := tracing.LoggerFromContext(ctx) | ||
|
|
||
|
|
@@ -86,11 +108,9 @@ func (c *ManifestConverter) GenerateStamp(ctx context.Context) (Stamp, error) { | |
| stamp.EncodedManifest = base64.StdEncoding.EncodeToString(rawManifest) | ||
|
|
||
| stamp.Mixins = make(map[string]MixinRecord, len(c.Manifest.Mixins)) | ||
| usedMixinsVersion := c.getUsedMixinsVersion() | ||
| for usedMixinName, usedMixinVersion := range usedMixinsVersion { | ||
| stamp.Mixins[usedMixinName] = MixinRecord{ | ||
| Version: usedMixinVersion, | ||
| } | ||
| usedMixins := c.getUsedMixinRecords() | ||
| for _, record := range usedMixins { | ||
| stamp.Mixins[record.Name] = record | ||
| } | ||
|
|
||
| digest, err := c.DigestManifest() | ||
|
|
@@ -122,9 +142,10 @@ func (c *ManifestConverter) DigestManifest() (string, error) { | |
| v := pkg.Version | ||
| data = append(data, v...) | ||
|
|
||
| usedMixinsVersion := c.getUsedMixinsVersion() | ||
| for usedMixinName, usedMixinVersion := range usedMixinsVersion { | ||
| data = append(append(data, usedMixinName...), usedMixinVersion...) | ||
| usedMixins := c.getUsedMixinRecords() | ||
| sort.Sort(usedMixins) // Ensure that this is sorted so the digest is consistent | ||
| for _, mixinRecord := range usedMixins { | ||
| data = append(append(data, mixinRecord.Name...), mixinRecord.Version...) | ||
| } | ||
|
|
||
| digest := sha256.Sum256(data) | ||
|
|
@@ -152,17 +173,21 @@ func LoadStamp(bun cnab.ExtendedBundle) (Stamp, error) { | |
| return stamp, nil | ||
| } | ||
|
|
||
| // getUsedMixinsVersion compare the mixins defined in the manifest and the ones installed and then retrieve the mixin's version info | ||
| func (c *ManifestConverter) getUsedMixinsVersion() map[string]string { | ||
| usedMixinsVersion := make(map[string]string) | ||
| // getUsedMixinRecords compare the mixins defined in the manifest and the ones installed and then retrieve the mixin's version info | ||
|
||
| func (c *ManifestConverter) getUsedMixinRecords() MixinRecords { | ||
| usedMixins := make(MixinRecords, 0) | ||
|
|
||
| for _, usedMixin := range c.Manifest.Mixins { | ||
| for _, installedMixin := range c.InstalledMixins { | ||
| if usedMixin.Name == installedMixin.Name { | ||
| usedMixinsVersion[usedMixin.Name] = installedMixin.GetVersionInfo().Version | ||
| usedMixins = append(usedMixins, MixinRecord{ | ||
| Name: installedMixin.Name, | ||
| Version: installedMixin.GetVersionInfo().Version, | ||
| }) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return usedMixinsVersion | ||
| sort.Sort(usedMixins) | ||
| return usedMixins | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a combination of name and version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bundle can only use a single mixin version at a time, so there can't be [email protected] and [email protected] for example, so just sorting by name will work. But who knows what the future holds! I can add version into the mix just in case we change things up later once mixins can be referenced bundles instead of embedded binaries.