openfaas / openfaas/faas-cli

Proposal: Template lock file and configurable template cache location

Open
#879 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
816
Forks
230
Avg merge
6h 4m
Merged PRs (30d)
1

Description

I have a rather big proposal, but one I have thought about for awhile and can implicitly fix this problems like #745

We should mimick some of the behavior we see with Go modules? Specifically, we should have the equivalent of a go.mod and a go.sum file. This could look like

  1. a templates.yaml, this has a format <template name>: <github repo>#<sha>
    • I picked yaml for the simplicity of parsing
  2. a templates.lock or templates.sum which has the format <github repo>#<sha> <hash>
  3. write the templates cache to a location dictated by OF_TEMPLATES_CACHE, defaulting to .openfaas/templates or something similar
  4. the template cache writes template contents to folders with the structure OF_TEMPLATES_CACHE/github.com/repo/template_name@hash
  5. (this is where we start overlapping with this issue) if the current folder has a template folder we can treat it like a "vendor" folder if it contains a special folder: templates.txt.
    if this file exists, we treat the subfolders as possible templates and we ignore this folder.
    if this file does not exist, we treat it as function content

this proposal does a couple of things

First, the files templates.yaml and templates.lock are easy to generate during faas-cli pull|build, just like Go does.

Second, this new cache scheme still allows for multiple versions of a template to be used between different projects.

Third, this also reduces the number of times a template needs to be copied to a machine.

Finally, we elimate any need to guess about colocated template folders, either they have an explicity templates.txt or not, which provides all of the needed context to decide if we should copy it into the build context, the user can easily control this.

It is important to note that this change is not backwards compatible, but we can achieve compatibility by incrementing the version in the stack.yaml . We would have version: 1.0 which stays exactly as it is today and version: 2.0 which would incidate to the CLI the new template behavior.

Version 2 would also remove the configuration.templates section because this capability is implemented by the new templates.yaml|lock

This also means we can remove the gitignore for the templates folder (if it exists) is user created.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the existing template handling used by faas-cli pull and build, including stack.yaml and its configuration.templates section. Compare that behavior with the proposed templates.yaml, templates.lock or templates.sum, OF_TEMPLATES_CACHE, and templates.txt rules. Done would require an agreed version-2 design, backward-compatibility behavior, cache layout, and documented generation and build-context semantics.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, yaml
Domain
build-system, cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.