Skip to content

Commit b89f64a

Browse files
weltekialexellis
authored andcommitted
Add instructions for local registry
Add instructions to use a local registry with the function builder API on faasd. Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
1 parent 86af5e7 commit b89f64a

1 file changed

Lines changed: 99 additions & 11 deletions

File tree

docs/edge/builder.md

Lines changed: 99 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,83 @@ The builder runs as a non-root user making use of user namespaces in Linux.
1111
* Docker must not be installed on the host system.
1212
* faasd-pro version 0.2.23 or later is required.
1313

14-
## Create a registry secret
14+
## Configure a registry
1515

16-
For testing purposes, you can use an ephemeral registry which requires no authentication such as [ttl.sh](https://ttl.sh).
16+
We will be deploying a local container registry as an additional service with faasd and configure the function builder to push images to it.
1717

18-
Bear in mind that this ephemeral cluster is public, and have much more latency than your final production setup.
18+
Create the credentials that will be used to login to the registry. The following commands create credentials for a user named faasd.
19+
The credentials are saved to the file `/var/lib/faasd/registry/auth/htpasswd` in a hashed format, you’ll also need to take a copy of the plaintext version of the password, so that you can authenticate
20+
to the registry.
1921

20-
```bash
21-
sudo tee /var/lib/faasd/secrets/docker-config <<EOF
22-
{
23-
}
22+
Ensure `htpasswd`is installed on your system:
23+
24+
```sh
25+
# On Debian run:
26+
sudo apt install apache2-utils
27+
28+
# On RHEL run:
29+
sudo dnf install httpd-tools
30+
```
31+
32+
```sh
33+
export PASSWORD=$(openssl rand -base64 16)
34+
echo $PASSWORD > ~/registry-password.txt
35+
36+
htpasswd -Bbc ./htpasswd faasd $PASSWORD
37+
sudo mv ~/htpasswd /var/lib/faasd/registry/auth/htpasswd
38+
```
39+
40+
Create a configuration file for the registry:
41+
42+
```sh
43+
sudo cat >> /var/lib/faasd/registry/config.yml <<EOF
44+
version: 0.1
45+
log:
46+
accesslog:
47+
disabled: true
48+
level: warn
49+
formatter: text
50+
51+
storage:
52+
filesystem:
53+
rootdirectory: /var/lib/registry
54+
auth:
55+
htpasswd:
56+
realm: basic-realm
57+
path: /etc/registry/htpasswd
58+
http:
59+
addr: 0.0.0.0:5000
60+
relativeurls: false
61+
draintimeout: 60s
2462
EOF
2563
```
2664

27-
For production use, create a secret with a proper authenticated registry, see the notes on the [Function Builder API for Kubernetes](/openfaas-pro/builder).
65+
Create a crednetials file that can be use by faasd and the pro-builder to push and pull images from the registry. The faas-cli has a utility command that can be used to create the credentials file:
66+
67+
```sh
68+
cat ~/registry-password.txt | faas-cli registry-login \
69+
--server http://registry:5000 \
70+
--username faasd \
71+
--password-stdin
72+
```
73+
74+
We are using the `--server` flag to point to the local registry using its internal service name and port.
75+
76+
The file will be created in the `.credentials` folder. Copy the file so that it can be accessed by faasd and the function builder:
77+
78+
```sh
79+
# Ensure faasd-provider can pull images from the faasd service".
80+
sudo cp ./credentials/config.json /var/lib/faasd/.docker/config.json
81+
# Ensure the pro-builder can mount the credentials file.
82+
sudo cp ./credentials/config.json /var/lib/faasd/secrets/docker-config
83+
```
84+
85+
Just like the registry the function builder will be running as a faasd service and is able to reach the registry using the internal service name.
86+
To be able to access the registry from the host machine, update the `/etc/hosts` file. This ensures the faasd-provider can also access the registry using the same service name.
87+
88+
```sh
89+
echo "127.0.0.1 registry" | sudo tee -a /etc/hosts
90+
```
2891

2992
## Create a payload secret
3093

@@ -39,6 +102,24 @@ openssl rand -base64 32 | sudo tee /var/lib/faasd/secrets/payload-secret
39102
Add the following services to your `docker-compose.yaml` file:
40103

41104
```yaml
105+
registry:
106+
image: docker.io/library/registry:3
107+
volumes:
108+
- type: bind
109+
source: ./registry/data
110+
target: /var/lib/registry
111+
- type: bind
112+
source: ./registry/auth
113+
target: /etc/registry/
114+
read_only: true
115+
- type: bind
116+
source: ./registry/config.yml
117+
target: /etc/docker/registry/config.yml
118+
read_only: true
119+
deploy:
120+
replicas: 1
121+
ports:
122+
- "127.0.0.1:5000:5000"
42123
pro-builder:
43124
depends_on: [buildkit]
44125
user: "app"
@@ -113,11 +194,19 @@ Add the following services to your `docker-compose.yaml` file:
113194
114195
Now use faas-cli to perform a test build on the faasd host directly.
115196
197+
Scaffold a new function for testing:
198+
116199
```bash
117200
faas-cli new --lang python3-http \
118-
--prefix ttl.sh/openfaas-tests \
201+
--prefix registry:5000/functions \
119202
pytest
203+
```
204+
205+
The `--prefix` flag is used to set prefix for the function image to our local registry.
120206

207+
Build the function using the function builder API and deploy it:
208+
209+
```bash
121210
sudo cp /var/lib/faasd/secrets/payload-secret ./payload-secret
122211

123212
faas-cli up \
@@ -149,7 +238,7 @@ faas-cli up \
149238
curl -s http://127.0.0.1:8080/function/pytest
150239
```
151240

152-
The second run will be quicker due to caching, however the temporary ttl.sh registry will still slow things down more than you'll see in production.
241+
The second run will be quicker due to caching.
153242

154243
## Turn off access to the Function Builder API via the host
155244

@@ -161,4 +250,3 @@ You should be calling the function builder via its internal service name http://
161250
ports:
162251
- "127.0.0.1:8088:8080"
163252
```
164-

0 commit comments

Comments
 (0)