Skip to content

Commit f173e1d

Browse files
authored
Adjust docs for build image from local source code (#321)
Signed-off-by: Benjamin Huo <benjamin@kubesphere.io>
1 parent 773813d commit f173e1d

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

content/en/docs/concepts/function_build.md

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ linkTitle: "Function Build"
44
weight: 3110
55
description:
66
---
7-
Currently, OpenFunction builds function images with [Cloud Native Buildpacks](https://buildpacks.io/). The traditional `Dockerfile` build method will be supported in the future.
7+
Currently, OpenFunction supports building function images using [Cloud Native Buildpacks](https://buildpacks.io/) without the need to create a `Dockerfile`.
88

9-
## Build functions by adding a build section in the function definition
9+
In the meantime, you can also use OpenFunction to build [Serverless Applications](./serverless_apps/#build-and-run-a-serverless-application-with-a-dockerfile) with `Dockerfile`.
10+
11+
## Build functions by defining a build section
12+
13+
You can build your functions or applications from the source code in a git repo or from the source code stored locally.
14+
15+
### Build functions from source code in a git repo
1016

1117
You can build a function image by simply adding a build section in the `Function` definition like below.
1218
If there is a serving section defined as well, the function will be launched as soon as the build completes.
@@ -42,19 +48,26 @@ spec:
4248

4349
### Build functions from local source code
4450

45-
To build functions from local source code, we need a bundle image which contains the source code.
46-
We can use the following `Dockerfile` to build a bundle image.
51+
To build functions or applications from local source code, you'll need to package your local source code into a container image and push this image to a container registry.
52+
53+
Suppose your source code is in the `samples` directory, you can use the following `Dockerfile` to build a source code bundle image.
4754

4855
```shell
4956
FROM scratch
50-
5157
WORKDIR /
5258
COPY samples samples/
5359
```
5460

55-
> We suggest using a empty image such as `scratch` as the base image of the bundle image, a non-empty base image may cause the source code copy to fail.
61+
Then you can build the source code bundle image like this:
62+
63+
```shell
64+
docker build -t <your registry name>/sample-source-code:latest -f </path/to/the/dockerfile> .
65+
docker push <your registry name>/sample-source-code:latest
66+
```
67+
68+
> It's recommended to use the empty image `scratch` as the base image to build the source code bundle image, a non-empty base image may cause the source code copy to fail.
5669

57-
The `srcRepo` of function should be changed like this.
70+
Unlike defining the `spec.build.srcRepo.url` field for the git repo method, you'll need to define the `spec.build.srcRepo.bundleContainer.image` field instead.
5871

5972
```yaml
6073
apiVersion: core.openfunction.io/v1beta1
@@ -65,11 +78,11 @@ spec:
6578
build:
6679
srcRepo:
6780
bundleContainer:
68-
image: openfunctiondev/local-source
81+
image: openfunctiondev/sample-source-code:latest
6982
sourceSubPath: "/samples/functions/async/logs-handler-function/"
7083
```
7184

72-
> The `sourceSubPath` is the absolute path of the source code in the bundle image.
85+
> The `sourceSubPath` is the absolute path of the source code in the source code bundle image.
7386

7487
## Build functions with the pack CLI
7588

0 commit comments

Comments
 (0)