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

feat: can now resolves args from all stages #1160

Conversation

JordanGoasdoue
Copy link
Contributor

Fixes #747

Description

feat: can now resolves args from all stages

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes unit tests
  • Adds integration tests if needed.

See the contribution guide for more details.

Reviewer Notes

  • The code flow looks good.
  • Unit tests and or integration tests added.

Release Notes

Kaniko now resolves args from all stages

@googlebot googlebot added the cla: yes CLA signed by all commit authors label Mar 26, 2020
@JordanGoasdoue JordanGoasdoue changed the title feat: can now resolves args from stage feat: can now resolves args from all stages Mar 26, 2020
@JordanGoasdoue JordanGoasdoue force-pushed the can-now-resolve-args-from-stage branch 3 times, most recently from 1c59b8e to a1a129d Compare March 26, 2020 23:24
@JordanGoasdoue JordanGoasdoue changed the title feat: can now resolves args from all stages Wip: feat: can now resolves args from all stages Mar 26, 2020
@JordanGoasdoue JordanGoasdoue force-pushed the can-now-resolve-args-from-stage branch from a1a129d to 428318b Compare March 27, 2020 00:08
@JordanGoasdoue JordanGoasdoue changed the title Wip: feat: can now resolves args from all stages feat: can now resolves args from all stages Mar 27, 2020
@JordanGoasdoue
Copy link
Contributor Author

@tejal29 I'm stuck here with this error on Travis CI :
https://travis-ci.org/github/GoogleContainerTools/kaniko/jobs/667502659?utm_medium=notification&utm_source=github status

+sudo minikube start --vm-driver=none
* minikube v1.9.0 on Ubuntu 18.04
* Using the none driver based on user configuration
X The none driver requires conntrack to be installed for kubernetes version 1.18.0
Makefile:62: recipe for target 'minikube-setup' failed
make: *** [minikube-setup] Error 78

@JordanGoasdoue JordanGoasdoue force-pushed the can-now-resolve-args-from-stage branch 3 times, most recently from 8c53b05 to bef5d35 Compare March 27, 2020 09:39
@JordanGoasdoue
Copy link
Contributor Author

JordanGoasdoue commented Mar 27, 2020

Something else to add @tejal29 :

Taking this Dockerfile :

ARG IMAGE="ubuntu:16.04"
ARG LAST_STAGE_VARIANT
FROM ${IMAGE} as base
RUN echo hi > /hi
FROM base AS base-dev
RUN echo dev >> /hi
FROM base AS base-prod
RUN echo prod >> /hi
FROM base-${LAST_STAGE_VARIANT}
RUN cat /hi

Using Docker

docker build . -t test-build-arg --build-arg IMAGE --build-arg LAST_STAGE_VARIANT=dev

Will use MetaArg ubuntu:16.04 for ARG IMAGE and :

docker build . -t test-build-arg --build-arg IMAGE="" --build-arg LAST_STAGE_VARIANT=dev

Will return error because ARG IMAGE shouldn't be blank

On Kaniko even :

docker run -v path/to/build:/build localhost:5000/executor-arg:latest --context=/build --no-push --build-arg IMAGE --build-arg LAST_STAGE_VARIANT="dev"

or

docker run -v path/to/build:/build localhost:5000/executor-arg:latest --context=/build --no-push --build-arg IMAGE="" --build-arg LAST_STAGE_VARIANT="dev"

Will use MetaArg ubuntu:16.04 for ARG IMAGE

I didn't find a way to do something 100% similar because
--build-arg IMAGE="" and --build-arg IMAGE react similarely on opts.BuildArgs by adding on it IMAGE=

Here it would be good if opts.BuildArgs wouldn't take IMAGE= on the case we are on --build-arg IMAGE scenario. But it could continue to do so on the case we are on --build-arg IMAGE="" scenario

This way i can then remove the check of empty string on opts.BuildArgs I did here : https://github.com/GoogleContainerTools/kaniko/pull/1160/files#diff-b651d79bcb38f3023c41dfb9e42f6236R108 , and it should work same way than Docker.

What do you think ?

@tejal29
Copy link
Member

tejal29 commented Mar 27, 2020

@JordanGoasdoue Looks like there was a new minikube release yesterday. I will either pin the minikube version to 1.18 or wait for minikube team to suggest

@tejal29
Copy link
Member

tejal29 commented Mar 27, 2020

@JordanGoasdoue Can you please rebase from master.

@JordanGoasdoue JordanGoasdoue force-pushed the can-now-resolve-args-from-stage branch from bef5d35 to 36dce3e Compare March 27, 2020 17:37
@JordanGoasdoue JordanGoasdoue force-pushed the can-now-resolve-args-from-stage branch from 36dce3e to ed883b9 Compare March 27, 2020 17:43
@tejal29
Copy link
Member

tejal29 commented Mar 27, 2020

Something else to add @tejal29 :

Taking this Dockerfile :

ARG IMAGE="ubuntu:16.04"
ARG LAST_STAGE_VARIANT
FROM ${IMAGE} as base
RUN echo hi > /hi
FROM base AS base-dev
RUN echo dev >> /hi
FROM base AS base-prod
RUN echo prod >> /hi
FROM base-${LAST_STAGE_VARIANT}
RUN cat /hi

Using Docker

docker build . -t test-build-arg --build-arg IMAGE --build-arg LAST_STAGE_VARIANT=dev

Will use MetaArg ubuntu:16.04 for ARG IMAGE and :

docker build . -t test-build-arg --build-arg IMAGE="" --build-arg LAST_STAGE_VARIANT=dev

Will return error because ARG IMAGE shouldn't be blank

On Kaniko even :

docker run -v path/to/build:/build localhost:5000/executor-arg:latest --context=/build --no-push --build-arg IMAGE --build-arg LAST_STAGE_VARIANT="dev"

or

docker run -v path/to/build:/build localhost:5000/executor-arg:latest --context=/build --no-push --build-arg IMAGE="" --build-arg LAST_STAGE_VARIANT="dev"

Will use MetaArg ubuntu:16.04 for ARG IMAGE

I didn't find a way to do something 100% similar because
--build-arg IMAGE="" and --build-arg IMAGE react similarely on opts.BuildArgs by adding on it IMAGE=

Here it would be good if opts.BuildArgs wouldn't take IMAGE= on the case we are on --build-arg IMAGE scenario. But it could continue to do so on the case we are on --build-arg IMAGE="" scenario

This way i can then remove the check of empty string on opts.BuildArgs I did here : https://github.com/GoogleContainerTools/kaniko/pull/1160/files#diff-b651d79bcb38f3023c41dfb9e42f6236R108 , and it should work same way than Docker.

What do you think ?

Sure, we can. But my big worry is we have always supported empty args for a while now and removing that might cause a backward incompatible change for existing users which use this ""

Before doing that, we need to take appropriate steps like

  1. First print a warning in N-1 release
  2. then follow up with release to change it to an error.

Since no one has yet complained about this i am ok to not address in this PR.
But for sure, in future, i could see ppl wanting to plum their docker build command as is and expect the same result. However, if you are keen, we could definitely add this in incremental steps.

@tejal29
Copy link
Member

tejal29 commented Mar 27, 2020

The PR passes here https://travis-ci.org/github/GoogleContainerTools/kaniko/builds/667817048?utm_medium=notification&utm_source=github_status

@JordanGoasdoue
Copy link
Contributor Author

Yes we could do that, but first we should see impact of such a change on the code, and yes it's definetely not urgent.

@tejal29
Copy link
Member

tejal29 commented Mar 30, 2020

re-opening for travis to pick up this PR.

@tejal29 tejal29 merged commit 2270ac0 into GoogleContainerTools:master Apr 14, 2020
dani29 pushed a commit to dani29/kaniko that referenced this pull request Apr 15, 2020
@dani29 dani29 mentioned this pull request Apr 15, 2020
4 tasks
@gabyx
Copy link
Contributor

gabyx commented Feb 2, 2022

Has this been tested with

FROM alpine:latest as base
RUN echo hi > /hi

FROM base AS base-dev
ARG NAME="1234"
RUN echo "dev:: $NAME" >> /hi

FROM base-dev as base-custom
ARG NAME
RUN echo "custom:: $NAME"
RUN cat /hi

Without specifying --build-arg NAME=...
It should work but it does not... $NAME is empty in base-custom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes CLA signed by all commit authors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multi stage build fails when referencing a previous stage with ARG
4 participants