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

Allow environment variables to be used in docker build argument #1912

Merged
merged 8 commits into from
Apr 30, 2019

Conversation

rahulwa
Copy link
Contributor

@rahulwa rahulwa commented Apr 3, 2019

Closes #1619 .

@googlebot
Copy link

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. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@rahulwa
Copy link
Contributor Author

rahulwa commented Apr 3, 2019

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@codecov-io
Copy link

codecov-io commented Apr 3, 2019

Codecov Report

Merging #1912 into master will decrease coverage by 0.05%.
The diff coverage is 54.83%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
pkg/skaffold/schema/latest/config.go 100% <ø> (ø) ⬆️
pkg/skaffold/build/local/docker.go 53.19% <0%> (-3.63%) ⬇️
pkg/skaffold/build/gcb/desc.go 94.28% <100%> (ø) ⬆️
pkg/skaffold/docker/parse.go 78.02% <57.14%> (-1.7%) ⬇️
pkg/skaffold/docker/image.go 71.42% <66.66%> (-0.7%) ⬇️
pkg/skaffold/build/gcb/docker.go 90.47% <66.66%> (-9.53%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 11f8a1b...1db54bd. Read the comment docs.

Copy link
Contributor

@balopat balopat left a 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

pkg/skaffold/docker/parse.go Outdated Show resolved Hide resolved
@rahulwa
Copy link
Contributor Author

rahulwa commented Apr 4, 2019

@balopat Added test and doc.

balopat
balopat previously requested changes Apr 4, 2019
Copy link
Contributor

@balopat balopat left a 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/schema/latest/config.go Outdated Show resolved Hide resolved
pkg/skaffold/docker/parse_test.go Show resolved Hide resolved
value = *buildArgs[key]
value, err = evaluateBuildArgsValue(*buildArgs[key])
if err != nil {
logrus.Errorf("unable to get value for build arg %q", key)
Copy link
Contributor

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.

@rahulwa
Copy link
Contributor Author

rahulwa commented Apr 5, 2019

I updated an integration test (examples/nodejs as it is a perfect candidate to use environment variable) to have this also, hoping that it passes, unable to run integration tests locally.

Signed-off-by: Rahul Sinha <[email protected]>
@balopat balopat added the kokoro:run runs the kokoro jobs on a PR label Apr 5, 2019
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label Apr 5, 2019
@rahulwa
Copy link
Contributor Author

rahulwa commented Apr 5, 2019

@balopat I guess now it is ready for review.

@balopat balopat added the kokoro:run runs the kokoro jobs on a PR label Apr 6, 2019
@rahulwa rahulwa requested a review from tejal29 as a code owner April 20, 2019 16:45
@rahulwa
Copy link
Contributor Author

rahulwa commented Apr 20, 2019

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?

@rahulwa
Copy link
Contributor Author

rahulwa commented Apr 25, 2019

Any progress on this @nkubala @balopat ?

@rahulwa
Copy link
Contributor Author

rahulwa commented Apr 26, 2019

@balopat @nkubala It's been a long time, can I do something to help here?

Copy link
Member

@tejal29 tejal29 left a 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

pkg/skaffold/build/gcb/docker_test.go Outdated Show resolved Hide resolved
pkg/skaffold/docker/image_test.go Show resolved Hide resolved
@tejal29 tejal29 added the kokoro:run runs the kokoro jobs on a PR label Apr 29, 2019
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label Apr 29, 2019
@tejal29
Copy link
Member

tejal29 commented Apr 29, 2019

I also ran the integration tests for you!

@tejal29 tejal29 self-assigned this Apr 29, 2019
@rahulwa
Copy link
Contributor Author

rahulwa commented Apr 29, 2019

Thank you very much @tejal29

@tejal29 tejal29 added the kokoro:run runs the kokoro jobs on a PR label Apr 30, 2019
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label Apr 30, 2019
@@ -4,6 +4,9 @@ build:
artifacts:
- image: gcr.io/k8s-skaffold/node-example
context: backend
docker:
buildArgs:
SCRIPT: "{{.SCRIPT_ENV}}"
Copy link
Member

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?

Copy link
Contributor Author

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.

@tejal29
Copy link
Member

tejal29 commented Apr 30, 2019

@rahulwa Thanks! started a new integration test run. If it passes, we will merge this in today!
Thank you!

@tejal29 tejal29 merged commit 24de7c3 into GoogleContainerTools:master Apr 30, 2019
@bpetit
Copy link

bpetit commented May 10, 2019

Thank you so much for this PR, but I can't get it work with skaffold v0.29.0 and this configuration:

apiVersion: skaffold/v1beta10
kind: Config
profiles:
  - name: test 
    activation:
      - env: SKAFFOLD_ENV=test
    build:
      artifacts:
        - image: "myimage"
          context: .
          docker:
            dockerfile: Dockerfile
            buildArgs:
              NPM_TOKEN: "{{.NPM_TOKEN}}"

For example with an environment variable like NPM_TOKEN, I get the variable string itself: "{{.NPM_TOKEN}}" in the docker build process.

And using

NPM_TOKEN: {{.NPM_TOKEN}}

Gives:

cannot unmarshal !!map into string

Am I missing something here ?

@khrisrichardson
Copy link
Contributor

@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.

@rahulwa
Copy link
Contributor Author

rahulwa commented May 11, 2019

Indeed, this is not working. Let me check it.
I am really sorry about it, it shouldn’t have occurred.

@rahulwa
Copy link
Contributor Author

rahulwa commented May 11, 2019

@bpetit @khrisrichardson One more setting is required to make it work, useDockerCLI has to true. Something like below works:

build:
  local:
    useDockerCLI: true

@tejal29 @balopat Do we need to update the docs to clarify this condition or it should run regardless of useDockerCLI option?

@bpetit
Copy link

bpetit commented May 14, 2019

Thank you for the hint. It does work.
Updating the documentation would be a good thing, in my opinion.

Have a nice day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Allow docker build arg to pick values up from the environment values also
9 participants