Closed LucasRoesler closed 4 years ago
I think this might fit well under the build options section? Thoughts?
I think that would require a refactor and a breaking change, unfortunately. Ithink the original implementation assumes that build options == ADDITIONAL_PACKAGES
, but I would have to double check
I thought we parsed them for the docker client to pass into the template dockerfile where the user has added the corresponding ARG. The ADDITIONAL_PACKAGES part is how the build_options are passed through & using it as a build-arg was a nice little bi-product of the implementation.
I'm moving this to openfaas/faas-cli, hope people don't mind.. just let me know otherwise 🛩
I would like to see if we can get it into build_options
, even if we write a migrator like @viveksyngh started looking into for the OpenFaaS YAML config file.
Should this be a map or an array? I guess it's really a KV?
I'm a fan of distributing the build options down to the end function yaml as much as possible. It's ideal if you have as much of the function definition close to the function and out of the template, which is a big benefit of having the additional packages wiring. If we had build_args available in the function.yml
file would there still be a benefit to having language level build flags (aside from backwards compatibility)?
Good question. In a sense the packages are maintained i.e. dev and mysql are not 1:1 but map to curated packages.
@rgee0
https://github.com/openfaas/faas-cli/issues/687#issuecomment-528030679
That's correct
We now have a use-case where we want to enable Go modules (some of the time) and @bmcstdio made a --build-arg
available for that. How do we move this forward?
Today build_options
looks like this:
build_options:
- ca-certificates
Taken from https://docs.openfaas.com/reference/yaml/#function-build-options
I don't know how heavily it's being used, but we could use a schema version change and bump it to be richer.
build_options:
bundles:
- ca-certs
build_args:
GO_MOD: 1
If you can provide a bit of guidance on implementation we might be able to help with this one.
From how I understand the conversation, i think @alexellis wants to introduce the following yaml structure
version: 1
provider:
name: openfaas
gateway: http://127.0.0.1:8080
functions:
url-ping:
lang: python
handler: ./sample/url-ping
image: alexellis2/faas-urlping
build_options:
bundles:
- ca-certs
build_args:
GO_MOD: 1
there are a couple important change in this structure
version
value. This would allow us to introduce a breaking change in the function spec. We would need to freeze the current spec as version: 0
and when version is missing we assume 0
. Ideally we should be just parsing to a single internal structure, just using a different parser/loader based on the version in the file. That way the internal code only needs to deal with a single structure.the build_options
would change from a list to a map
build_options:
bundles:
- ca-certs
build_args:
GO_MOD: 1
this change would allow us to expand the build time options to now include the build_args
map. This map would be translated to the docker --build-args
flags during the docker build. This would need an update here https://github.com/openfaas/faas-cli/blob/0ab4012784510381e2b90c031ede3d77197b10b1/builder/build.go#L125-L135 and here https://github.com/openfaas/faas-cli/blob/0ab4012784510381e2b90c031ede3d77197b10b1/builder/build.go#L239-L276
The CLI would need to be updated to read the build option packages from build_options.bundles
. See here in the source code https://github.com/openfaas/faas-cli/blob/0ab4012784510381e2b90c031ede3d77197b10b1/builder/build.go#L52
If we want to avoid a breaking change, then we need a new name for the build_options
. Perhaps we can deprecate build_options
over the next couple of months and replace it with build_config
field? Use the same structure described as above but then we need to worry less about the version
field.
I'm not seeing much usage in OSS repos: (if this search is working as expected) https://github.com/search?q=faas+build_options&type=Code
I'm leaning towards build_config
, we could also just extend the existing field:
From i.e.
build_options:
- ca-certificates
- build-essential
to:
build_options:
- ca-certificates
- "--build-arg GO111MODULE=on"
I think i would rather introduce a breaking change or use build_config
versus mixing the build options and flag parsing
So should we stay with:
build_options:
- ca-certificates
- build-essential
And not mix config and flag parsing? Did you reach consensus?
From the above conversation, I think @alexellis and @LucasRoesler are good with deprecating build_option
and enabling new build_config
option. The new yaml structure will look like:
version: 1
provider:
name: openfaas
gateway: http://127.0.0.1:8080
functions:
url-ping:
lang: python
handler: ./sample/url-ping
image: alexellis2/faas-urlping
build_config: # build_options changed to build_config
build_args: # would be translated to the docker --build-args flags during the docker build
GO_MOD: 1
@chrisrichard and I am working on this. I believe we understood the issue correctly. Please let us know otherwise or in case of any issue.
EDITED: after discussion with @chrisrichard
This was originally proposed in https://github.com/openfaas/faas-cli/issues/262 but was eventually implemented as flags on the
faas-cli
. This CLI behavior is documented here https://docs.openfaas.com/cli/build/#30-pass-custom-build-argumentsTo ensure reproducible and portable builds, we should support supplying build args via the YAML stack file.
My actions before raising this issue
Expected Behaviour
It should be possible for both of these commands to produce the same build
Current Behaviour
The only way to set build args is via tha CLI
Possible Solution
Allow specifying a map of build args per function in the stack yaml, for example