Skip to content

Commit 2e3c00d

Browse files
committed
deployer (tbc)
1 parent e147790 commit 2e3c00d

15 files changed

Lines changed: 1002 additions & 80 deletions

File tree

.env.example

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@ KUBERNETES_CERT_FILENAME=./tokens/ca.crt
1212
# if not set, the image is build with local tag and will not be pushed
1313
REGISTRY=
1414
# namespace is required if REGISTRY is set
15-
NAMESPACE=
15+
NAMESPACE=
16+
17+
REGISTRY_HOST=http://127.0.0.1:5000
18+
REGISTRY_USER=opsuser
19+
REGISTRY_PASS=password
20+
21+
ADMIN_API_URL=http://127.0.0.1:5002

README.md

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,23 @@ Available APIs at the moment:
3434

3535
`PATCH /system/api/v1/auth/{login}` - Update the user password patching the corresponding wsku/\<login\> entry.
3636

37+
### Build API
38+
39+
`POST /system/api/build` - Perform the build of a custom image and push it to repository.
40+
41+
More informations [Here](docs/DEPLOYER.md)
42+
3743
### Info API
3844

3945
`GET /system/info` - Info endpoint
4046

41-
4247
## Developer instructions
4348

4449
You need to have access to be Apache OpenServerless admin and have access to kubernetes cluster.
4550

4651
Refer to the [Apache OpenServerless installation page](https://openserverless.apache.org/docs/installation/install/docker/):
4752

48-
Give the command `task setup-developer` and it will:
53+
Give the command `task dev:setup-developer` and it will:
4954

5055
- extract the required ca.crt and token from operator service account
5156
- copy a sample .env file
@@ -61,14 +66,22 @@ Open http://localhost:5002/system/apidocs/ to see the API documentation.
6166
Taskfile supports the following tasks:
6267

6368
```yaml
64-
* build: Build the image locally
65-
* build-and-load: Build the image and loads it to local Kind cluster
66-
* buildx: Build the docker image using buildx. Set PUSH=1 to push the image to the registry.
67-
* docker-login: Login to the docker registry. Set REGISTRY=ghcr or REGISTRY=dockerhub in .env to use the respective registry.
68-
* get-tokens: Get Service Account tokens and save them to tokens directory
69-
* image-tag: Create a new tag for the current git commit.
70-
* run: Run the admin api locally, using configuration from .env file
71-
* setup-developer: Setup developer environment
69+
* build: Build the image locally
70+
* build-and-load: Build the image and loads it to local Kind cluster
71+
* buildx: Build the docker image using buildx. Set PUSH=1 to push the image to the registry.
72+
* docker-login: Login to the docker registry. Set REGISTRY=ghcr or REGISTRY=dockerhub in .env to use the respective registry.
73+
* image-tag: Create a new tag for the current git commit.
74+
* builder:cleanjobs: Clean up old jobs
75+
* builder:delete-image: Delete an image from the registry
76+
* builder:get-image: Get an image from the registry
77+
* builder:list-catalogs: List catalogs in the registry
78+
* builder:list-images: List images in a specific catalog
79+
* builder:logs: Show logs of the last build job
80+
* builder:send: Send the build to the server
81+
* builder:updatetoml: Update the buildkitd.toml file config map
82+
* dev:get-tokens: Get Service Account tokens and save them to tokens directory
83+
* dev:run: Run the admin api locally, using configuration from .env file
84+
* dev:setup-developer: Setup developer environment
7285
```
7386

7487
## Build and push
@@ -128,4 +141,8 @@ $ git push apache 0.1.0-incubating.2507270910
128141
```
129142

130143
This will trigger the build workflow, and the process will be visible at
131-
https://github.com/apache/openserverless-admin-api/actions
144+
https://github.com/apache/openserverless-admin-api/actions
145+
146+
## Additional Documentation
147+
148+
- [Deployer](docs/DEPLOYER.md)

Taskfile.yml

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,14 @@ vars:
2727

2828
dotenv:
2929
- .env
30-
31-
tasks:
3230

33-
get-tokens:
34-
desc: "Get Service Account tokens and save them to tokens directory"
35-
silent: true
36-
cmds:
37-
- mkdir -p tokens
38-
- kubectl get secret nuvolaris-wsku-secret -o jsonpath='{.data.token}' | base64 --decode > tokens/token
39-
- kubectl get secret nuvolaris-wsku-secret -o jsonpath='{.data.ca\.crt}' | base64 --decode > tokens/ca.crt
31+
includes:
32+
builder:
33+
taskfile: TaskfileBuilder.yml
34+
dev:
35+
taskfile: TaskfileDev.yml
4036

41-
setup-developer:
42-
desc: "Setup developer environment"
43-
silent: true
44-
cmds:
45-
- task: get-tokens
46-
- |
47-
if [ ! -f .env ];
48-
then cp .env.example .env
49-
echo "Please edit .env file with your local CouchDB and Kubernetes credentials"
50-
fi
51-
- |
52-
if [ ! -d .venv ];
53-
then uv venv
54-
fi
55-
- uv pip install -r pyproject.toml 2>/dev/null
37+
tasks:
5638

5739
docker-login-ghcr: >
5840
silent: true
@@ -144,9 +126,3 @@ tasks:
144126
BASEIMG=$(task base-image-name)
145127
IMG="$BASEIMG:{{.TAG}}"
146128
kind load docker-image $IMG --name=nuvolaris
147-
148-
run:
149-
desc: |
150-
Run the admin api locally, using configuration from .env file
151-
cmds:
152-
- uv run -m openserverless

TaskfileBuilder.yml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
19+
version: '3'
20+
21+
tasks:
22+
23+
send:
24+
desc: Send the build to the server
25+
vars:
26+
AUTH:
27+
sh: cat ~/.wskprops | grep "AUTH" | cut -d'=' -f2 | xargs -I {}
28+
cmds:
29+
- if test -z "{{.SOURCE}}"; then echo "SOURCE IS NOT SET" && exit 1; fi
30+
- if test -z "{{.TARGET}}"; then echo "TARGET IS NOT SET" && exit 1; fi
31+
- if test -z "{{.KIND}}"; then echo "KIND IS NOT SET" && exit 1; fi
32+
- |
33+
echo '{"source": "{{.SOURCE}}", "target": "{{.TARGET}}", "kind": "{{.KIND}}", "file": "{{.REQUIREMENTS}}" }' | http POST $ADMIN_API_URL/system/build Content-Type:application/json Authorization:"{{.AUTH}}"
34+
- sleep 5
35+
- task: logs
36+
deps:
37+
- cleanjobs
38+
# - updatetoml
39+
silent: true
40+
41+
logs:
42+
desc: Show logs of the last build job
43+
cmds:
44+
- kubectl -n nuvolaris logs $(kubectl get jobs.batch -o name | grep "build-") -c buildkit --follow
45+
silent: false
46+
47+
cleanjobs:
48+
desc: Clean up old jobs
49+
cmds:
50+
- for I in $(kubectl get jobs -n nuvolaris | grep build | awk '{ print $1 }' | tr "\n" " "); do kubectl delete job $I; done
51+
- for I in $(kubectl get cm -n nuvolaris | grep "cm-" | awk '{ print $1 }' | tr "\n" " "); do kubectl delete cm $I; done
52+
silent: true
53+
54+
updatetoml:
55+
desc: Update the buildkitd.toml file config map
56+
cmds:
57+
- |
58+
if test $(kubectl -n nuvolaris get cm -o name | grep nuvolaris-buildkitd-conf | wc -l) -gt 0;
59+
then kubectl -n nuvolaris delete configmap nuvolaris-buildkitd-conf
60+
fi
61+
- kubectl -n nuvolaris create configmap nuvolaris-buildkitd-conf --from-file=deploy/buildkit/buildkitd.toml
62+
silent: true
63+
64+
list-catalogs:
65+
desc: List catalogs in the registry
66+
cmds:
67+
- http -a $REGISTRY_USER:$REGISTRY_PASS GET "${REGISTRY_HOST}/v2/_catalog"
68+
silent: false
69+
70+
list-images:
71+
desc: List images in a specific catalog
72+
vars:
73+
CATALOG: '{{.CATALOG}}'
74+
cmds:
75+
- if test -z "{{.CATALOG}}"; then echo "CATALOG IS NOT SET" && exit 1; fi
76+
- http -a $REGISTRY_USER:$REGISTRY_PASS GET "${REGISTRY_HOST}/v2/{{.CATALOG}}/tags/list"
77+
silent: false
78+
79+
get-image:
80+
desc: Get an image from the registry
81+
vars:
82+
IMAGE: '{{.IMAGE}}'
83+
IMAGE_NAME:
84+
sh: echo '{{.IMAGE}}' | cut -d':' -f1
85+
HASH:
86+
sh: echo '{{.IMAGE}}' | cut -d':' -f2
87+
cmds:
88+
- echo "Getting image {{.IMAGE_NAME}} with hash {{.HASH}}"
89+
- http -a $REGISTRY_USER:$REGISTRY_PASS GET "${REGISTRY_HOST}/v2/{{.IMAGE_NAME}}/manifests/{{.HASH}}"
90+
silent: false
91+
92+
delete-image:
93+
desc: Delete an image from the registry
94+
vars:
95+
IMAGE: '{{.IMAGE}}'
96+
IMAGE_NAME:
97+
sh: echo '{{.IMAGE}}' | cut -d':' -f1
98+
HASH:
99+
sh: echo '{{.IMAGE}}' | cut -d':' -f2
100+
MANIFEST_DIGEST:
101+
sh: http --headers -a $REGISTRY_USER:$REGISTRY_PASS GET "${REGISTRY_HOST}/v2/{{.IMAGE_NAME}}/manifests/{{.HASH}}" | grep -i 'Docker-Content-Digest:' | awk '{print $2}' | tr -d '\r'
102+
cmds:
103+
- echo 'Deleting image {{.IMAGE}}'
104+
- echo "Deleting manifest {{.MANIFEST_DIGEST}} for image {{.IMAGE_NAME}}"
105+
- http -a $REGISTRY_USER:$REGISTRY_PASS DELETE "${REGISTRY_HOST}/v2/{{.IMAGE_NAME}}/manifests/{{.MANIFEST_DIGEST}}"
106+
silent: false

TaskfileDev.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
19+
version: '3'
20+
21+
tasks:
22+
get-tokens:
23+
desc: "Get Service Account tokens and save them to tokens directory"
24+
silent: true
25+
cmds:
26+
- mkdir -p tokens
27+
- kubectl get secret nuvolaris-wsku-secret -o jsonpath='{.data.token}' | base64 --decode > tokens/token
28+
- kubectl get secret nuvolaris-wsku-secret -o jsonpath='{.data.ca\.crt}' | base64 --decode > tokens/ca.crt
29+
30+
setup-developer:
31+
desc: "Setup developer environment"
32+
silent: true
33+
cmds:
34+
- task: get-tokens
35+
- |
36+
if [ ! -f .env ];
37+
then cp .env.example .env
38+
echo "Please edit .env file with your local CouchDB and Kubernetes credentials"
39+
fi
40+
- |
41+
if [ ! -d .venv ];
42+
then uv venv
43+
fi
44+
- uv pip install -r pyproject.toml 2>/dev/null
45+
46+
run:
47+
desc: |
48+
Run the admin api locally, using configuration from .env file
49+
cmds:
50+
- uv run -m openserverless

deploy/buildkit/buildkitd.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# =========================
2+
# Worker OCI (rootlesskit)
3+
# =========================
4+
[worker.oci]
5+
enabled = true
6+
rootless = true
7+
no-process-sandbox = true
8+
snapshotter = "overlayfs" # usa overlayfs se il kernel lo consente
9+
10+
[worker.containerd]
11+
enabled = false
12+
13+
# =========================
14+
# Registry HTTP insicuro
15+
# =========================
16+
[registry."nuvolaris-registry-svc:5000"]
17+
insecure = true
18+
http = true
19+
20+
# =========================
21+
# Logging
22+
# =========================
23+
[log]
24+
level = "debug"

deploy/samples/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
gnews
2+
beautifulsoup4

docs/DEPLOYER.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<!--
2+
~ Licensed to the Apache Software Foundation (ASF) under one
3+
~ or more contributor license agreements. See the NOTICE file
4+
~ distributed with this work for additional information
5+
~ regarding copyright ownership. The ASF licenses this file
6+
~ to you under the Apache License, Version 2.0 (the
7+
~ "License"); you may not use this file except in compliance
8+
~ with the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing,
13+
~ software distributed under the License is distributed on an
14+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
~ KIND, either express or implied. See the License for the
16+
~ specific language governing permissions and limitations
17+
~ under the License.
18+
~
19+
-->
20+
# Deployer
21+
22+
These tasks are useful to interact with OpenServerless Admin Api Builder
23+
24+
There are some tasks to interact with OpenServerless internal registry too.
25+
26+
## Available tasks
27+
28+
task: Available tasks for this project:
29+
30+
```
31+
* builder:cleanjobs: Clean up old jobs
32+
* builder:delete-image: Delete an image from the registry
33+
* builder:get-image: Get an image from the registry
34+
* builder:list-catalogs: List catalogs in the registry
35+
* builder:list-images: List images in a specific catalog
36+
* builder:logs: Show logs of the last build job
37+
* builder:send: Send the build to the server
38+
* builder:updatetoml: Update the buildkitd.toml file config map
39+
```
40+
41+
## Examples
42+
43+
### Build a custom runtime
44+
45+
`task builder:send SOURCE=apache/openserverless-runtime-python:v3.13-2506091954 TARGET=devel:python3.13-custom KIND=python REQUIREMENTS=$(base64 -i deploy/samples/requirements.txt)`
46+
47+
### List images for the user
48+
49+
`task builder:list-images CATALOG=devel`
50+
51+
### Delete an image for the user
52+
53+
`task builder:delete-image IMAGE=devel:alpine`
54+
55+
# Useful Links
56+
57+
- https://crazymax.dev/buildkit/user-guides/rootless-mode/
58+
- https://www.linkedin.com/pulse/kubernetes-v133-user-namespaces-revolutionizing-false-rodrigo-mqoif/
59+
- https://chatgpt.com/c/689c9b5b-1d3c-8333-9f25-19d016fdacd0
60+
- https://kubernetes.io/docs/concepts/workloads/pods/user-namespaces/

0 commit comments

Comments
 (0)