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

[Feature Request] Fetch templates from configuration first #927

Open
vnourdin opened this issue Sep 12, 2022 · 6 comments · May be fixed by #965
Open

[Feature Request] Fetch templates from configuration first #927

vnourdin opened this issue Sep 12, 2022 · 6 comments · May be fixed by #965

Comments

@vnourdin
Copy link

vnourdin commented Sep 12, 2022

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

  • FaaS-CLI version: 0.14.6
@alexellis
Copy link
Member

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
Copy link
Member

/add label: incomplete/issue-template

@vnourdin
Copy link
Author

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
Copy link
Contributor

rgee0 commented Sep 25, 2022

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:

func getTemplateURL(argumentURL, environmentURL, defaultURL string) string {

And this is how the gateway priority is determined:

func getGatewayURL(argumentURL, defaultURL, yamlURL, environmentURL string) string {

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:

faas-cli/commands/build.go

Lines 165 to 168 in 35fcca5

templateAddress := getTemplateURL("", os.Getenv(templateURLEnvironment), DefaultTemplateRepository)
if pullErr := PullTemplates(templateAddress); pullErr != nil {
return fmt.Errorf("could not pull templates for OpenFaaS: %v", pullErr)
}

And relying only on the configuration template pull:

faas-cli/commands/build.go

Lines 200 to 210 in 35fcca5

if len(services.StackConfiguration.TemplateConfigs) != 0 && !disableStackPull {
newTemplateInfos, err := filterExistingTemplates(services.StackConfiguration.TemplateConfigs, "./template")
if err != nil {
return fmt.Errorf("already pulled templates directory has issue: %s", err.Error())
}
err = pullStackTemplates(newTemplateInfos, cmd)
if err != nil {
return fmt.Errorf("could not pull templates from function yaml file: %s", err.Error())
}
}

@NikhilSharmaWe
Copy link
Contributor

NikhilSharmaWe commented May 28, 2023

@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
Copy link
Member

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

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