Skip to content

Commit 852a532

Browse files
committed
Switch to ttl.sh for examples and explain multi-arch support
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent b977980 commit 852a532

File tree

1 file changed

+47
-13
lines changed

1 file changed

+47
-13
lines changed

docs/openfaas-pro/builder.md

+47-13
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ faas-cli up --remote-builder http://127.0.0.1:8081/build \
9999

100100
### Remote builds via `curl`
101101

102+
As an alternative to a private or authenticated registry, you can use [ttl.sh by Replicated](https://ttl.sh) as a temporary registry for testing (only). It allows you to publish containers that are removed after a certain time-limit, try `ttl.sh/test-image-hello:1h` for an image that is removed after 1 hour.
103+
104+
You can use any registry that is configured in your `config.json` file by changing the `image` field in the configuration file.
105+
102106
Create a build context using the `faas-cli build --shrinkwrap` command:
103107

104108
```bash
@@ -108,7 +112,7 @@ mkdir -p /tmp/functions
108112
cd /tmp/functions
109113

110114
# Create a new function
111-
faas-cli new --lang node16 hello-world
115+
faas-cli new --lang node20 hello-world
112116

113117
# The shrinkwrap command performs the templating
114118
# stage, then stops before running "docker build"
@@ -126,12 +130,11 @@ mv hello-world context
126130
# Create a config file with the registry and the
127131
# image name that you want to use for publishing the
128132
# function.
129-
export DOCKER_USER=alexellis2
130-
echo -n '{"image": "docker.io/'$DOCKER_USER'/test-image-hello:0.1.0"}' > com.openfaas.docker.config
133+
export REGISTRY=ttl.sh
134+
export OWNER=alexellis2
135+
echo -n '{"image": "'$REGISTRY'/'$OWNER'/test-image-hello:0.1.0", "platforms": ["linux/amd64","linux/arm64"]}' > com.openfaas.docker.config
131136
```
132137

133-
> As an alternative to a private or authenticated registry, you can use [ttl.sh by Replicated](https://ttl.sh) as a temporary registry for testing (only). It allows you to publish containers that are removed after a certain time-limit, try `ttl.sh/test-image-hello:1h` for an image that is removed after 1 hour.
134-
135138
If you wish, you can also construct this filesystem using your own application, but it is easier to execute the `faas-cli` command from your own code.
136139

137140
Then create a tar archive of the context of the `/tmp/functions/build/` directory:
@@ -176,11 +179,13 @@ curl -H "X-Build-Signature: sha256=$HMAC" -s http://127.0.0.1:8081/build -X POST
176179
....
177180
"v: 2021-10-20T16:48:34Z exporting to image 8.01s"
178181
],
179-
"image": "docker.io/alexellis2/test-image-hello:0.1.0",
182+
"image": "ttl.sh/alexellis2/test-image-hello:0.1.0",
180183
"status": "success"
181184
}
182185
```
183186

187+
The initial build is likely to take some time, however, if you run the build again or only change some text within a file the subsequent build could complete with single-digit seconds.
188+
184189
### Remote builds with a HTTP client
185190

186191
A HTTP client has three tasks to perform:
@@ -229,7 +234,7 @@ There are several examples available of how to call the Function Builder's API v
229234

230235
You should be able to translate the example given with curl into any programming language, but if you need additional support, feel free to [reach out to us](https://openfaas.com/support).
231236

232-
## Monitor the builder
237+
## How to monitor the builder
233238

234239
The builder has additional metrics which will be scraped by the Prometheus instance installed by the OpenFaaS helm chart.
235240

@@ -239,28 +244,57 @@ The builder has additional metrics which will be scraped by the Prometheus insta
239244

240245
* [Download the Grafana JSON file from the Customer Community](https://github.com/openfaas/customers/tree/master/dashboards)
241246

242-
## In-cluster access
247+
## How to gain in-cluster access
243248

244-
You can access the Function Builder via your code, or an OpenFaaS function by specifying its URL and its in-cluster service name. You do not need to expose the builder's API publicly.
249+
You can access the Function Builder via your code, or an OpenFaaS function by specifying its URL and its in-cluster service name.
245250

246251
```
247252
http://pro-builder.openfaas:8080/build
248253
```
249254
250-
## Build arguments
255+
Even though the endpoint is authenticated, we recommend you do not expose the builder's API to the Internet.
256+
257+
## How to specify build arguments
251258
252259
You may need to enable build arguments for the Dockerfile, these can be passed through the configuration file.
253260
254261
```json
255262
{
256-
"image": "docker.io/alexellis2/test-image:0.1.0",
263+
"image": "ttl.sh/alexellis/test-image:0.1.0",
257264
"buildArgs": {
258265
"BASE_IMAGE": "gcr.io/quiet-mechanic-140114/openfaas-base/node16"
259266
}
260267
}
261268
```
262269

263-
## Scaling the builder
270+
## How to perform multi-arch builds
271+
272+
You may wish to cross-compile a function to run on an arm64 host, if so, you can provide a `platform` key in the configuration file.
273+
274+
The below will build an image for arm64 only and must be deployed only to an arm64 host using OpenFaaS Profiles to ensure it is scheduled correctly to an arm64 host.
275+
276+
```json
277+
{
278+
"image": "ttl.sh/alexellis/test-image:0.1.0",
279+
"platforms": ["linux/arm64"]
280+
}
281+
```
282+
283+
Multiple platforms can be specified, the below will build an image for arm64 and amd64, and can be deployed to either type of host.
284+
285+
```json
286+
{
287+
"image": "ttl.sh/alexellis/test-image:0.1.0",
288+
"platforms": ["linux/arm64", "linux/amd64"]
289+
}
290+
```
291+
292+
Bear in mind:
293+
294+
* multi-arch images will usually take longer to publish than single-arch images due to emulation with QEMU
295+
* any steps performed under a TARGETARCH which differs from BUILDARCH will be emulated with QEMU which will add overhead to the build process - you can mitigate this by running a dedicated arm64 and amd64 pro-builder Helm chart installation
296+
297+
## How to scale the builder
264298

265299
The Function Builder can be scaled out, which also deploys additional replicas of the Function Builder:
266300

@@ -269,7 +303,7 @@ kubectl scale -n openfaas deploy/pro-builder \
269303
--replicas=3
270304
```
271305

272-
## Limiting the amount of concurrent requests
306+
## How to limiting the amount of concurrent builds
273307

274308
You can limit the amount of concurrent requests that a builder will accept by setting `proBuilder.maxInflight: N` within the helm chart or the `max_inflight` environment variable on the Deployment.
275309

0 commit comments

Comments
 (0)