-
Notifications
You must be signed in to change notification settings - Fork 224
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
Accessing build-options after shrinkwrap for separate builders #817
Comments
Hi @ArcticXWolf This is something we can fix relatively quickly I would think, we just need to think about the options because this needs to be parsed by your container builder of choice. It will probably be that a custom bash script or process will need to load it and invoke kaniko. For openfaas-cloud we do something similar for build-args and have the target image name stored too, it's a JSON file. openfaas/openfaas-cloud@63a2f66 Alex |
Hi, thanks for the quick reply! Yes, a wrapper script is needed to parse that file. A JSON file would be great, it could contain even more metadata concerning the build. |
Hey, if it is okay, I would like to try and implement this. Go isn't my main language, so I might need some help/advice on style and tests later, but I would love to give it a shot (and I guess that's what Code reviews are for ^^). However we should specify some things:
EDIT: |
I would like to see you make a proof of concept for how you would parse and read the config file and then "send it to Kaniko" and bear in mind that other container builders exist. I appreciate the suggested solutions too, but let's first prove out that this is a viable approach before opening PRs or hacking on the code. |
@ArcticXWolf It's been just over a week since we heard from you, is this still something you need and want to work on? |
Ah, I was waiting for your input, because your answers were posted just 30 min ago. Sure, I have already a proof of concept, gonna type it out in detail later. |
Here is my kubernetes-job that I would use. The volume build-context would get populated with a shrinkwrap build context, that contains the build-args like an env-file. This shrinkwrap will be done via an init-container like @alexellis did in his blogpost mentioned above. [FUNCTION_NAME] has to be substituted for the name of the function we want to build (Can be done via envsubst for example). "docker-registry" is the domain name of the registry where the image gets push onto. There is a small problem with Kaniko, as it does not support spaces in their build-arg command line option, this can be temporarily solved by providing the build-arg via env-variables.
Thus a sample com.openfaas.docker.config file would look like:
The buildscript adds this to the environment and then passes the variable to the kaniko executor. The final command would be:
Of course this example is now quite specific to Kaniko because of the spaces-issue mentioned in the comments, however this should work for other builders too. To summarize my proposal:
Someone who wants to use it can use the following workflow:
|
If you know the builder that you want to use, we could just generate a shell command for it like we do for |
@LucasRoesler + @utsavanand2 we were discussing this topic on the call WRT to using buildkit in GitHub Actions. Do you have any suggestions on how to pass the image name / build args etc to an external builder after we've run "build --shrinkwrap"? |
There are so many ways that one can build a Docker image, I think it would be hard to support each and every one ourselves. But can we do something like what we have done with the inletsctl provisioner? Define a basic way of how we will get some commands for a particular builder (an interface), say starting with Docker Buildx, and other people can contribute for their builders of choice. |
what if we add an option to output the flags to stdout, for example With the For example, our build command is currently docker
build
<--no-cache>
<--squash>
<--build-arg http_proxy=?>
<--build-arg https_proxy=?>
<--build-arg ?=?>
<--label ?=?>
-t <name> so the user can say faas-cli build \
--shrinkwrap \
--show-flags \
--format=flags \
--rename='no-cache=nocache' \
--rename='squash=flatten' \
--rename='t=name' etc to further customize the output. |
How would we separate the output of the flags from the output of the faas-cli? Stdout/stderr? Or disable other output when the |
How about when user run |
That may be an option. The problem is that using shrinkwrap implies that you are not using a standard builder, it's a very non-standard and bespoke path, so without a customer for this it's difficult to design something that would work. |
When using the shrinkwrap option to generate a build context for separate builders like buildkit, kaniko or else, we copy all information about the build (Files + Dockerfile) to the ./build directory. However, for a successful build we also need the build-args and build-options which are fed into the docker build process (or in our case the kaniko process).
In our case, we use kaniko to build the function images inside our Kubernetes cluster with one-off-jobs. Our images need some additional packages installed, so we use the build options feature of our templates. The kaniko-job is very similar to the one @alexellis created for his blogpost. The problem is that we wont populate the ADDITIONAL_PACKAGES arg in the Dockerfile and thus the build fails.
So a local workaround would be to parse the template.yml and stack.yml ourselves, identify which function is being built currently and which options apply and then construct the build args. However this would be a lot of duplicated effort, as faas-cli already has this information.
A good idea would be to settle on a way to exchange that information with the builder, maybe adding it to a specific file in the build context?
Expected Behaviour
It should be possible to save the relevant build args for the current build during a shrinkwrap. This might take the form (to be discussed) of a file containing all build args as key-values:
Current Behaviour
During a shrinkwrap build only the files of a build context are copied. The build args are missing and thus cannot be restored for an external builder.
Possible Solution
See Expected Behaviour.
Context
We build function images via kaniko similar to the way @alexellis did it for his blogpost. There build options are sadly not usable with the builds.
Your Environment
faas-cli version
):Docker version: 19.03.8
Are you using Docker Swarm (FaaS-swarm ) or Kubernetes (FaaS-netes)?
FaaS-netes
Operating System and version (e.g. Linux, Windows, MacOS):
Ubuntu and Windows 10
The text was updated successfully, but these errors were encountered: