openfaas / faas-cli

Official CLI for OpenFaaS
https://www.openfaas.com/
Other
794 stars 227 forks source link

[Feature Request] Fetch templates from configuration first #927

Open vnourdin opened 1 year ago

vnourdin commented 1 year ago

Expected Behaviour

When running faas-cli up with no template dir, it should fetch templates configured in the stack.yml before fetching official ones.

Current Behaviour

Fetch first from https://github.com/openfaas/templates.git then from configuration.

Why do you need this?

I work with a custom template, shared across projects, so it is hosted on a git repo. Thus, I need to pull it from my CI/CD in every project. Currently, if I run faas-cli up it pulls every official template for nothing. It doesn't take a lot of time, but it's wasting network and CI/CD resources.

Are you a GitHub Sponsor

No

Possible Solution

Fetch first configuration and check if all templates used are here before getting the "default" ones.

Workaround

I currently run faas-cli template pull to only pull my template, before running up. But I would find it more logical if up pull automatically configured templates before default ones.

Your Environment

alexellis commented 1 year ago

Hi @vnourdin

It seems like you edited the issue template and removed some key questions. Especially, why you think faas-cli should work that way.

Explaining and defending why you want us to make a custom change for you, is just as important as tell us what the change is that you desire. How is this affecting you? Why do you need the proposed change? This is your opportunity to convince us.

https://github.com/openfaas/faas-cli/blob/master/.github/ISSUE_TEMPLATE.md

Alex

alexellis commented 1 year ago

/add label: incomplete/issue-template

vnourdin commented 1 year ago

Hi @alexellis, thanks for your response, I updated the issue with the reason why I find this behavior problematic and also the workaround I use.

rgee0 commented 1 year ago

I had a quick look at this because it seemed familiar - I was recalling how the gateway priority operates.

This is how the template priority is determined:

https://github.com/openfaas/faas-cli/blob/35fcca5759d012cd0d4298ad34588c400c31d836/commands/priority.go#L38

And this is how the gateway priority is determined:

https://github.com/openfaas/faas-cli/blob/35fcca5759d012cd0d4298ad34588c400c31d836/commands/priority.go#L17

During build, and prior to the target template being determined, the yaml file has been parsed so the templates configured in the stack should be known....However, if the gateway approach was followed this would break the build where a stack had both bespoke and default templated functions.

So, if this was approved, I think we'd be looking to ascertain whether the stack contained any functions requiring the default templates and if it doesn't then skipping over the default template pull:

https://github.com/openfaas/faas-cli/blob/35fcca5759d012cd0d4298ad34588c400c31d836/commands/build.go#L165-L168

And relying only on the configuration template pull:

https://github.com/openfaas/faas-cli/blob/35fcca5759d012cd0d4298ad34588c400c31d836/commands/build.go#L200-L210

NikhilSharmaWe commented 1 year ago

@vnourdin @alexellis Is this issue resolved, since now we first check for configuration template pull and if it is not present then only pull the default template repo: https://github.com/openfaas/faas-cli/blob/master/commands/build.go#L167-L181

If something still needs to be done, please inform.

alexellis commented 1 year ago

Hi @NikhilSharmaWe I don't know if it's resolved.

Can you try it out and confirm?

faas-cli template store pull golang-middleware

faas-cli new --lang golang-middleware --prefix ttl.sh config1

Add to config1.yml

config:
  templates:
  - name: golang-middleware

Remove the templates:

rm -rf template

Then check :

alex@bq:/tmp/test$ faas-cli build -f config1.yml 
2023/05/31 14:54:34 No templates found in current directory.
2023/05/31 14:54:34 Attempting to expand templates from https://github.com/openfaas/templates.git
2023/05/31 14:54:35 Fetched 18 template(s) : [csharp dockerfile go java11 java11-vert-x node node12 node12-debian node14 node16 node17 node18 php7 php8 python python3 python3-debian ruby] from https://github.com/openfaas/templates.git
[0] > Building config1.
[0] < Building config1 done in 0.00s.
[0] Worker done.

Total build time: 0.00s
Errors received during build:
- language template: golang-middleware not supported, build a custom Dockerfile

alex@bq:/tmp/test$ 

Looks like it's still an issue, so yes will need a fix please.

Alex