
package io.quarkus.container.image.openshift.deployment;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;

import io.dekorate.kubernetes.decorator.NamedResourceDecorator;
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.openshift.api.model.BuildConfigSpecFluent;
import io.quarkus.deployment.util.FileUtil;

public class ApplyDockerfileToBuildConfigDecorator extends NamedResourceDecorator<BuildConfigSpecFluent<?>> {

    private final Path pathToDockerfile;

    public ApplyDockerfileToBuildConfigDecorator(String name, Path pathToDockerfile) {
        super(name);
        this.pathToDockerfile = pathToDockerfile;
    }

    @Override
    public void andThenVisit(final BuildConfigSpecFluent<?> spec, ObjectMeta meta) {
        try (InputStream is = new FileInputStream(pathToDockerfile.toFile())) {
            spec.withNewSource()
                    .withDockerfile(new String(FileUtil.readFileContents(is)))
                    .endSource()
                    .withNewStrategy()
                    .withNewDockerStrategy()
                    .endDockerStrategy()
                    .endStrategy();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

@@ -646,24 +646,482 @@
 uper(name);%0A
+        if (!pathToDockerfile.toFile().exists()) %7B%0A            throw new IllegalArgumentException(%0A                    %22Specified Dockerfile: '%22 + pathToDockerfile.toAbsolutePath().toString() + %22' does not exist.%22);%0A        %7D%0A        if (!pathToDockerfile.toFile().isFile()) %7B%0A            throw new IllegalArgumentException(%0A                    %22Specified Dockerfile: '%22 + pathToDockerfile.toAbsolutePath().toString() + %22' is not a normal file.%22);%0A        %7D%0A
         this

Add a more informative error message when Dockerfile is unavailable during s2i