From 11355271f932b80b821ce427d5766b73653eea65 Mon Sep 17 00:00:00 2001 From: Carlos Fontes Date: Mon, 6 Nov 2023 06:29:08 +0000 Subject: [PATCH 1/8] Add routing example using bell --- .github/workflows/faas_fn_build_invoke.yml | 10 ++++++++++ README.adoc | 3 +-- examples/http/bb-routes-bell/bb.edn | 2 ++ examples/http/bb-routes-bell/handler.clj | 11 +++++++++++ examples/stack.yml | 4 ++++ template/bb/bb.edn | 1 + template/bb/index.clj | 1 - 7 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 examples/http/bb-routes-bell/bb.edn create mode 100644 examples/http/bb-routes-bell/handler.clj diff --git a/.github/workflows/faas_fn_build_invoke.yml b/.github/workflows/faas_fn_build_invoke.yml index 45e6461..22fdc9f 100644 --- a/.github/workflows/faas_fn_build_invoke.yml +++ b/.github/workflows/faas_fn_build_invoke.yml @@ -72,3 +72,13 @@ jobs: if [ "$(docker exec bb-http-map-context curl -X POST -d '{"foo": "bar", "spam": "eggs"}' -H 'content-type: application/json' --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo","spam"],["bar","eggs"],"application/json","http://127.0.0.1:8082"]' ]; then exit 7 fi + + (docker stop bb-routes-bell || exit 0) + (docker rm bb-routes-bell || exit 0) + docker run -d --name bb-routes-bell ghcr.io/${{ github.repository_owner }}/bb-routes-bell:latest bb --main index + if [ "$(docker exec bb-routes-bell curl -X POST -d '{"foo": "bar"}' -H 'content-type: application/json' --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo","spam"]]; then + exit 8 + fi + if [ "$(docker exec bb-routes-bell curl -X PUT --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082/foo/123)" != '[["id"],["123"]]; then + exit 9 + fi diff --git a/README.adoc b/README.adoc index 8c7fe44..cbdceb2 100644 --- a/README.adoc +++ b/README.adoc @@ -100,8 +100,7 @@ In `bb-streaming` language: ---- (defn handler [event] ...) ---- -The `event` is the payload body, and the function return is the payload body for the response. - +The `event` is extracted from the HTTP payload body, and the function return is used as the HTTP payload body for the response. == link:examples[Function examples] diff --git a/examples/http/bb-routes-bell/bb.edn b/examples/http/bb-routes-bell/bb.edn new file mode 100644 index 0000000..f248a6b --- /dev/null +++ b/examples/http/bb-routes-bell/bb.edn @@ -0,0 +1,2 @@ +{:paths ["."] + :deps {net.tessellator/bell {:mvn/version "0.2.0"}}} diff --git a/examples/http/bb-routes-bell/handler.clj b/examples/http/bb-routes-bell/handler.clj new file mode 100644 index 0000000..71f77cc --- /dev/null +++ b/examples/http/bb-routes-bell/handler.clj @@ -0,0 +1,11 @@ +(ns function.handler + (:require [bell.core :refer [router POST PUT]])) + +(def handler + (router + (POST "/" + (fn [{:keys [body]}] + [(keys body) (vals body)])) + (PUT "/foo/:id" + (fn [{:keys [path-params]}] + [(keys path-params) (vals path-params)])))) diff --git a/examples/stack.yml b/examples/stack.yml index f179924..6ab9612 100644 --- a/examples/stack.yml +++ b/examples/stack.yml @@ -27,3 +27,7 @@ functions: image: ${DOCKER_REGISTRY_IMG_ORG_PATH}/bb-http-map-context environment: keywords: true + bb-routes-bell: + lang: bb + handler: ./http/bb-routes-bell + image: ${DOCKER_REGISTRY_IMG_ORG_PATH}/bb-routes-bell diff --git a/template/bb/bb.edn b/template/bb/bb.edn index 8a951cf..9080da9 100644 --- a/template/bb/bb.edn +++ b/template/bb/bb.edn @@ -1,2 +1,3 @@ +; used only for tests. Not copied into docker container {:paths ["." "lib"] :deps {eg/eg {:mvn/version "0.5.6-alpha"}}} diff --git a/template/bb/index.clj b/template/bb/index.clj index 349876e..41edbc0 100755 --- a/template/bb/index.clj +++ b/template/bb/index.clj @@ -8,7 +8,6 @@ [ring.middleware.json :refer [wrap-json-body]] [ring.middleware.text :refer [wrap-text-body]] [ring.middleware.headers :refer [wrap-lowercase-headers wrap-friendly-headers]] - [ring.middleware.headers] [ring.util.walk :as ring-walk] [compojure.response :as response] [function.handler :as function])) From 0bba0fb88199f98dd30f7c4fec58f9a52555ce6c Mon Sep 17 00:00:00 2001 From: Carlos Fontes Date: Mon, 6 Nov 2023 06:32:46 +0000 Subject: [PATCH 2/8] Fix missing quote --- .github/workflows/faas_fn_build_invoke.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/faas_fn_build_invoke.yml b/.github/workflows/faas_fn_build_invoke.yml index 22fdc9f..73656ac 100644 --- a/.github/workflows/faas_fn_build_invoke.yml +++ b/.github/workflows/faas_fn_build_invoke.yml @@ -76,9 +76,9 @@ jobs: (docker stop bb-routes-bell || exit 0) (docker rm bb-routes-bell || exit 0) docker run -d --name bb-routes-bell ghcr.io/${{ github.repository_owner }}/bb-routes-bell:latest bb --main index - if [ "$(docker exec bb-routes-bell curl -X POST -d '{"foo": "bar"}' -H 'content-type: application/json' --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo","spam"]]; then + if [ "$(docker exec bb-routes-bell curl -X POST -d '{"foo": "bar"}' -H 'content-type: application/json' --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo","spam"]]'; then exit 8 fi - if [ "$(docker exec bb-routes-bell curl -X PUT --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082/foo/123)" != '[["id"],["123"]]; then + if [ "$(docker exec bb-routes-bell curl -X PUT --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082/foo/123)" != '[["id"],["123"]]'; then exit 9 fi From fd585529b498298abae559d232ed80b287d70e5f Mon Sep 17 00:00:00 2001 From: Carlos Fontes Date: Mon, 6 Nov 2023 06:42:48 +0000 Subject: [PATCH 3/8] Increase delay --- .github/workflows/faas_fn_build_invoke.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/faas_fn_build_invoke.yml b/.github/workflows/faas_fn_build_invoke.yml index 73656ac..14ffe2a 100644 --- a/.github/workflows/faas_fn_build_invoke.yml +++ b/.github/workflows/faas_fn_build_invoke.yml @@ -62,23 +62,23 @@ jobs: (docker stop bb-http-map || exit 0) (docker rm bb-http-map || exit 0) docker run -d --name bb-http-map ghcr.io/${{ github.repository_owner }}/bb-http-map:latest bb --main index - if [ "$(docker exec bb-http-map curl -X POST -d '{"foo": "bar", "spam": "eggs"}' -H 'content-type: application/json' --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo","spam"],["bar","eggs"]]' ]; then + if [ "$(docker exec bb-http-map curl -X POST -d '{"foo": "bar", "spam": "eggs"}' -H 'content-type: application/json' --retry 10 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo","spam"],["bar","eggs"]]' ]; then exit 6 fi (docker stop bb-http-map-context || exit 0) (docker rm bb-http-map-context || exit 0) docker run -d --name bb-http-map-context ghcr.io/${{ github.repository_owner }}/bb-http-map-context:latest bb --main index - if [ "$(docker exec bb-http-map-context curl -X POST -d '{"foo": "bar", "spam": "eggs"}' -H 'content-type: application/json' --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo","spam"],["bar","eggs"],"application/json","http://127.0.0.1:8082"]' ]; then + if [ "$(docker exec bb-http-map-context curl -X POST -d '{"foo": "bar", "spam": "eggs"}' -H 'content-type: application/json' --retry 10 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo","spam"],["bar","eggs"],"application/json","http://127.0.0.1:8082"]' ]; then exit 7 fi (docker stop bb-routes-bell || exit 0) (docker rm bb-routes-bell || exit 0) docker run -d --name bb-routes-bell ghcr.io/${{ github.repository_owner }}/bb-routes-bell:latest bb --main index - if [ "$(docker exec bb-routes-bell curl -X POST -d '{"foo": "bar"}' -H 'content-type: application/json' --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo","spam"]]'; then + if [ "$(docker exec bb-routes-bell curl -X POST -d '{"foo": "bar"}' -H 'content-type: application/json' --retry 10 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo","spam"]]'; then exit 8 fi - if [ "$(docker exec bb-routes-bell curl -X PUT --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082/foo/123)" != '[["id"],["123"]]'; then + if [ "$(docker exec bb-routes-bell curl -X PUT --retry 10 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082/foo/123)" != '[["id"],["123"]]'; then exit 9 fi From ad14d9ec72e360e6538dc1b2c4453bf214bb242b Mon Sep 17 00:00:00 2001 From: Carlos Fontes Date: Mon, 6 Nov 2023 06:46:21 +0000 Subject: [PATCH 4/8] Add missing ] --- .github/workflows/faas_fn_build_invoke.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/faas_fn_build_invoke.yml b/.github/workflows/faas_fn_build_invoke.yml index 14ffe2a..87b3bcf 100644 --- a/.github/workflows/faas_fn_build_invoke.yml +++ b/.github/workflows/faas_fn_build_invoke.yml @@ -76,9 +76,9 @@ jobs: (docker stop bb-routes-bell || exit 0) (docker rm bb-routes-bell || exit 0) docker run -d --name bb-routes-bell ghcr.io/${{ github.repository_owner }}/bb-routes-bell:latest bb --main index - if [ "$(docker exec bb-routes-bell curl -X POST -d '{"foo": "bar"}' -H 'content-type: application/json' --retry 10 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo","spam"]]'; then + if [ "$(docker exec bb-routes-bell curl -X POST -d '{"foo": "bar"}' -H 'content-type: application/json' --retry 10 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo","spam"]]' ]; then exit 8 fi - if [ "$(docker exec bb-routes-bell curl -X PUT --retry 10 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082/foo/123)" != '[["id"],["123"]]'; then + if [ "$(docker exec bb-routes-bell curl -X PUT --retry 10 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082/foo/123)" != '[["id"],["123"]] ]'; then exit 9 fi From db096545ddcdf9aa3550419652e48c7060a9fa04 Mon Sep 17 00:00:00 2001 From: Carlos Fontes Date: Mon, 6 Nov 2023 07:07:39 +0000 Subject: [PATCH 5/8] Fix test --- .github/workflows/faas_fn_build_invoke.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/faas_fn_build_invoke.yml b/.github/workflows/faas_fn_build_invoke.yml index 87b3bcf..d3093db 100644 --- a/.github/workflows/faas_fn_build_invoke.yml +++ b/.github/workflows/faas_fn_build_invoke.yml @@ -76,7 +76,7 @@ jobs: (docker stop bb-routes-bell || exit 0) (docker rm bb-routes-bell || exit 0) docker run -d --name bb-routes-bell ghcr.io/${{ github.repository_owner }}/bb-routes-bell:latest bb --main index - if [ "$(docker exec bb-routes-bell curl -X POST -d '{"foo": "bar"}' -H 'content-type: application/json' --retry 10 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo","spam"]]' ]; then + if [ "$(docker exec bb-routes-bell curl -X POST -d '{"foo": "bar"}' -H 'content-type: application/json' --retry 10 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo"],["spam"]]' ]; then exit 8 fi if [ "$(docker exec bb-routes-bell curl -X PUT --retry 10 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082/foo/123)" != '[["id"],["123"]] ]'; then From 717e18af8897a0e195cd12d3a5500d494fb2c584 Mon Sep 17 00:00:00 2001 From: Carlos Fontes Date: Mon, 6 Nov 2023 07:10:12 +0000 Subject: [PATCH 6/8] Fix test --- .github/workflows/faas_fn_build_invoke.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/faas_fn_build_invoke.yml b/.github/workflows/faas_fn_build_invoke.yml index d3093db..5e8d609 100644 --- a/.github/workflows/faas_fn_build_invoke.yml +++ b/.github/workflows/faas_fn_build_invoke.yml @@ -76,7 +76,7 @@ jobs: (docker stop bb-routes-bell || exit 0) (docker rm bb-routes-bell || exit 0) docker run -d --name bb-routes-bell ghcr.io/${{ github.repository_owner }}/bb-routes-bell:latest bb --main index - if [ "$(docker exec bb-routes-bell curl -X POST -d '{"foo": "bar"}' -H 'content-type: application/json' --retry 10 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo"],["spam"]]' ]; then + if [ "$(docker exec bb-routes-bell curl -X POST -d '{"foo": "bar"}' -H 'content-type: application/json' --retry 10 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo"],["bar"]]' ]; then exit 8 fi if [ "$(docker exec bb-routes-bell curl -X PUT --retry 10 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082/foo/123)" != '[["id"],["123"]] ]'; then From 754f5ca463c0377365ae17fbc939f701f0bb49ca Mon Sep 17 00:00:00 2001 From: Carlos Fontes Date: Mon, 6 Nov 2023 07:13:04 +0000 Subject: [PATCH 7/8] Fix test --- .github/workflows/faas_fn_build_invoke.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/faas_fn_build_invoke.yml b/.github/workflows/faas_fn_build_invoke.yml index 5e8d609..7470bc3 100644 --- a/.github/workflows/faas_fn_build_invoke.yml +++ b/.github/workflows/faas_fn_build_invoke.yml @@ -62,23 +62,23 @@ jobs: (docker stop bb-http-map || exit 0) (docker rm bb-http-map || exit 0) docker run -d --name bb-http-map ghcr.io/${{ github.repository_owner }}/bb-http-map:latest bb --main index - if [ "$(docker exec bb-http-map curl -X POST -d '{"foo": "bar", "spam": "eggs"}' -H 'content-type: application/json' --retry 10 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo","spam"],["bar","eggs"]]' ]; then + if [ "$(docker exec bb-http-map curl -X POST -d '{"foo": "bar", "spam": "eggs"}' -H 'content-type: application/json' --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo","spam"],["bar","eggs"]]' ]; then exit 6 fi (docker stop bb-http-map-context || exit 0) (docker rm bb-http-map-context || exit 0) docker run -d --name bb-http-map-context ghcr.io/${{ github.repository_owner }}/bb-http-map-context:latest bb --main index - if [ "$(docker exec bb-http-map-context curl -X POST -d '{"foo": "bar", "spam": "eggs"}' -H 'content-type: application/json' --retry 10 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo","spam"],["bar","eggs"],"application/json","http://127.0.0.1:8082"]' ]; then + if [ "$(docker exec bb-http-map-context curl -X POST -d '{"foo": "bar", "spam": "eggs"}' -H 'content-type: application/json' --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo","spam"],["bar","eggs"],"application/json","http://127.0.0.1:8082"]' ]; then exit 7 fi (docker stop bb-routes-bell || exit 0) (docker rm bb-routes-bell || exit 0) docker run -d --name bb-routes-bell ghcr.io/${{ github.repository_owner }}/bb-routes-bell:latest bb --main index - if [ "$(docker exec bb-routes-bell curl -X POST -d '{"foo": "bar"}' -H 'content-type: application/json' --retry 10 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo"],["bar"]]' ]; then + if [ "$(docker exec bb-routes-bell curl -X POST -d '{"foo": "bar"}' -H 'content-type: application/json' --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo"],["bar"]]' ]; then exit 8 fi - if [ "$(docker exec bb-routes-bell curl -X PUT --retry 10 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082/foo/123)" != '[["id"],["123"]] ]'; then + if [ "$(docker exec bb-routes-bell curl -X PUT --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082/foo/123)" != '[["id"],["123"]] ]'; then exit 9 fi From b748f943d9b6752c40ab3b36322f5de37827947c Mon Sep 17 00:00:00 2001 From: Carlos Fontes Date: Mon, 6 Nov 2023 09:01:01 +0000 Subject: [PATCH 8/8] Fix quote --- .github/workflows/faas_fn_build_invoke.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/faas_fn_build_invoke.yml b/.github/workflows/faas_fn_build_invoke.yml index 7470bc3..1639f2b 100644 --- a/.github/workflows/faas_fn_build_invoke.yml +++ b/.github/workflows/faas_fn_build_invoke.yml @@ -79,6 +79,6 @@ jobs: if [ "$(docker exec bb-routes-bell curl -X POST -d '{"foo": "bar"}' -H 'content-type: application/json' --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo"],["bar"]]' ]; then exit 8 fi - if [ "$(docker exec bb-routes-bell curl -X PUT --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082/foo/123)" != '[["id"],["123"]] ]'; then + if [ "$(docker exec bb-routes-bell curl -X PUT --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082/foo/123)" != '[["id"],["123"]]' ]; then exit 9 fi