Bug 1656755

Summary: build config support for custom Dockerfile path
Product: OpenShift Container Platform Reporter: Aleksandar Kostadinov <akostadi>
Component: BuildAssignee: Ben Parees <bparees>
Status: CLOSED NOTABUG QA Contact: wewang <wewang>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 4.1.0CC: aos-bugs, lxia, nmoraiti, wewang, wzheng
Target Milestone: ---Keywords: UserExperience
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-12-06 14:35:26 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
oc explain output none

Description Aleksandar Kostadinov 2018-12-06 09:26:18 UTC
Created attachment 1512015 [details]
oc explain output

Description of problem:
In build config, when docker strategy is used, user can specify:
* source git repo
* context dir
* Dockerfile content

But user cannot specify Dockerfile path. There must be a file called `Dockerfile` inside contextDir. The file cannot be called `Dockerfile.rhel7`, `jenkins/Dockerfile.centos` or `prow/Dockerfile` for example.

Specifying Dockerfile content inside build config is not really useful, because changes to Dockerfile in code cannot be reflected automatically into the build config.

This is limiting how one project can have multiple Dockerfiles for different use cases.

As an example see verification-tests repo [1]. We have a pair of Dockerfiles in tools/jenkins/slaves, then another one tools/openshift-ci/Dockerfile.centos

All of these Dockerfiles require scripts tools/install_os_deps.sh and tools/hack_bundle.rb. Now trying to create a build configs in OCP, I first need to move all Dockerfiles to separate directories and set contextDir to the appropriate directory. But then the scripts fall out of the contextDir, thus they cannot be accessed by the build.

My workaround is to clone repo inside the Dockerfile by calling `git clone`. This is suboptimal though, because it makes testing Dockerfile locally before pushing the code to repo hardly possible without doing temporary changes to Dockerfile.

All other container build tools I know allow you to specify some custom PATH to Dockerfile while keeping context dir to the root of the repo. I understand this is a feature often used by many projects. I think OpenShift build config needs also to support this for a good user/dev experience on this platform.

[1] https://github.com/openshift/verification-tests

Version-Release number of selected component (if applicable):
v4.0.0-0.81.0

How reproducible:
always

Steps to Reproduce:
1. oc explain buildconfig.spec.source

Actual results:
* no option to specify Dockerfile PATH (see attached oc output)

Expected results:
* there is option to specify Dockerfile path within contextDir

Comment 1 Nikolaos Leandros Moraitis 2018-12-06 10:31:45 UTC
You can actually specify the dockerfile_path in your build strategy [1], and keep the context_dir to "."
Of course, you will have to have a `git_source` [2] to make the build to clone your repository. You don't need to specify `contextDir` and `Dockerfile` in your source.

[1] https://docs.openshift.com/container-platform/3.4/dev_guide/builds/build_strategies.html#dockerfile-path
[2] https://docs.openshift.com/container-platform/3.7/dev_guide/builds/build_inputs.html#source-code

Comment 2 Aleksandar Kostadinov 2018-12-06 14:35:26 UTC
Thank you very much. I looked mainly at `source` element and didn't notice all the options under `dockerStrategy` element. It works like a charm. Also thinking about it I now make sense out of having these under different elements.

btw very useful is also

> imageOptimizationPolicy: SkipLayers

So this is not actually a bug.