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

Proposal: support docker build args via "faas-cli build" flags. #325

Closed
hypnoglow opened this issue Feb 16, 2018 · 4 comments
Closed

Proposal: support docker build args via "faas-cli build" flags. #325

hypnoglow opened this issue Feb 16, 2018 · 4 comments

Comments

@hypnoglow
Copy link

The proposal is to add a possibility to pass build args to an underlying "docker build" process. This is kind of related to #262 but I propose to add command-line flags to "faas-cli build" command.

Expected Behaviour

  1. Define a build arg in Dockerfile.

     FROM golang:1.9.2 as builder
     ARG FOO=defaultValue
     RUN echo $FOO
     
  2. Run faas-cli build -f my-func.yaml --args FOO=bar. The FOO argument is actually passed to docker build command as --build-arg flag.

  3. Output:

     faas-cli build -f my-func.yml --args FOO=bar
     2018/02/16 16:47:54 No templates found in current directory.
     2018/02/16 16:47:54 Attempting to expand templates from https://github.com/openfaas/templates.git
     2018/02/16 16:47:55 Fetched 11 template(s) : [csharp dockerfile go go-armhf node node-arm64 node-armhf python python-armhf python3 ruby] from https://github.com/openfaas/templates.git
     [0] > Building my-func.
     Building: my-func with Dockerfile. Please wait..
     Sending build context to Docker daemon  86.02kB
     Step 1/3 : FROM golang:1.9.2 as builder
      ---> 138bd936fa29
     Step 2/3 : ARG FOO=defaultValue
      ---> Running in 88983c7e27d7
     Removing intermediate container 88983c7e27d7
      ---> ee0d598870c7
     Step 3/3 : RUN echo $FOO
      ---> Running in 751d526d0828
     bar
     Removing intermediate container 751d526d0828
      ---> 273e36de5a09
     Successfully built 273e36de5a09
     Successfully tagged my-func:latest
     Image: my-func built.
     

Current Behaviour

Docker build args are not supported.

Context

This can solve issues like this, if we can use build arguments in openfaas templates.

@alexellis
Copy link
Member

alexellis commented Feb 18, 2018

Hi Igor,

I've read your proposal and compared it to #262 - as far as I can tell it's a duplicate but you specify wanting to use CLI arguments and @itscaro specifies using YAML.

If we make this change then it will need to be supported via the CLI and via YAML so I'm going to close your issue and reference it on #262. Please feel free to mention your request for CLI support there or +1 the issue.

My concern in passing arbitrary build flags to the OpenFaaS template is the following:

  • the template becomes less deterministic
  • more opportunities for hard-to-reproduce bugs
  • different behaviour on one machine vs another depending on flags
  • tightly couples the function to the underlying Docker build
    • the users now need white-box knowledge of what is inside the templates in order to know what build-args to pass
    • users are likely to want to change the available build-args to make the templates more configurable, this will add complexity to the standard templates

With those concerns in mind we should be careful about injecting run-time parameters into the Docker build. Maybe if we take a step back and analyze the problem that this acts to solve we could consider whether other approaches exist?

@hypnoglow
Copy link
Author

hypnoglow commented Feb 19, 2018

Hmm, from one point of view these are definitely interesting concerns that should be analyzed.

But, I think all these decisions were already made when docker implemented build arguments feature. Refs: 1, 2 and others. And, as openfaas uses docker as a container implementation, but tries to abstract it away, maybe can we have a specific group of CLI flags that are related to docker and passed directly to the docker CLI?

As an example that comes to mind: minikube start supports --container-runtime flag (the container runtime to be used) and --docker-opt flag (Specify arbitrary flags to pass to the Docker daemon. (format: key=value)). I'm not saying that this is the only right decision. But at least it provides the flexibility in docker usage.

Another weird thing to notice is that openfaas CLI already supports docker-specific flags like --no-cache and --squash.

Just thinking out loud.

@alexellis
Copy link
Member

Derek close: duplicate

@derek derek bot closed this as completed Mar 1, 2018
@alexellis
Copy link
Member

@hypnoglow let's continue discussion on the original issue.

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

No branches or pull requests

2 participants