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

Multi stage build fails when referencing a previous stage with ARG #747

Closed
erandagan opened this issue Aug 22, 2019 · 1 comment · Fixed by #1160
Closed

Multi stage build fails when referencing a previous stage with ARG #747

erandagan opened this issue Aug 22, 2019 · 1 comment · Fixed by #1160
Labels
area/dockerfile-command For all bugs related to dockerfile file commands area/multi-stage builds issues related to kaniko multi-stage builds kind/bug Something isn't working kind/enhancement New feature or request priority/p2 High impact feature/bug. Will get a lot of users happy

Comments

@erandagan
Copy link

erandagan commented Aug 22, 2019

TLDR FROM <previous-stage-alias>-${SOME_ARG} fails Kaniko.

This issue presents a special case of #233 where the stage alias contains a reference to an ARG, a pattern supported by docker & BuildKit.

Actual behavior
A handy feature of Multistage builds is the ability to dynamically select a base stage in later stages:

ARG VARIANT

FROM scratch AS base
# Shared stuff over here...

FROM base AS base-dev
# Some dev only stuff here, like installing debugging tools.

FROM base AS base-prod
# Some prod only stuff here, like running Release builds or installing prod-only dependencies.

FROM base-${VARIANT}
# Final image dynamically selected. 
# Some final processing steps here, like ENTRYPOINT.

In the above example, when VARIANT is set to dev, the final image will inherit from base-dev. This pattern works great on stock Docker & BuildKit (which even skips unused branches, like base-prod, to speed up the build further). However, on Kaniko, the above build will fail

VARIANT=dev:

INFO[0003] Downloading base image base-dev              
2019/08/22 11:32:08 No matching credentials were found, falling back on anonymous
error building image: UNAUTHORIZED: authentication required; [map[Name:library/base-dev Action:pull Type:repository Class:]]

But, if we replace FROM base-${VARIANT} with a hardcoded FROM base-dev, everything is resolved correctly, though it renders the dynamic base picking useless.

So, it seems that Kaniko doesn't properly resolve stage aliases when they contain an ARG expression.

Expected behavior
Kaniko should correctly handle FROM <previous-stage-name>-${SOME_ARG} instructions.

To Reproduce
Steps to reproduce the behavior:

  1. Write a Dockerfile similar to the one above
  2. Attempt to build it with Kaniko (should fail)
  3. Attempt to build it using docker (should succeed)

Additional Information

  • Dockerfile
    As presented in the example above.
  • Build Context
    --build-arg VARIANT=dev
  • Kaniko Image (fully qualified with digest)
    gcr.io/kaniko-project/executor@sha256:78d44ec4e9cb5545d7f85c1924695c89503ded86a59f92c7ae658afa3cff5400
@tejal29 tejal29 added area/multi-stage builds issues related to kaniko multi-stage builds kind/enhancement New feature or request labels Aug 29, 2019
@tejal29
Copy link
Contributor

tejal29 commented Aug 29, 2019

@erandagan Currently we do not support evaluating args.
We do support resolving env varaibles in the stage name
https://github.com/GoogleContainerTools/kaniko/blob/master/pkg/dockerfile/dockerfile.go#L67

We need to do something similar something similar for Args.

Feel free to take a stab at it.

@cvgw cvgw added area/dockerfile-command For all bugs related to dockerfile file commands kind/bug Something isn't working labels Dec 23, 2019
@cvgw cvgw added the priority/p2 High impact feature/bug. Will get a lot of users happy label Jan 10, 2020
@tejal29 tejal29 added this to the GA Release v1.0.0 milestone Jan 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dockerfile-command For all bugs related to dockerfile file commands area/multi-stage builds issues related to kaniko multi-stage builds kind/bug Something isn't working kind/enhancement New feature or request priority/p2 High impact feature/bug. Will get a lot of users happy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants