-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Allow environment variables to be used in docker build argument #1912
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
I signed it! |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
Codecov Report
@@ Coverage Diff @@
## master #1912 +/- ##
==========================================
- Coverage 56.03% 55.97% -0.06%
==========================================
Files 175 175
Lines 7615 7635 +20
==========================================
+ Hits 4267 4274 +7
- Misses 2940 2948 +8
- Partials 408 413 +5
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your first contribution!
- please add tests
- please add docs to BuildArgs in pkg/skaffold/schema/latest/config.go
@balopat Added test and doc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great to have an integration test for this as well - which would have shown that this is not working just yet: you will need to implement the env var expansion in the builder - not just the dependency resolution path: https://github.com/GoogleContainerTools/skaffold/blob/master/pkg/skaffold/docker/image.go#L326
pkg/skaffold/docker/parse.go
Outdated
value = *buildArgs[key] | ||
value, err = evaluateBuildArgsValue(*buildArgs[key]) | ||
if err != nil { | ||
logrus.Errorf("unable to get value for build arg %q", key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should fail the build if the template is invalid instead of just logging - please propagate back the err value through expandBuildArgs
, readDockerfile
up to GetDependencies
.
Signed-off-by: Rahul Sinha <[email protected]>
Signed-off-by: Rahul Sinha <[email protected]>
I updated an integration test ( |
Signed-off-by: Rahul Sinha <[email protected]>
@balopat I guess now it is ready for review. |
I tried to make changes according to master, I hope it's working. Unit tests are working, Can someone please run integration tests and check? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @rahulwa Sorry for the delay.
All looks good.
few nits
I also ran the integration tests for you! |
Thank you very much @tejal29 |
@@ -4,6 +4,9 @@ build: | |||
artifacts: | |||
- image: gcr.io/k8s-skaffold/node-example | |||
context: backend | |||
docker: | |||
buildArgs: | |||
SCRIPT: "{{.SCRIPT_ENV}}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am guessing you meant "{{.SCRIPT}} here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing it out.
@rahulwa Thanks! started a new integration test run. If it passes, we will merge this in today! |
Thank you so much for this PR, but I can't get it work with skaffold v0.29.0 and this configuration:
For example with an environment variable like NPM_TOKEN, I get the variable string itself: "{{.NPM_TOKEN}}" in the docker build process. And using
Gives:
Am I missing something here ? |
@bpetit I have the same issue, and noticed that the environment variable build argument is missing from the docker builder in https://skaffold.dev/docs/references/yaml/, but I'm hoping that was just an oversight. |
Indeed, this is not working. Let me check it. |
@bpetit @khrisrichardson One more setting is required to make it work, build:
local:
useDockerCLI: true @tejal29 @balopat Do we need to update the docs to clarify this condition or it should run regardless of |
Thank you for the hint. It does work. Have a nice day. |
Closes #1619 .