Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/redirects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,7 @@ plugins:
versioned/getting-started/clean-up.md: versioned/getting-started/next-steps.md#clean-up
versioned/bookstore/disclaimer/README.md: versioned/bookstore/disclaimer/disclaimer.md
versioned/bookstore/extra-challenge/README.md: versioned/bookstore/extra-challenge/extra-challenges.md
versioned/functions/install-func.md: versioned/functions/running-functions.md
versioned/functions/creating-functions.md: versioned/functions/running-functions.md
versioned/functions/invoking-functions.md: versioned/functions/running-functions.md
versioned/functions/kafka-functions.md: versioned/functions/subscribing-functions.md
14 changes: 5 additions & 9 deletions docs/versioned/.nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,11 @@ nav:
###############################################################################
- Functions:
- Overview: functions/README.md
- Install: functions/install-func.md
- Create: functions/creating-functions.md
- Build: functions/building-functions.md
- Run locally: functions/running-functions.md
- Deploy: functions/deploying-functions.md
- Invoke: functions/invoking-functions.md
- Subscribe to events: functions/subscribing-functions.md
- Kafka: functions/kafka-functions.md
- Language packs: functions/language-packs.md
- Develop locally: functions/running-functions.md
- Build an image: functions/building-functions.md
- Deploy a function: functions/deploying-functions.md
- Connect events: functions/subscribing-functions.md
- Templates and runtimes: functions/language-packs.md
###############################################################################
# Serving
###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion docs/versioned/client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The `func` CLI enables you to create, build, and deploy Knative Functions withou

### Additional resources

- See [Installing Knative Functions](../functions/install-func.md).
- See [Develop locally — Prepare](../functions/running-functions.md#prepare).
- See the [`func` documentation]({{ funcdocs() }}){target=_blank} in Github.

## Connecting CLI tools to your cluster
Expand Down
33 changes: 19 additions & 14 deletions docs/versioned/functions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,31 @@ audience: developer
components:
- functions
function: explanation
hide_prev: true
hide_next: true
---

# Knative Functions overview
# Knative Functions

--8<-- "about-functions.md"

## Function templates
## Start here

--8<-- "functions-templates-intro.md"
New to Knative Functions? Follow [Try Functions](../getting-started/about-knative-functions.md)
to create, edit, and test a Go function locally — no Kubernetes cluster or
registry account required.

## Language packs
## Choose a task

Functions can be written in any language supported by the available [language packs](https://github.com/knative/func/blob/main/docs/language-packs/language-pack-contract.md){target=_blank}.
<!--TODO: Remove and replace with lang pack snippet in future PR, similar to templates-->
- **[Develop locally](running-functions.md):** install `func`, create a project,
run it locally, and send HTTP or CloudEvents test requests.
- **[Build an image](building-functions.md):** build a container image locally
without running or deploying it.
- **[Deploy a function](deploying-functions.md):** deploy from your machine or
build and deploy remotely on a cluster with Tekton.
- **[Connect events](subscribing-functions.md):** subscribe a function to a
Knative Broker with Triggers, or consume Apache Kafka topics via sidecar.
- **[Templates and runtimes](language-packs.md):** choose a language and
HTTP/CloudEvents template, or use custom language-pack repositories.

## Getting started with functions

Follow [Get started with Functions](../getting-started/about-knative-functions.md)
to create, change, and test a Go function locally. This is the same Functions
track linked from Get Started. Cluster deployment is optional and links to the
shared learning-cluster setup.

For an existing project, use the how-to guides in this section.
For the full CLI reference, see the [`func` documentation]({{ funcdocs() }}){target=_blank}.
153 changes: 49 additions & 104 deletions docs/versioned/functions/building-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,136 +3,81 @@ audience: developer
components:
- functions
function: how-to
hide_prev: true
hide_next: true
---

# Building functions
# Build an image
Comment thread
gauron99 marked this conversation as resolved.
Resolved

Build a container image from an existing function project. The local procedure
builds only: it does not run, publish, or deploy the function. The optional
on-cluster workflow below builds **and deploys**, so choose it only when you want
that result.
`func build` turns a function project into a container image. It does not push
anything to a registry by default (add `--push` to push the image), and it never
deploys. For standard deployments, skip this separate build step:
[`func deploy`](deploying-functions.md) builds, pushes, and deploys in one command.

## Local builds
## Requirements

### Prerequisites
- An initialized function project containing `func.yaml` and source code.
[Create a project](running-functions.md#create-a-project) if needed.
- A running Docker-compatible container engine, such as
[Docker](https://docs.docker.com/get-started/get-docker/) or
[Podman](https://github.com/knative/func/blob/main/docs/building-functions/podman.md){target=_blank},
for containerized builders (`pack` or `s2i`).
- Run commands from inside the function project directory (or use `--path`).

- You have an initialized function project containing `func.yaml` and its source.
[Create a project](creating-functions.md) if needed.
- Docker is running for the container-based buildpacks builder used here.
- Run these commands from that project directory, not its parent directory.
<span id="local-builds"></span>

### Procedure
## Build

Set an explicit local image name so the build does not need a registry prompt:
Pass your registry: the registry host and your account namespace, for example
`ghcr.io/alice` or `docker.io/alice`:

=== "func"

```bash
func build --builder pack \
--image localhost/my-function:latest
func build --registry <registry>
```

=== "kn func"

```bash
kn func build --builder pack \
--image localhost/my-function:latest
kn func build --registry <registry>
```

`my-function` is an example image name; substitute yours consistently if desired.
`localhost` here is a local tag, not a registry server you must create. Wait for
building to complete, then check the image in Docker:
`func` names the image `<registry>/<function-name>:latest` and saves the registry
in `func.yaml`, so later builds and deploys need no registry flag. You can also
set the registry with `FUNC_REGISTRY`. The image stays in your container engine's
local image store until you push it. If you previously set `--image`, see
[Set the image name yourself](#set-the-image-name-yourself) to return to registry-based naming.

```bash
docker image ls localhost/my-function:latest
```

A row with the tag `latest` and an image ID identifies the built image. This does
not mean it was pushed or started. For publishing, see the
[deployment guide](deploying-functions.md#procedure), which explains registry
prefixes and full image destinations. [Try Functions](../getting-started/about-knative-functions.md#run-and-test)
shows how to run and test an image as a separate step. For other builders, image
naming options, and flags, see the [func build reference](https://github.com/knative/func/blob/main/docs/reference/func_build.md).

## On-cluster Builds

This alternative uses a remote pipeline and deploys the resulting function.
It avoids a local container build, but requires a configured cluster and registry
credentials. The source can come from Git **or** direct upload; Git is not required
for the direct-upload branch.

### Prerequisites

- Your kubeconfig selects a cluster with Knative Serving installed.
- Tekton Pipelines and the function build pipeline are configured according to the
[on-cluster build setup guide](https://github.com/knative/func/blob/main/docs/building-functions/on_cluster_build.md).
- The pipeline can push to your chosen registry, and the cluster can pull the image.
Complete the registry/credential setup in that guide rather than assuming local
Docker login alone configures every remote pipeline.
- You have an initialized local function project and are in its directory.

### Procedure

Choose the source branch below. Replace `REGISTRY-USER` with your Docker Hub
account namespace in the image name. For Git, separately replace `GIT-OWNER` and
`GIT-REPO` with the repository owner and name; the Git owner need not match your
registry account. The explicit image destination avoids carrying over a local-only
tag from an earlier build.

#### Git-backed source

The function project must be committed in a Git repository the pipeline can read.
For a private repository, your platform administrator must provision pipeline
access before you use this branch; the linked function-build setup guide does
not provide a private-Git authentication recipe. The [Tekton authentication guide](https://tekton.dev/docs/pipelines/auth/)
is background for that platform setup. If you cannot arrange repository access,
use direct upload instead.

These commands assume the project is at the repository root. For a subdirectory,
set `build.source.dir` in your project's `func.yaml` to its relative path, following
the configuration example in the [on-cluster build guide](https://github.com/knative/func/blob/main/docs/building-functions/on_cluster_build.md).
For example, `dir: functions/my-function` selects that directory within the Git repository.

=== "func"
## Verify the image

```bash
func deploy --remote \
--image docker.io/REGISTRY-USER/my-function:latest \
--git-url https://github.com/GIT-OWNER/GIT-REPO
```

=== "kn func"
Confirm the image exists (with Podman, use `podman image ls`):

```bash
kn func deploy --remote \
--image docker.io/REGISTRY-USER/my-function:latest \
--git-url https://github.com/GIT-OWNER/GIT-REPO
```
```bash
docker image ls <registry>/<function-name>
```

#### Direct-upload source
A row with tag `latest` and an image ID confirms the build succeeded.

Use this branch to upload the current local project. No Git repository is required.
Passing an empty Git URL explicitly clears a previously configured Git source.
If you previously set `build.source.dir` for a Git subdirectory, remove that `dir`
entry from `build.source` too so the upload uses the current local project root:
<span id="on-cluster-builds"></span>

=== "func"
## Other builders

```bash
func deploy --remote \
--image docker.io/REGISTRY-USER/my-function:latest \
--git-url=""
```
`func build` supports `--builder pack` (Cloud Native Buildpacks, the default),
`--builder s2i` (Source-to-Image), and `--builder host`, which builds with your
local toolchain and needs no container engine. The `host` builder currently
supports Go and Python functions. It writes the image to `.func/build/oci`
in the project, not to the container engine, so `docker image ls` does not list it.

=== "kn func"
For remote on-cluster builds with Tekton, see
[Deploy a function — Build and deploy remotely](deploying-functions.md#build-and-deploy-remotely).
For all flags and builder options, see the
[`func build` reference](https://github.com/knative/func/blob/main/docs/reference/func_build.md){target=_blank}.

```bash
kn func deploy --remote \
--image docker.io/REGISTRY-USER/my-function:latest \
--git-url=""
```
## Set the image name yourself

Wait for the pipeline and deployment to finish. Verify the **deployed** function
using `func invoke --target remote` (or `kn func invoke --target remote`) and
check your function's expected response. A finished image build alone does not
prove deployment or invocation succeeded.
To choose the full image name instead of `<registry>/<function-name>:latest`,
pass `--image`, for example `--image ghcr.io/alice/my-image:v1`. `func` saves it
in the `image:` line in `func.yaml`, where it takes precedence over `--registry`
and `FUNC_REGISTRY` on later builds and deploys. To return to registry-based
naming, delete the `image:` line from `func.yaml`.
10 changes: 0 additions & 10 deletions docs/versioned/functions/creating-functions.md

This file was deleted.

Loading
Loading