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 Req] Template store to allow custom sub-directory path to "template" #789

Open
justinfx opened this issue Apr 6, 2020 · 3 comments

Comments

@justinfx
Copy link

justinfx commented Apr 6, 2020

When hosting a custom template within a repository, it is a requirement that the templates live in a "template" folder at the root of the project. And the template store json can only reference the repository, following the expectation that templates live within that root folder.

It would be very flexible to allow a project to additionally host openfaas templates, and to choose where to place these within a sub-directory path. The template store should then also be able to describe the optional template path value.

I'm looking to see if this is a desirable feature, what aspects would need to be changed to be accepted, and whether there was an initial thought or effort to support this, or if I should contribute to it?

Expected Behaviour

A project that also provides openfaas templates should be able to host templates from:

projectRoot/
    docs/
    source/
        go_stuff
        python_stuff
        java_stuff
    deploy/
        faas/
            templates/
                <custom templates here>
            templates.json

template.json

[
  {
    "template": "my-template",
    "platform": "x86_64",
    "language": "Go",
    "source": "my-company",
    "description": "A custom template",
    "repo": "https://gitlab.company.com/group/proj",
    "path": "deploy/faas/templates",
    "official": "false"
  }
...

Current Behaviour

faas-cli has a hard-coded requirement that there be a root-level "template" directory in the repository, and a store can only define the repository:

projectRoot/
    docs/
    source/
        go_stuff
        python_stuff
        java_stuff
    templates/
        <custom templates here>
    templates.json

template.json

[
  {
    "template": "my-template",
    "platform": "x86_64",
    "language": "Go",
    "source": "my-company",
    "description": "A custom template",
    "repo": "https://gitlab.company.com/group/proj",
    "official": "false"
  }
...

Possible Solution

If a "path" value could be provided in a template store, it could be passed into updated api functions in faas-cli/commands package when fetching templates. The default would still be the root level "template" directory.

Context

I am working to integrate openfaas at my company, behind a restrictive proxy. My solution to providing openfaas functions and microservices is to customise the templates to use our internal container image proxy/repo, and various other custom image tweaks. I would like to host these templates within a larger project as opposed to creating a new repo solely for the templates. It would be nice for the faas-cli and template store logic to support this workflow.

Your Environment

  • FaaS-CLI version ( Full output from: faas-cli version ): 0.12.2

  • Docker version ( Full output from: docker version ): 19.03.08

  • Are you using Docker Swarm (FaaS-swarm ) or Kubernetes (FaaS-netes)? Kubernetes / faas-netes

  • Operating System and version (e.g. Linux, Windows, MacOS): linux

@justinfx
Copy link
Author

justinfx commented Apr 7, 2020

I have a working local branch with this feature, should it be something that is considered valuable; I could submit a patch.

The changes affect the template store pull / list / describe commands, by allowing a template store to consider an optional "path" to use instead of "./template" at the root of the repo.

The stack yaml support is updated to also accept a "path" string field in addition to the "name" and "source" of a template.

The template pull command is also updated to allow an optional path arg after the repository.

faas-cli template pull 'https://gitlab.company.com/group/project#branch' path/to/template

justinfx added a commit to justinfx/faas-cli that referenced this issue Apr 7, 2020
…s#789)

To support hosting templates within the directory structure of an existing project, we need to allow for custom paths to the root template directory instead of requiring a separate repo with a root level template directory.

Signed-off-by: Justin Israel <[email protected]>
@alexellis
Copy link
Member

What's the issue with using a templates repo?

@justinfx
Copy link
Author

justinfx commented Oct 9, 2020

It would be more convenient and align with our build and deploy system to have the templates live and be versioned with the project for which they are being used.
I figure since this doesn't break existing behaviour and makes it possible to have a monorepo, that the flexibility would be a benefit and enable users to deploy templates in different ways.

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

Successfully merging a pull request may close this issue.

2 participants