diff --git a/cmd/image-builder/main.go b/cmd/image-builder/main.go index 6467d2499964..0a51c888e8f5 100644 --- a/cmd/image-builder/main.go +++ b/cmd/image-builder/main.go @@ -263,7 +263,7 @@ func buildInADO(o options) error { fmt.Println("Building image in ADO pipeline.") // Validate provided dockerfile for ADO usage - if err := validateDockerFile(o.dockerfile); err != nil { + if err := validateDockerFile(o.context, o.dockerfile); err != nil { return fmt.Errorf("invalid dockerfile provided: %w", err) } @@ -365,8 +365,9 @@ func buildInADO(o options) error { // validateDockerFile checks whether provided dockerfile // will run smoothly in ADO image-builder. // It return clear error message, including known issue urls. -func validateDockerFile(dockerFilePath string) error { +func validateDockerFile(context, dockerFile string) error { // Load Dockerfile + dockerFilePath := fmt.Sprintf("%s/%s", context, dockerFile) data, err := os.ReadFile(dockerFilePath) if err != nil { return fmt.Errorf("cannot load provided dockerfile: %w", err) diff --git a/cmd/image-builder/main_test.go b/cmd/image-builder/main_test.go index 8ea5cdf8474c..3fccbf5e4fff 100644 --- a/cmd/image-builder/main_test.go +++ b/cmd/image-builder/main_test.go @@ -735,14 +735,14 @@ func Test_validateDockerFile(t *testing.T) { t.Run(c.name, func(t *testing.T) { // Arrange tempDir := t.TempDir() - dockerFilePath := fmt.Sprintf("%s/out_file", tempDir) + dockerFilePath := fmt.Sprintf("%s/Dockerfile", tempDir) err := os.WriteFile(dockerFilePath, []byte(c.dockerfile), os.ModePerm) if err != nil { t.Errorf("failed to write dockerfile for test: %s", err) } // Act & Assert - err = validateDockerFile(dockerFilePath) + err = validateDockerFile(tempDir, "Dockerfile") if err != nil && !c.expectErr { t.Errorf("unexpected error occured: %s", err) }