Skip to content
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

Fix validation of dockerfile #11011

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/image-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cmd/image-builder/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Loading