Skip to content

Commit

Permalink
Resolves #1124: Always scan the repository for provided scripts
Browse files Browse the repository at this point in the history
Whether the base image provides the scripts or not, the repository can supply override scripts.
Removes the expectation/need of a location specified in the image.
  • Loading branch information
cuppett committed Aug 11, 2023
1 parent 980ca19 commit 0397929
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
17 changes: 7 additions & 10 deletions pkg/build/strategies/dockerfile/dockerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,8 @@ func (builder *Dockerfile) CreateDockerfile(config *api.Config) error {
artifactsDestDir := filepath.Join(getDestination(config), "artifacts")
artifactsTar := sanitize(filepath.ToSlash(filepath.Join(defaultDestination, "artifacts.tar")))
// hasAllScripts indicates that we blindly trust all scripts are provided in the image scripts dir
imageScriptsDir, hasAllScripts := getImageScriptsDir(config)
var providedScripts map[string]bool
if !hasAllScripts {
providedScripts = scanScripts(filepath.Join(config.WorkingDir, builder.uploadScriptsDir))
}
imageScriptsDir := getImageScriptsDir(config)
providedScripts := scanScripts(filepath.Join(config.WorkingDir, builder.uploadScriptsDir))

if config.Incremental {
imageTag := util.FirstNonEmpty(config.IncrementalFromTag, config.Tag)
Expand Down Expand Up @@ -424,18 +421,18 @@ func getDestination(config *api.Config) string {

// getImageScriptsDir returns the directory containing the builder image scripts and a bool
// indicating that the directory is expected to contain all s2i scripts
func getImageScriptsDir(config *api.Config) (string, bool) {
func getImageScriptsDir(config *api.Config) string {
if strings.HasPrefix(config.ScriptsURL, "image://") {
return strings.TrimPrefix(config.ScriptsURL, "image://"), true
return strings.TrimPrefix(config.ScriptsURL, "image://")
}
scriptsURL, _ := util.AdjustConfigWithImageLabels(config)
if strings.HasPrefix(scriptsURL, "image://") {
return strings.TrimPrefix(scriptsURL, "image://"), true
return strings.TrimPrefix(scriptsURL, "image://")
}
if strings.HasPrefix(config.ImageScriptsURL, "image://") {
return strings.TrimPrefix(config.ImageScriptsURL, "image://"), false
return strings.TrimPrefix(config.ImageScriptsURL, "image://")
}
return defaultScriptsDir, false
return defaultScriptsDir
}

// scanScripts returns a map of provided s2i scripts
Expand Down
5 changes: 1 addition & 4 deletions pkg/build/strategies/dockerfile/dockerfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,10 @@ func TestGetImageScriptsDir(t *testing.T) {
},
}
for _, tc := range cases {
output, hasScripts := getImageScriptsDir(tc.Config)
output := getImageScriptsDir(tc.Config)
if output != tc.ExpectedDir {
t.Errorf("Expected image scripts dir %s to be %s", output, tc.ExpectedDir)
}
if hasScripts != tc.HasAllScripts {
t.Errorf("Expected has all scripts indicator:\n%v\nto be: %v", hasScripts, tc.HasAllScripts)
}
}
}

Expand Down

0 comments on commit 0397929

Please sign in to comment.