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

Clarify why multi-stage build works #21627

Closed
Reamer opened this issue Dec 6, 2018 · 9 comments

Comments

@Reamer
Copy link

commented Dec 6, 2018

Not really a problem, just a question. Why does multi-stage build works on openshift 3.10 and possible above? I've searched for a release-note, but I doesn't found anything. I'm happy that multistage builds are working, but I doesn't know if this permanent.

Version
# oc version
oc v3.10.0+0c4577e-1
kubernetes v1.10.0+b81c8f8
features: Basic-Auth GSSAPI Kerberos SPNEGO
# docker version
Client:
 Version:         1.13.1
 API version:     1.26
 Package version: docker-1.13.1-75.git8633870.el7.centos.x86_64
 Go version:      go1.9.4
 Git commit:      8633870/1.13.1
 Built:           Fri Sep 28 19:45:08 2018
 OS/Arch:         linux/amd64

Server:
 Version:         1.13.1
 API version:     1.26 (minimum version 1.12)
 Package version: docker-1.13.1-75.git8633870.el7.centos.x86_64
 Go version:      go1.9.4
 Git commit:      8633870/1.13.1
 Built:           Fri Sep 28 19:45:08 2018
 OS/Arch:         linux/amd64
 Experimental:    false
Steps To Reproduce
  1. Install Openshift
  2. Create a BuildConfig with multistage instructions and ImageStream for pushing to registry (Example: https://gist.github.com/Reamer/d1393d42249b328fc17e0cb6863a38f5)
Current Result

It works.

Expected Result

Related with #19198. It should not work.

Additional Information

Building the same Dockerfile directly on node with "docker build ..." doesn't work.

@Reamer Reamer changed the title Clarify why multi-stage build work Clarify why multi-stage build works Dec 6, 2018

@merusso

This comment has been minimized.

Copy link

commented Jan 12, 2019

I'm also mystified by this. Can anyone explain this?

@ofrzeta

This comment has been minimized.

Copy link

commented Jan 23, 2019

I tried it on OpenShift Enterprise 3.11 and it also worked. Here's a Gist with busybox and appropriate Entrypoint added, so you can rsh to the pods https://gist.github.com/ofrzeta/3bb08efc79f4c33fa267835b72bc96f6

@ofrzeta

This comment has been minimized.

Copy link

commented Jan 24, 2019

The build is run in the build container with a specific builder image (https://github.com/openshift/builder). Therefore it is not using the underlying Docker. When you debug the build pod (oc debug mytestbuild-1-build) and run the command openshift-docker-build --log-level=5 you can see that the tool detects the multi-stage configuration:

Starting Docker build from build config mytestbuild-1 ...
Detected multi-stage Dockerfile, image will be built with imageOptimizationPolicy set to SkipLayers

When you check the build pod configuration you can see the corresponding image registry URL:

image: registry.redhat.io/openshift3/ose-docker-builder:v3.11.59

I didn't manage to find the above string in a public source code file, though, but there's a reference to multi-stage handling in pkg/build/builder/common.go.

@bparees

This comment has been minimized.

Copy link
Contributor

commented Jan 30, 2019

@ofrzeta has mostly answered this. When we detect that the dockerfile is a multistage one, the dockerfile is built using https://github.com/openshift/imagebuilder/ instead of a traditional "docker build".

imagebuilder supports multistage builds, unlike the version of docker that openshift pre-reqs.

Note that when this happens you also get layer squashing implicitly, whether you want it or not.

In any case it's intentional and isn't going to go away. multistage builds will continue to work.

@bparees bparees closed this Jan 30, 2019

domq pushed a commit to epfl-idevelop/wp-ops that referenced this issue Feb 12, 2019

Dominique Quatravaux
Full path to pip and pyenv commands
For whatever reason, the PATH is not the same between Openshift and
"plain" `docker build`; this might have something to do with the fact
that according to openshift/origin#21627
Openshift doesn't, in fact, use `docker build`.

domq pushed a commit to epfl-idevelop/wp-ops that referenced this issue Feb 12, 2019

Dominique Quatravaux
Full path to pip and pyenv commands
For whatever reason, the PATH is not the same between Openshift and
"plain" `docker build`; this might have something to do with the fact
that according to openshift/origin#21627
Openshift doesn't, in fact, use `docker build`.

domq pushed a commit to epfl-idevelop/wp-ops that referenced this issue Feb 12, 2019

Dominique Quatravaux
Full path to pip and pyenv commands
For whatever reason, the PATH is not the same between Openshift and
"plain" `docker build`; this might have something to do with the fact
that according to openshift/origin#21627
Openshift doesn't, in fact, use `docker build`.

domq pushed a commit to epfl-idevelop/wp-ops that referenced this issue Feb 12, 2019

Dominique Quatravaux
Full path to pip and pyenv commands
For whatever reason, the PATH is not the same between Openshift and
"plain" `docker build`; this might have something to do with the fact
that according to openshift/origin#21627
Openshift doesn't, in fact, use `docker build`.

domq pushed a commit to epfl-idevelop/wp-ops that referenced this issue Feb 12, 2019

Dominique Quatravaux
Build jahia2wp as a standalone binary
* Use PyInstaller (https://www.pyinstaller.org/)

* Use a Docker multi-stage build (see
  https://docs.docker.com/develop/develop-images/multistage-build/)
  since that feature is now supported by
  OpenShift (openshift/origin#21627)

domq pushed a commit to epfl-idevelop/wp-ops that referenced this issue Feb 12, 2019

Dominique Quatravaux
Full path to pip and pyenv commands
For whatever reason, the PATH is not the same between Openshift and
"plain" `docker build`; this might have something to do with the fact
that according to openshift/origin#21627
Openshift doesn't, in fact, use `docker build`.
@sbose78

This comment has been minimized.

Copy link

commented Apr 2, 2019

@bparees , Does the openshift ci infra support multi-stage builds?

images: 
- from: os
  to: devconsole-operator
  dockerfile_path: Dockerfile

( https://github.com/redhat-developer/devconsole-operator/blob/master/Dockerfile )

caused the following error ..

Pulling image build-tools ...
error: build error: failed to pull image: repository docker.io/build-tools not found: does not exist or no pull access
2019/04/02 07:04:18 Ran for 4m56s
error: could not run steps: could not wait for build: the build devconsole-operator failed after 8s with reason PullBuilderImageFailed: Failed pulling builder image.

Pulling image build-tools ...
error: build error: failed to pull image: repository docker.io/build-tools not found: does not exist or no pull access

Wondering if I'm not writing my Dockerfile right?

@bparees

This comment has been minimized.

Copy link
Contributor

commented Apr 2, 2019

@sbose78 yes it supports multistage builds. what is "docker.io/build-tools"?

docker pull docker.io/build-tools
Using default tag: latest
Error response from daemon: pull access denied for build-tools, repository does not exist or may require 'docker login'

Seems like maybe you expected that value to be replaced with something?

@sbose78

This comment has been minimized.

Copy link

commented Apr 2, 2019

Thank you!

Here's what is causing that. My Dockerfile looks like:

FROM centos:7 as build-tools
....
...
..
FROM build-tools as builder
...
....
..

@bparees That's coming from https://github.com/redhat-developer/devconsole-operator/blob/master/Dockerfile

@bparees

This comment has been minimized.

Copy link
Contributor

commented Apr 2, 2019

@sbose78 can you point me to your ci-operator config? Do you have someone from our test platform team helping you get this setup?

@bparees

This comment has been minimized.

Copy link
Contributor

commented Apr 2, 2019

(we should also take this discussion elsewhere, this issue isn't the right spot for it. aos-devel is a good mailing list for it)

domq pushed a commit to epfl-idevelop/wp-ops that referenced this issue Apr 24, 2019

Dominique Quatravaux
Build jahia2wp as a standalone binary
* Use PyInstaller (https://www.pyinstaller.org/)

* Use a Docker multi-stage build (see
  https://docs.docker.com/develop/develop-images/multistage-build/)
  since that feature is now supported by
  OpenShift (openshift/origin#21627)

domq pushed a commit to epfl-idevelop/wp-ops that referenced this issue Apr 24, 2019

Dominique Quatravaux
Full path to pip and pyenv commands
For whatever reason, the PATH is not the same between Openshift and
"plain" `docker build`; this might have something to do with the fact
that according to openshift/origin#21627
Openshift doesn't, in fact, use `docker build`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.