Commit Graph

289 Commits

Author SHA1 Message Date
Luke Kingland e918f74b9e
feat!: invoke (#705)
* feat!: rename 'emit' to 'invoke' and default to local

This commit renames 'func emit' command to 'func invoke' and makes the
default behavior to send an event to localhost. The special '--sink'
value 'local' is changed to 'cluster' to indicate that the function
should be invoked on the cluster instead of locally. All other behavior
has remained the same.

BREAKING CHANGE

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: update commands.md doc

Signed-off-by: Lance Ball <lball@redhat.com>

* squash: change Emitter interface to Invoker

Changes Emit() to Send() in the (now named) Invoker interface, and changes
Emit() to Invoke() in the client.

BREAKING CHANGE

Signed-off-by: Lance Ball <lball@redhat.com>

* squash: use a common Invoker interface for HTTP and events

Signed-off-by: Lance Ball <lball@redhat.com>

* checkpoint

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: change Emitter to EventInvoker

Signed-off-by: Lance Ball <lball@redhat.com>

* Invoke v2 Draft

* feat: client invoke function

* static invoke defaults and methods

* remove assimilated invoker package

* includes an ignored .func directory on create

* Instances manager with local and remote defaults

Funciton Info is now Instance, representing a Function in a given
environment.

Describing a Function instance is now Instances().Get(f, environment)

Moves Runner to be async with a Stop method to enable returning runtime pid
and port for persisting.

Instances now have a place for primary Route in addition to all routes slice

Running Functions write PID and Port to .func

* cascading targets: local vs remote vs ad-hoc endpoint

* runner start signals and cancel cleanup

* return run on context done or err on channel

* async runner

Refactors the image runner to start the container asynchronously,
reporting back the port on which it started.  Errors are communicated
back via a provided channel and stop is signaled using context
cancelation.

* pid neither required nor available

* add withTransport option

Incorporates addition of custom transport of the emitter into the
renamed version invoker. Flag and help text cleanup.  Re-additionof the
Info accessor.

* schema now includes invocation data

* loop build msg

* run jobs

Externally exposed port is now chosen based on availability, with 8080
preferred and falling back to an os-chosen open port.
The Client Run method is now async, returning the port assigned to the
running Function, a stop/cleanup function and a runtime errors channel.
The Runner is internally divided into the runner and its started Jobs.

* job metadata

Extracts job metadata tracking to a Job object in the core,
Handles multiple instances of the same Function by creating a single
file for each instances in .func/instances/<port>

* remove superfluous error types and flag bindings

* feat: enable invoke target remote

* feat: preferentially invoke local, remote if running

* feat: read --file for invoke

* feat: invoke confirm prompts

* fixup cli tests

- Updates to handle asynchronous Runner
- Standardize on the naming convention for selective running

* docker runner tests and lint errors

* test refactor

* feat: invoke format override

* comments, spelling and other cleanup

* invoke command doc

* feat: invoke format interactive option

* rename runjob.go to job.go

* e2e test flag update

* test naming homoginization

* silence build activity messages when verbose

* test debugging

* code review updates

- return Job from Client.Run rather than constituent members
- Treat .gitignore as contentious, punting on feature to mutate if
  extant.
- docs wording changes
- add invocation format to pertinent manifest.yaml files

* help text spelling etc.

Co-authored-by: Lance Ball <lball@redhat.com>
2022-01-21 12:04:05 -08:00
Luke Kingland 4504b21369
src: simplify go templates (#741) 2022-01-10 13:59:12 -08:00
Fabian Lopez 866728dbc0
mitigate log4j dependency vulnerability (#723)
* mitigate log4j dependency vulnerability

* bump log4j version to 2.16.0

* update pkged.go

* manually fix pkged.go annotation

* Revert "manually fix pkged.go annotation"

This reverts commit dc67a48185.

* fix pkged.go

* podman test trigger

* e2e test trigger
2021-12-16 03:32:17 -08:00
Lance Ball d7cfe6ead7
feat: add telemetry to Node.js and TypeScript function templates (#719)
* feat: add telemetry to Node.js and TypeScript function templates

This commit pulls in the latest version of faas-js-runtime which supports
metrics exposed at /metrics. Also, concidentally, adds CloudEvent batch
support, so Node.js and TypeScript functions may be invoked with a set of
more than one event simultaneously.

Fixes: https://github.com/knative-sandbox/kn-plugin-func/issues/710

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: regenerate and commit pkged.go

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: remove stray go.sum and update pkged.go file

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: try to make knative code style happy

Signed-off-by: Lance Ball <lball@redhat.com>

* Revert "fixup: try to make knative code style happy"

This reverts commit 91d625be7b.

* fixup: update package-lock.json files

Signed-off-by: Lance Ball <lball@redhat.com>
2021-12-15 03:00:29 -08:00
Matej Vasek 834e8ae46c
fix: use specific version of paketo builder (#670)
For some reason latest version is not working with node.

Signed-off-by: Matej Vasek <mvasek@redhat.com>
2021-11-18 14:40:22 -08:00
Lance Ball 3935747b91
chore: use buildEnvs instead of custom buildpack (#663)
The TypeScript templates have been using a small buildpack from the boson
project. The sole purpose of the buildpack was to run the `npm run build`
command so that a TypeScript project would be transpiled before deployment.

The Paketo buildpack for Node.js supports using environment variables at
build time to enable additional scripts to be run, such as `build`. Prior
to the addition of `buildEnvs` by @salaboy in
https://github.com/knative-sandbox/kn-plugin-func/pull/646 it was not
possible to set this value for TypeScript projects. That new feature allows
us to stop using the small buildpack from boson.

Signed-off-by: Lance Ball <lball@redhat.com>
2021-11-16 17:37:33 -08:00
salaboy c70a21e9a4
feat: make SpringBoot template SpringNative by default (#649)
* move springboot template to use springnative

* improving templates to use spring-cloud-deps and ce-type routing

* updating readmes

* removing trailing spaces and adding newline at EOF
2021-11-16 10:31:53 -08:00
Shashank Sharma dc0f0c1289
MethodNotAllowed for rust cloudevents template (#639) 2021-11-08 11:32:42 -08:00
Lance Ball c810efc7a4
fix: remove stray manifest.yaml files (#628)
Fixes: https://github.com/knative-sandbox/kn-plugin-func/issues/626

Signed-off-by: Lance Ball <lball@redhat.com>
2021-11-05 12:07:12 -07:00
Lance Ball e319ea3b62
feat: add support for manifest.yaml at repo/language/template levels (#558)
* feat!: add support for manifest.yaml and runtime.yaml

BREAKING CHANGE
This commit adds the concepts of a manifest.yaml file at the top level
of a template repository, and a runtime.yaml file for each language/runtime
within the repository. Prior to this, repository metadata was primarily
restricted to information that could be gleaned from the file system, such
as the directory name used as the Name.

A manifest.yaml file contains a Name, URL, Version, and a list of supported
runtimes; and if all of the runtimes expose the same health endpoints, these
can be set here.

Within a runtime directory, there may exist a runtime.yaml file which allows
language pack providers to set the health endpoints, overriding the values
set in manifest.yaml, as well as Builders and Buildpacks.

This change removes support for a builders.yaml file in a runtime/template
directory, as this was guaranteed to be redundant with the builders.yaml
file in a sibling template directory. The choice was to move these up a
level to runtime/runtime.yaml.

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: bump go version for unit tests

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: using go 1.16 now requires 'go mod tidy'
See: https://golang.org/doc/go1.16

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: restore support for directory traversal

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: whitespace linting

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: update func_yaml-schema.json

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: spelling errors caught by reviewdog

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: use os.ReadDir

Signed-off-by: Lance Ball <lball@redhat.com>

* squash: restore project creation from remote repos

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: remove billyFilesystem

Signed-off-by: Lance Ball <lball@redhat.com>

* doc: expand on language pack documentation

Adds more detail around how language packs can be provided by third
parties, and the expected structure and metadata required.

Fixes: https://github.com/knative-sandbox/kn-plugin-func/issues/452

Signed-off-by: Lance Ball <lball@redhat.com>

* doc: update language pack documentation

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: cleanup deps

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: cleanup deps - again

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: reviewdog whitespace cleanup

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: custom repo template listing

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: bump go version for integration tests

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: adjust test-templates repo uri for e2e

Signed-off-by: Lance Ball <lball@redhat.com>

* fix: don't fail when extended templates don't support a given runtime

Signed-off-by: Lance Ball <lball@redhat.com>

* src: repo and template type hierarchy

As the client API increases in complexity, upgrading to a more correct
type hierarchy for the object managers serves to keep things clean.  In
this update, the Repository and Templates manager now use constructors
with private members, including a backreference to the root Client
object, which provides the mangers with full access to the current
client instance API for implementing their (growing) features.

* src: template manager writes

The templateWriter struct has now been upgraded to integrate with the
newly-added type system which includes a Templates Manager by adding a
.Write method which writes a template at the given location.  This
encapsulation of the write functionality moves us towards having a
cleaner abstraction atop writing any template to disk from any
repository.

In addition, the "Get" prefix was removed from many accessor methods, as
this is standard a Go idiom.

* src: templates write including denormalize

- merges templateWriter into templates manager
- denormalization of builders, health endpoints etc. made part of .Write
- write logic now works on a Template rather than string paths etc

The templates manager can now write out a template given a function directy.
Included internnaly to write is the denormalization logic, which is now closer
to where it is used, which should improve cohesion and decouple the template
implementation detail from the Client. Also moves the write logic closer to the
template itself, with the expectation the same will happen for functions when
Config and Function are merged.

* src: vendor

* src: merge manifests into domain model

In general, the manifests sytsem is merged more tightly into the overall
system while also expalding it to use a path to templates to avoid
having to create a full filesystem shadow-copy in yaml. Preserves
backwards-compatiblity by keeping the base case a yaml-free repo of only
templates.  Creaets a hierarchical inheritance from repository to
runtime to template for builders, endpoints etc.  whcih allows for the
manifest within templates to be a first-class citizen, though its use
will be rather rare.  Some more in-depth explanations of the more
substantive changes are as follows:

- Merges Manifest with Repository

The Manifest structure is essentially a serialized Repository, so they
are now the same object.

- Converts repo URL to a calculated field

The URL is informative and entirely dependent on the current state of
the repo, so it should be calculated to avoid confusion and avoid being
serialized to the manifest.

- Merge FunctionTemplate with Template

The struct being serialized here is a Template, so they are now the same object

- Extracts new "BuildConfig" embedded struct

The Builders and Buildpacks members are shared between Repository,
Runtime and Template, so they are now an embedded stuct in the same
manner as HealthEndpoints.

- yaml 'inline' declaration for embedded structs

The HealthEndpoints and other embedded structs were not actually being
read from their configs because of a nuance of yaml which (in contrast
to json unmarshallers) requires the `,inline` tag on the struct member
to trigger inclusion in decode.

- Replaces Repository's runtimes member with templates

While it is true that on disk templates are subdivided into their
effective runtime, this is for ease of development.  The logical
structure is: repositories have templates.  Templates are applicabe to
runtimes.  Therefore the correct API is to have templates a direct
member of repository but requiring a runtime filter for access.

- Use repository templates path instead of full list

The goal is to support the use of repositories which contain more than
just templates.  The solution is to define an alternate location for
templates (such as ./templates).  Creating an entire exhaustive manifest
where each runtime and each template is defined with a name and path is
a usurpation of the responsibilities of a filesystem, and causes
unintend negative knock-on effects.  Let's try this simple solution
before jumping to the nuclear option of defining a filesystem-in-yaml.

- Use filesystems when loading repository objects

The fact that a file exists on the disk, embedded, or remote should be
of no concern to most of the code.  This is accomplished by using the
filesystem abstraction which is used during template writing.  This will
be further improved in future versions by upgrading to use the fs.FS
interface and tooling.

- Uses manifest.yaml at all levels

Once the hierarchical nature of the manifest was instituted, it seemed
more intuitive to have the same filename at each level.  This also has
the nice benefit of being backwards-compatible with template-level
manifest.  This is not a correctness issue, but a guess that remembering
a single filename which can exist at different levels in a hierarchy is
easier to remember than different filenames, and its location in the
hierearchy sufficient differentiator making the different filenames
_perhaps_ unencssary.  The constants are left as separate for an easy
revert.

- Moves static defaults into code wherever possible

Wherever yaml was being statically compiled in, it was updated such that
canonical values for static defaults were defined on the Go structure,
with the yaml being for overrides.  For example Default Readiness and
Liveness endpoints.

Some notable benefits of letting the filesystem do it's thing:
* Preserves the ability to create a repository of templates without
  hacking yaml
* Reflects changes directly in IDEs which have native support for
  filesystem, not so for a proprietary manifest.yaml
* the builtin repository has no name, so parsing a manifest from within
  it is both prone to error and confusing, as it could lead future
  developers to submit PRs which change its name.

* fix: revert repository.git to a bare server repo

* src: repository default name

The Repository struct now includes a Name and DefaultName. The former is
the current name of the repository, and corresponds to the path on disk.
The latter is the name specified in the manifest.yaml, and is used as
the default name of the repository when no name is provided.

Fixes an issue where there could be name collisions using a uuid for the
initial name until the manifest is read in.

Restructures the embedded repositories such that one exemplifies a base
case repo with no metadata and only templates, the other specifying a
manifest to exemplify for example a complete language pack.

Adds a test such that all three cases are covered: explicit name, no
name but manifest-defined default name, URI-derived name.

* feat: single repo mode

Enables single repository mode suystem-wide, which fully implements the
logic intended by the WithRepository option.

The default repoisitory is now programatically defined, and while by
default is the embedded repo, it can be overriden using the
WithRepository option.  This keeps the logic internal to the
repositories managet, removeing the need for a crossp-cutting concern in
other parts of the system.

* src: manifest inheritance and existence tests

Respects alternate templates location when defined in a manifest.
Respects manifest embedded structs HealthEndpoints and BuildConfig at
each of the three levels, with inheritance:  Repo, Runtime and Template.
Separates test repositories into the two cases of a templates-only repo
(with no manifest) and a complex repo (with manifests) such as for
language packs.
Leaves the BuildConfig struct as inline but sets the HealthEndpoints as
being named, such that the latter has its fields in the yaml under the
key 'healthEndpoints' but the former does not (passthrough).
Adds error checks when attempting to access named repo when in
single-repo mode.

* src: remove function merge

Removes feature of mergine a func.yaml defined in a template in favor of
sticking with the manifest.yaml until such time as this is requested.
Assuming YAGNI.

* src: repo filesystems

- Embeds repositories with an internal filesystem
- Replaces filesystem disk checkouts with in-memory until final write
- Combines template Write of various types into a single write which uses the
  filesystem of the applicable templates's repository
- Template is now a simple noun, with logic localized to the templates manager
- Adds better error message regarding single repo mode conditions

The reason for replacing filesystem-based repository instances with in-memory
(especially remote for WithRepository mode) is for a few reasons:  First, 'Add'
will fail without using the temporary UUID hack if there already exists a
repository of the _repo_ name (due to a filesystem collision).  We have
to read the repo to determine the default name as well, so it's messy to avoid.
Second, using an on-disk version is potentially leaky because it may leave
files on the system in the event of a process interruption; able to be
mitigated, but with a likewise hacky use of a os temp directory.  Third, it
may cause racing conditions when using multiple instances the Client as a lib.
Lastly, it precludes our ability to run without touching the filesystm: a
useful mode when running as a pure library or in security-restricted
environments.

* fix: paths within embedded fs

* src: repositories code cleanup

* Removes the manual 0_18 version suffix
* Reanames "single" (uri for single-mode) to the more descriptive
  "remote" (with associated accessor api)
* Default repo name when no URI provided is set to default
* Various wording improvements in error text and comments

* src: error formatting

* feat: templates from local file paths

Adds back the local os filesystem as a fallthrough to support loading
template repositories from file:// paths on disk, without the
requirement that they also be git repositories.

* fix: clone once

Fixes the shortcut of performing a clone to read the manifest prior to
cloning the repository to disk.  This double-clone was replaced by a
single clone (applying the manifest) followed by a file copy from the
in-memory FS to the on-disk repository location.

* src: test fixes

* respect explict name on repository .Add
* fail if repository already exists
* update expected test filenames to new general (non-go-specific) setup
* adds the default repo name to the NewRepository constructor,
  internalizing the somewhat tricky default logic.
* move repo write logig to repo itself, as it will contain impl-specific
  nuances.
* invalid repo path is an error, but only if defined
* temporarily disable repository URL test

* src: update templates test to reflect new name 'cloudevents'

* src: fix go templates and repackage

* fixup: reviewdog spelling errors

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: reviewdog whitespace cleanup

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: run ./hack/update-codegen.sh

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: restore boson-project templates for e2e

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: do not error if default repo location does not exist

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: typo

Signed-off-by: Lance Ball <lball@redhat.com>

* paketo builder and paket community rust buildpack (#599)

* fixup: apply f161d50084

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: update documentation to match impl

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: add git attributes to ignore linting on binary files

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: remove whitespace

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: tweak linter rules

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: tweak .gitattributes

Signed-off-by: Lance Ball <lball@redhat.com>

Co-authored-by: Luke Kingland <lkingland2038@gmail.com>
Co-authored-by: Shashankft9 <48708039+Shashankft9@users.noreply.github.com>
2021-10-27 07:09:01 -07:00
Lance Ball fb7504a900
src: improve usability of Node.js and TypeScript templates (#608)
* src: improve usability of Node.js and TypeScript templates

Fixes: https://github.com/knative-sandbox/kn-plugin-func/issues/596
Related: https://github.com/knative-sandbox/kn-plugin-func/issues/572

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: whitespace again

Signed-off-by: Lance Ball <lball@redhat.com>
2021-10-27 04:39:01 -07:00
Shashankft9 f161d50084
paketo builder and paket community rust buildpack (#599) 2021-10-25 05:57:38 -07:00
Matthias Wessendorf 7d78de98a8
chore: remove unused Context import (#570)
* 💄 Remove unused Context import

Signed-off-by: Matthias Wessendorf <mwessend@redhat.com>

* ♻️ regenerate pkged.go

Signed-off-by: Matthias Wessendorf <mwessend@redhat.com>
2021-10-14 03:15:43 -07:00
Lance Ball 68b0904b17
feat!: rename event templates to 'cloudevents' (#584)
* feat!: rename event templates to 'cloudevents'

This commit renames the templates for cloudevents to be named "cloudevents".

BREAKING CHANGE

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: update commands.md doc

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: fix make test-templates

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: missed an e2e test change

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: gitignore and pkged.go

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: adjust Makefile recipe for pkged.go

Signed-off-by: Lance Ball <lball@redhat.com>
2021-10-13 14:19:42 -07:00
Matthias Wessendorf 52fb215c3c
chore: Cloudevents sdk 2.5.0 (#566)
* Bumping templates to 2.5.0

Signed-off-by: Matthias Wessendorf <mwessend@redhat.com>

* Bump the project to 2.5.0 as well

Signed-off-by: Matthias Wessendorf <mwessend@redhat.com>
2021-10-11 02:31:15 -07:00
Matej Vasek 4b47dbba78
Update Quarkus version in templates (#557)
* Update Quarkus version in templates

Signed-off-by: Matej Vasek <mvasek@redhat.com>

* Update Java to 11 in GH actions

Signed-off-by: Matej Vasek <mvasek@redhat.com>
2021-09-27 14:33:13 -07:00
Luke Kingland 4fe9fdcab0
feat: create cli (#547)
* feat: create cli prompts

* feat: display effective runtimes in prompt

replaces the static list of supported runtimes with a dynamic list of
currently installed+available runtimes; called the effective runtimes.
Used for both prompting and validation.

* feat: dynamic create help and error text

Output from create help text and the create commands now show valid
options for both language runtimes and templates.

* feat: runtime tab completion for runtmes and templates

* feat: support FUNC_PARENT_COMMAND in help

* feat: confirmation of successful create

* fix: include name in initial creation

* src: remove unnecessary comments on create name

* fix: associate prompt questions with struct members in create

* e2e: update tests for language flag

* fix: support nonexistent repositories path

Listing installed repositories considers a missing path equivalent to a
lack of installed repositories.  This will change to an error when the
logic to determin default config directory, and automatically create
initial structure, is moved into the client library.

* fix: only CLI-validate when no repo override
2021-09-22 13:00:12 -07:00
Matej Vasek 16ee28c83d
fix: use full image names (#535)
This is useful when working with `podman` which dislikes short names.

Signed-off-by: Matej Vasek <mvasek@redhat.com>
2021-09-16 08:51:40 -07:00
Luke Kingland ae638c349c
feat: repository management cli (#514)
* feat: repository management cli

* src: cleanup imports, newlines, spelling and trailing whitespace
2021-09-09 08:09:00 -07:00
Luke Kingland 232101d83b
remove superfluous headers from go template (#515) 2021-09-08 04:41:34 -07:00
Lance Ball fcd04da267
chore: update buildpack image URI for Go and typescript (#502)
Now that we have the Go and TypeScript buildpack images published at
https://github.com/boson-project/packs the templates should reference
those images.

Signed-off-by: Lance Ball <lball@redhat.com>
2021-09-01 00:31:32 -07:00
Lance Ball a4b15ad992
feat: move go, typescript and nodejs to paketo builders (#485)
This commit removes the Red Hat builders from the built in templates
for Go, TypeScript and Node.js, replacing them with paketo builders.
For Go, the builder is augmented with a simple buildpack that installs
the Go wrapper code and its dependencies. For TypeScript, the paketo
buildpacks oddly don't support an `npm build` step, so these templates
are also dependent on a small Boson buildpack. These buildpacks are
currently at https://github.com/lance/boson-buildpacks but should find
a home either in the boson-project organization, or the knative-sandbox
organization.

This change also slightly modifies how the Node.js and TypeScript
templates are structured, reducing the coupling between the buildpack
and a function project.

This commit includes the code in https://github.com/knative-sandbox/kn-plugin-func/pull/465
and is dependent on it in the use of manifest.yaml.

Provide sane defaults for health endpoints

Note that this will need to be documented as a requirement for
language packs that do not wish to provide explicit endpoints for
these kube health checks. In that case, the language pack should
specify these both as the root path, with a query parameter. For
example, `/?health=readiness` and `/?health=liveness`, or some other
similar construct.

Signed-off-by: Lance Ball <lball@redhat.com>
2021-08-24 08:46:24 -07:00
Lance Ball 48f40c35e3
feat: allow language packs to set function metadata (#465)
This commit introduces the concept of a `manifest.yaml` file which
can be added to each template directory to specify things such as health
endpoints, builders and buildpacks for the function.

It problematic that, because we don't yet have the concept
of a global configuration file, the only place to store this metadata is
in a project's `func.yaml` file. There is no reason a function dev
should be exposed to things like health endpoints. This information is
determined by the language pack and integrated by the builder. The only
reason we need it is that it's necessary to determine these endpoints when
deploying. Otherwise, we would have to insist that all language packs
provide endpoints at `/health/readiness` and `/health/liveness`.

This commit also adds support for a `buildpacks` property in `manifest.yaml`
which will be used to set the buildpacks when a function is being built.

Signed-off-by: Lance Ball <lball@redhat.com>
2021-08-22 09:00:34 -07:00
Zbynek Roubalik a21252ac93
docs: change `describe` command to `info` (#480)
Signed-off-by: Zbynek Roubalik <zroubali@redhat.com>
2021-08-17 04:19:16 -07:00
Matej Vasek 72a1cf885e
fix: enable healt checks for Quarkus (#477)
Signed-off-by: Matej Vasek <mvasek@redhat.com>
2021-08-12 06:27:35 -07:00
Dejan Bosanac 7656c40972
feat: Add proper example of configuring Rust functions. (#436) 2021-08-01 14:51:42 -07:00
Lance Ball d71532a070
fix: fix unit tests for Node.js event templates (#438)
The bump of a major version of the Node.js dependencies changed
the format for the data received over HTTP (string vs. object).
This fixes that test to use JSON.stringify().

Signed-off-by: Lance Ball <lball@redhat.com>
2021-07-26 10:42:15 -07:00
Markus Thömmes 02e86d394a
Change github.com links to the new home (#424) 2021-07-26 10:30:15 -07:00
Julian Friedman ff35740b45
Bump cloudevents dep to 4.0.3 (#434) 2021-07-23 09:43:45 -07:00
Julian Friedman 7e5fd9a526
Bump node dependencies (#433) 2021-07-23 08:27:45 -07:00
Dejan Bosanac a08b843a9c
feat: Configure Rust functions (#430)
* Add ability to add all custom function configuration in a separate module.

Co-authored-by: Dejan Bosanac <dejan@sensatic.net>
Co-authored-by: Jim Crossley <jcrossley3@gmail.com>

Co-authored-by: Jim Crossley <jcrossley3@gmail.com>
2021-07-23 07:02:45 -07:00
Matej Vasek 771a2307a1
fix: update builders version (#421)
Signed-off-by: Matej Vasek <mvasek@redhat.com>
2021-07-15 11:29:32 -07:00
Jim Crossley c2c1b999e0
Define handler in terms of CloudEvents rather than http/payload (#412)
This should simplify the unit tests. Only the invalid_event test uses
the actix-web test helpers, just as an example to show it's the HTTP
plumbing that will fail the request when it tries to construct an
Event from invalid (or missing) headers.
2021-07-12 09:04:13 -04:00
Lance Ball bfa5746442
chore: bump to buildpacks v0.8.3 for all versions (#402)
* chore: bump to buildpacks v0.8.2 for all versions

This is causing me to rethink using versions in these templates, and our
overall buildpack version/release strategy. But for now, we should land
this before 0.16.0

* adds trust for any quay.io/boson builder

Signed-off-by: Lance Ball <lball@redhat.com>
2021-06-23 12:44:42 -04:00
Jim Crossley 4711638495
feat: Rust templates (#376)
* Rust templates for http/event triggers

Each template is a fully-formed actix-web application that includes a
main.rs providing the server configuration and a handler.rs showing an
example function and a few simple unit tests. A README.md provides a
bit more detail to get the user started. The events handler is similar
to the example in the old faas-rust-runtime project.

* With developer guide for Rust
2021-06-18 13:08:50 -04:00
Luke Kingland 40f10277a4
feat: typed errors for templates use cases 2021-06-18 19:08:01 +09:00
Lance Ball 593bfd0dc9
chore(builders): add explicit version numbers for builder images (#365)
This commit adds specific version numbers to each of the builder images
referenced in function templates, func.yaml file. Because the API for
at least some of the runtimes has changed over time (looking at you,
faas-js-runtime), we should consider publishing our func.yaml files with
known-to-be-working-with-this-release versioned builder images.

Signed-off-by: Lance Ball <lball@redhat.com>
2021-06-01 10:03:59 -04:00
Lance Ball d3eafe2a84
feat: add typescript templates (#355)
* feat: add typescript templates

Bumps the faas-js-runtime dependency to 0.7.1 and Node.js buildpack dependency to v0.8.1

fix file globbing on windows

adjust eslint/prettier for windows

improve READMEs

add usage guide

Signed-off-by: Lance Ball <lball@redhat.com>
2021-05-26 11:23:42 -04:00
Jim Crossley caf0659900
src(templates)!: modify the nodejs event template to accept a cloudevent (#356)
* Simplify the nodejs events template

Pretty-printing the contents of the event and its envelope for each
request. This is handy when invoked as a Knative event sink as some
sources, e.g. Kafka, ignore the response body.

Co-authored-by: Lance Ball <lball@redhat.com>

* Expect the event parameter to be the entire CloudEvent

This will require a change to the faas-js-runtime, but at least the
template won't need to change when that's released

* Update nodejs guide to reflect 2nd arg's type is CloudEvent

* Templates now using faas-js-runtime 0.7.1

Co-authored-by: Lance Ball <lball@redhat.com>
2021-05-25 13:49:48 -04:00
Helio Frota ea0a75a7cc
fix: minor typos in node template docs (#351) 2021-05-18 08:48:34 -04:00
Lance Ball 2b025df199
src!: revert bump to go 1.16 and template changes (#340)
* Revert "src: rename boson import 'fn'"

This reverts commit c0a6f561c0.

* Revert "src: all test dirs set to 0700"

This reverts commit 99f01220c2.

* Revert "src: better error when custom template not found"

This reverts commit 6673395834.

* Revert "src: better errors when custom runtime not found"

This reverts commit a31a6f67a1.

* Revert "build: create separate target for templates.tgz"

This reverts commit 11164bf8d9.

* Revert "src: use consistent separators for fs.FS instances"

This reverts commit 4db07b412f.

* Revert "src: update go event template dependencies"

This reverts commit 3bfc13380f.

* Revert "src: tarfs assumes forward slashes internally"

This reverts commit 6cc0e67b1c.

* Revert "feat: support windows paths in embedded templates FS"

This reverts commit c2b216857b.

* Revert "feat: positive error when runtimme or template unrecognized"

This reverts commit acc56b0900.

* Revert "fix: lint issues"

This reverts commit 895872aee7.

* Revert "ci: go 1.16 compatiblity updates"

This reverts commit 1e3959c045.

* Revert "feat: preserve file modes using in-memory tar FS"

This reverts commit 7dc772ec62.

* Revert "feat: create templates archive on go generate"

This reverts commit 63b7f11471.

* Revert "ci: remove pkger from ci"

This reverts commit 876b0dd0f7.

* Revert "src: remove pkger dependency and tidy"

This reverts commit f006ab1e32.

* Revert "src: remove packaging artifact"

This reverts commit 4d9d0a7b4e.

* Revert "src: remove pkger from make targets"

This reverts commit e44c1ad74c.

* Revert "src: replace pkger with embed.FS"

This reverts commit 38874a4afd.

* Revert "src: update references to deprecated ioutil"

This reverts commit 4025460f73.

* Revert "src: require go 1.16"

This reverts commit 512d4c2580.

* chore: update pkged.go

Signed-off-by: Lance Ball <lball@redhat.com>
2021-05-12 14:37:21 -04:00
Luke Kingland 3bfc13380f
src: update go event template dependencies 2021-05-07 14:05:37 +09:00
Luke Kingland 1e3959c045
ci: go 1.16 compatiblity updates 2021-05-07 14:05:16 +09:00
Luke Kingland 7dc772ec62
feat: preserve file modes using in-memory tar FS 2021-05-07 14:05:14 +09:00
Luke Kingland 38874a4afd
src: replace pkger with embed.FS 2021-05-07 14:00:46 +09:00
Zbynek Roubalik 9488e01a26
chore: fix typo in node http template (#329)
Signed-off-by: Zbynek Roubalik <zroubali@redhat.com>
2021-05-06 10:27:18 +02:00
Matej Vasek 4f60504708
src: Quarkus events template uses CloudEvent<> (#303)
Signed-off-by: Matej Vasek <mvasek@redhat.com>
2021-04-14 14:28:08 -04:00
Zbynek Roubalik c86fdbc5e7
src: use go 1.14 in the templates (#299)
Signed-off-by: Zbynek Roubalik <zroubali@redhat.com>
2021-04-14 19:47:32 +02:00
Lance Ball 5da927808e
chore: update Node.js faas-js-runtime dependency to 0.6.0 (#302)
* chore: update Node.js faas-js-runtime dependency to 0.6.0
* fixup: remove erroneous console.error statement

Signed-off-by: Lance Ball <lball@redhat.com>
2021-04-14 13:27:35 -04:00
Zbynek Roubalik 4957b7c6bf
chore: bump CE version in Go templates (#300)
Signed-off-by: Zbynek Roubalik <zroubali@redhat.com>
2021-04-14 12:59:42 -04:00
Lance Ball ad335d217e
chore: update python templates to use parliament context/event (#301)
* chore: update python templates to use parliament context/event

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: fix tests

Signed-off-by: Lance Ball <lball@redhat.com>
2021-04-14 12:50:52 -04:00
Matej Vasek 129dc5a834
fix: build needs to use legacy jar
this should be reverted once our buildpack supports fast-jar

Signed-off-by: Matej Vasek <mvasek@redhat.com>
2021-04-12 16:52:49 +02:00
Matej Vasek f2c7b764c2
chore: update Quarkus version (#291)
Signed-off-by: Matej Vasek <mvasek@redhat.com>
2021-04-01 09:28:36 -04:00
Lance Ball 08f4fc7bd9
feat: add python templates (#286)
Signed-off-by: Lance Ball <lball@redhat.com>
2021-03-30 17:08:42 -04:00
Luke Kingland f1a6561543
src: also package templates on 'go generate' 2021-03-10 19:35:27 +09:00
Matej Vasek 38fd673fdb
fix: sprint-boot template
Signed-off-by: Matej Vasek <mvasek@redhat.com>
2021-03-02 04:33:27 +01:00
Zbynek Roubalik a5cbe3061b
src: rename from faas to func (#253)
Signed-off-by: Zbynek Roubalik <zroubali@redhat.com>
2021-01-21 17:10:39 +01:00
Zbynek Roubalik 55024921c2
fix: correct fn signatures in Go Events template (#246)
* fix: correct fn signatures in Go Events template
* change cloudevents import name to event

Signed-off-by: Zbynek Roubalik <zroubali@redhat.com>
2020-12-10 16:11:12 -05:00
Kamesh Sampath 557361a374
feat: add spring cloud function runtime and templates (#231)
* feat: add spring cloud function runtime and templates

* docs: review updates

* squash: apply suggestions from code review

Co-authored-by: Lance Ball <lball@redhat.com>
2020-11-25 12:15:48 -05:00
Matej Vasek b595500bb0
src: updated Quarkus template
Function in template now accepts beans instead of java.lang.Object

Signed-off-by: Matej Vasek <mvasek@redhat.com>
2020-11-06 18:19:05 +01:00
Lance Ball beb838ff43
fix: return JSON in Node.js event template (#211)
The event template was just returning a string, but the default response
content type is application/json so browsers were failing to parse the string
as JSON.

Signed-off-by: Lance Ball <lball@redhat.com>
2020-11-06 10:46:53 -05:00
Zbynek Roubalik 470ebb9da4
rename function -> func (#217)
Signed-off-by: Zbynek Roubalik <zroubali@redhat.com>
2020-11-06 12:47:30 +01:00
Zbynek Roubalik cd57692c9d
feat!: rename faas to function (#210)
* rename faas to function

Signed-off-by: Zbynek Roubalik <zroubali@redhat.com>

* function.yaml -> func.yaml

Signed-off-by: Zbynek Roubalik <zroubali@redhat.com>
2020-11-06 10:41:42 +01:00
Lance Ball 6110d50b6b
templates: Node.js event template to return event (#202)
This commit modifies the Node.js template so that it returns a CloudEvent. The
tests are also modified to test for CloudEvent attributes and headers. Additionally
the faas-js-runtime bump reverses the parameters for the function.

Fixes: https://github.com/boson-project/faas/issues/190
Fixes: https://github.com/boson-project/faas/issues/194

Signed-off-by: Lance Ball <lball@redhat.com>
2020-11-05 10:22:20 -05:00
Matej Vasek 5591e7fa2c
fix: examples in readme 2020-10-20 19:37:40 +02:00
Lance Ball 74511948ce
feat: introduce CloudEvent data as first parameter for event functions (#172)
The 0.4.0 version of faas-js-runtime extracts the CloudEvent data from
an incoming event and provides that as the first parameter when invoking
a function which receives a CloudEvent. This commit bumps to that version
as well as improves the overall readability and code documentation for the
Node.js CloudEvent function.

Signed-off-by: Lance Ball <lball@redhat.com>
2020-10-14 09:46:37 -04:00
Matej Vasek ffc6a123e4
fix: update quarkus templates 2020-10-13 17:57:54 +02:00
Lance Ball 6d301257f5
chore(templates): bump faas-js-runtime to 0.3.0 and update the name (#150)
* chore(templates): bump faas-js-runtime to 0.3.0 and update the name

The module name lost its @redhat prefix, and bumped a version. This
pulls in that latest dependency.

Running pkger for the first time on a new system also resulted in a
minor version bump for that dependency.


Signed-off-by: Lance Ball <lball@redhat.com>
2020-10-07 17:48:30 -04:00
Matej Vasek c2b4a304bd
feat: ability for users to specify custom builders (#147)
* refactor: functionWithOverrides
* feat: custom Buildpacks builder
* fix: namespaces
2020-10-05 10:29:51 -04:00
Matej Vasek 06391a4243
chore: update go cloudevent sdk dep 2020-09-29 18:24:53 +02:00
Lance Ball d6e131f915
feat: set builder images in templates and .faas.yaml (#136)
This commit adds a .builder.yaml file to each template directory. In the file
there is at the moment a single key/value pair, "default: <image>", where the
actual builder image name is <image>. Using a mapping allows the future
possibility that a user may specify a builder image by name via a flag on the
command line. For example,

```console
faas build --builder native
```

When a project is initialized, the .builder.yaml file is read, and the default
builder is saved in the project's .faas.yaml file. The .faas.yaml file is then
consulted when building an image with `faas build`. If the builder image is
specified, then the builder will use it. Otherwise, it will fallback to the
defaults. This allows developers to create custom builders, and specify them
in the configuration file.

After extracting the builder image from .builder.yaml in the project directory,
this file is deleted.

This commit also adds Verbose to the init command.
2020-09-24 11:41:34 -04:00
Matej Vasek 02309a24a1
fix: sync package-lock.json (#137) 2020-09-24 09:18:02 -04:00
Lance Ball 1b0bb15147
feat: add local debugging to node.js templates (#132)
This commit adds nodemon and an `npm run debug` command to the Node.js
templates to support debugging on localhost.
2020-09-22 09:32:23 -04:00
Matej Vasek 279e990843
chore: update Quarkus version to 1.8.1.Final 2020-09-21 15:08:15 +02:00
Matej Vasek bb575b04c0
fix: signature of HTTP go function in template 2020-09-09 15:27:38 +02:00
Matej Vasek 565066ef4b
chore: update quarkus version to 1.7.2.Final 2020-09-08 21:23:56 +02:00
Lance Ball 609ab86a4d
templates(node): make node templates use npx @redhat/faas-js-runtime (#99)
Currently the templates have a `local.js` file and an explicit dependency
on the @redhat/faas-js-runtime module. This removes that build-time
dependency and replaces it with a runtime dependency by using the (pending)
CLI from the module.

This is nice for a couple of reasons.

- Reduces the build time during `faas deploy`
- Eliminates the need for `faas` to bump with updates to faas-js-runtime

See: https://github.com/boson-project/faas-js-runtime
2020-09-08 14:16:51 -04:00
Luke K 3d51c27c6c
docs: initial Go template READMEs 2020-09-04 22:27:16 +09:00
Luke K 00ac880c3b
docs: fix function typos 2020-08-29 01:55:33 +09:00
Luke K 4918cc7eef
feat: cli usability enhancements and API simplification 2020-08-29 01:54:13 +09:00
Lance Ball ea7fe15376
src(templates/node): update Node.js templates (#68)
This commit updates the Node.js templates to use the latest faas-js-runtime
framework, and fixes a couple of dependency issues and broken tests. I have
also added a build time test for these templates so that if/when they change
again, we can be sure to catch any problems.
2020-08-13 17:05:25 -04:00
Matej Vasek 17cdf05801
feat: http template for Quarkus stack 2020-07-27 16:03:55 +02:00
Lance Ball 5d6e2d3c8c
init: add Node.js HTTP template
Note that this template currently points to boson-project/faas-js-runtime
for it's framework dependency as it depends on currently unreleased features.
Once 0.3.0 of that project is released, this template should be updated.
This dependency is only needed for local testing and development.
2020-07-09 15:14:32 -04:00
Luke K 2b4227736f
move js template to quarkus runtime 2020-07-02 13:07:51 +00:00
Luke K 66fb086d94
move java template to be quarkus runtime 2020-07-02 13:07:36 +00:00
Luke K a2f0ef312c
java events template 2020-06-11 12:25:35 +00:00
Luke K 4122522f23
js events template 2020-06-11 12:25:35 +00:00
Luke K 50da540bfb
templates generation docs 2020-06-11 12:25:35 +00:00
Luke K 6d720f44f2
example go templates for HTTP and CloudEvents 2020-06-11 12:21:54 +00:00