Bug 1656755 - build config support for custom Dockerfile path
Summary: build config support for custom Dockerfile path
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: OpenShift Container Platform
Classification: Red Hat
Component: Build
Version: 4.1.0
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
: ---
Assignee: Ben Parees
QA Contact: wewang
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-12-06 09:26 UTC by Aleksandar Kostadinov
Modified: 2019-03-12 14:27 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-12-06 14:35:26 UTC
Target Upstream Version:


Attachments (Terms of Use)
oc explain output (2.51 KB, text/plain)
2018-12-06 09:26 UTC, Aleksandar Kostadinov
no flags Details

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.


Note You need to log in before you can comment on or make changes to this bug.