Skip to content

Commit

Permalink
Merge pull request #43 from coveo/hash-source
Browse files Browse the repository at this point in the history
Hash source to allow long directory names
  • Loading branch information
julienduchesne authored Jan 14, 2019
2 parents 7bf8482 + f083294 commit eccc433
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type TGFConfigBuild struct {

func (cb TGFConfigBuild) hash() string {
h := md5.New()
io.WriteString(h, filepath.Base(filepath.Dir(cb.source)))
io.WriteString(h, cb.Instructions)
if cb.Folder != "" {
filepath.Walk(cb.Dir(), func(path string, info os.FileInfo, err error) error {
Expand Down Expand Up @@ -106,7 +107,7 @@ func (cb TGFConfigBuild) GetTag() string {
if cb.Tag != "" {
return cb.Tag
}
return fmt.Sprintf("%s-%s", filepath.Base(filepath.Dir(cb.source)), cb.hash())
return cb.hash()
}

// InitConfig returns a properly initialized TGF configuration struct
Expand Down
8 changes: 5 additions & 3 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestSetConfigDefaultValues(t *testing.T) {
assert.Equal(t, "RUN ls test", config.imageBuildConfigs[1].Instructions)
assert.Equal(t, "/abspath/my-folder", config.imageBuildConfigs[1].Folder)
assert.Equal(t, "/abspath/my-folder", config.imageBuildConfigs[1].Dir())
assert.Equal(t, "AWS-"+getHash(config.imageBuildConfigs[1].Instructions), config.imageBuildConfigs[1].GetTag())
assert.Equal(t, getHash([]string{"AWS", config.imageBuildConfigs[1].Instructions}), config.imageBuildConfigs[1].GetTag())

assert.Equal(t, "coveo/stuff", config.Image)
assert.Equal(t, "test", *config.ImageTag)
Expand Down Expand Up @@ -194,8 +194,10 @@ func randInt() int {
return random.Int()
}

func getHash(value string) string {
func getHash(values []string) string {
h := md5.New()
io.WriteString(h, value)
for _, value := range values {
io.WriteString(h, value)
}
return fmt.Sprintf("%x", h.Sum(nil))
}

0 comments on commit eccc433

Please sign in to comment.