From cc200894e1e5e56276d03874f44060f2b3fdd542 Mon Sep 17 00:00:00 2001 From: Carlos Fontes Date: Thu, 9 Nov 2023 13:13:58 +0900 Subject: [PATCH] Add bb hiccup example Function --- .github/workflows/faas_fn_build_invoke.yml | 8 ++++++++ README.adoc | 6 +++++- examples/http/bb-hiccup/bb.edn | 1 + examples/http/bb-hiccup/handler.clj | 5 +++++ examples/http/bb-hiccup/view.clj | 17 +++++++++++++++++ examples/stack.yml | 4 ++++ template/bb/Dockerfile | 2 +- 7 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 examples/http/bb-hiccup/bb.edn create mode 100644 examples/http/bb-hiccup/handler.clj create mode 100644 examples/http/bb-hiccup/view.clj diff --git a/.github/workflows/faas_fn_build_invoke.yml b/.github/workflows/faas_fn_build_invoke.yml index 1639f2b..a3e4315 100644 --- a/.github/workflows/faas_fn_build_invoke.yml +++ b/.github/workflows/faas_fn_build_invoke.yml @@ -82,3 +82,11 @@ jobs: 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 + + (docker stop bb-hiccup || exit 0) + (docker rm bb-hiccup || exit 0) + docker run -d --name bb-hiccup ghcr.io/${{ github.repository_owner }}/bb-hiccup:latest bb --main index + bb_hiccup_output=$(docker exec bb-hiccup curl -X GET -d '{"item-list": ["foo","bar","spam"]}' --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082) + if [[ "${bb_hiccup_output:0:5}" != "item-list [lst] + [:ul (for [x lst] [:li x])]) + +(defn hiccup-page [title {:keys [item-list]}] + [:html + [:head + [:title title]] + [:body + [:h1 title] + [:div {:id "item-list"} + (->item-list item-list)]]]) + +(defn render-page [title data] + (-> (hiccup-page title data) html str)) diff --git a/examples/stack.yml b/examples/stack.yml index 6ab9612..3808c60 100644 --- a/examples/stack.yml +++ b/examples/stack.yml @@ -31,3 +31,7 @@ functions: lang: bb handler: ./http/bb-routes-bell image: ${DOCKER_REGISTRY_IMG_ORG_PATH}/bb-routes-bell + bb-hiccup: + lang: bb + handler: ./http/bb-hiccup + image: ${DOCKER_REGISTRY_IMG_ORG_PATH}/bb-hiccup diff --git a/template/bb/Dockerfile b/template/bb/Dockerfile index c4951f9..2b23a89 100644 --- a/template/bb/Dockerfile +++ b/template/bb/Dockerfile @@ -12,7 +12,7 @@ ENV HOME /home/app RUN addgroup --system app && adduser --system --ingroup app app && \ mkdir -p $HOME/.deps.clj/1.11.1.1347/ClojureTools && \ mv /root/.m2 $HOME && \ - chown app:app -R $HOME/.m2 && \ + chown app:app -R $HOME && \ mv /usr/local/lib/clojure/libexec/clojure-tools-1.11.1.1347.jar $HOME/.deps.clj/1.11.1.1347/ClojureTools USER app