Skip to content

Commit

Permalink
Merge pull request #45 from coveo/remove-bad-characters-from-tags
Browse files Browse the repository at this point in the history
Remove potentially bad characters from docker tags
  • Loading branch information
julienduchesne authored Jan 31, 2019
2 parents 827cad5 + 6d91029 commit d983b66
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,12 @@ func (cb TGFConfigBuild) Dir() string {

// GetTag returns the tag name that should be added to the image
func (cb TGFConfigBuild) GetTag() string {
tag := filepath.Base(filepath.Dir(cb.source))
if cb.Tag != "" {
return cb.Tag
tag = cb.Tag
}
return filepath.Base(filepath.Dir(cb.source))
tagRegex := regexp.MustCompile(`[^a-zA-Z0-9\._-]`)
return tagRegex.ReplaceAllString(tag, "")
}

// InitConfig returns a properly initialized TGF configuration struct
Expand Down
24 changes: 24 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,30 @@ func TestSetConfigDefaultValues(t *testing.T) {
assert.Nil(t, config.ImageVersion)
}

func TestWeirdDirName(t *testing.T) {
tempDir, _ := ioutil.TempDir("", "bad@(){}-good-_.1234567890ABC")
currentDir, _ := os.Getwd()
os.Chdir(tempDir)
fmt.Println(tempDir)
defer func() {
os.Chdir(currentDir)
os.RemoveAll(tempDir)
}()
testSSMParameterFolder := fmt.Sprintf("/test/tgf-%v", randInt())
testTgfConfigFile := fmt.Sprintf("%s/.tgf.config", tempDir)
tgfConfig := []byte(String(`
docker-image: coveo/stuff
docker-image-build: RUN ls test2
docker-image-build-folder: my-folder
`).UnIndent().TrimSpace())
ioutil.WriteFile(testTgfConfigFile, tgfConfig, 0644)

config := InitConfig()
config.setDefaultValues(testSSMParameterFolder)

assert.True(t, strings.HasPrefix(config.imageBuildConfigs[0].GetTag(), "bad-good-_.1234567890ABC"))
}

func TestParseAliases(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit d983b66

Please sign in to comment.