Skip to content

Commit

Permalink
πŸ› fix(workflows): fix docker run command in faas_fn_build_invoke.yml
Browse files Browse the repository at this point in the history
πŸ“ docs(README.adoc): update project description and add third party code section
✨ feat(examples): add bb-map-context example
πŸ”§ chore(stack.yml): add bb-http-map-context function to stack
πŸ”§ chore(template): add author, url, and license metadata to index.clj and tests.clj
πŸ”§ chore(template): add author, contributors, url, and license metadata to json.clj
  • Loading branch information
ccfontes committed Aug 20, 2023
1 parent d868917 commit 20aa51f
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 27 deletions.
22 changes: 13 additions & 9 deletions .github/workflows/faas_fn_build_invoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ jobs:
(docker stop my-bb-http-function || exit 0)
(docker rm my-bb-http-function || exit 0)
faas build -f my-bb-http-function.yml
docker run -d --name my-bb-http-function ghcr.io/${{ github.repository_owner }}/my-bb-http-function:latest ./index.clj
(docker my-bb-http-function bb-http || exit 0)
(docker my-bb-http-function bb-http || exit 0)
docker run -d --name my-bb-http-function ghcr.io/${{ github.repository_owner }}/my-bb-http-function:latest bb index.clj
if [ "$(docker exec my-bb-http-function curl -X POST --data-raw "Hello world" --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != "Hello world" ]; then
exit 2
fi
Expand All @@ -52,13 +54,15 @@ jobs:
exit 3
fi
docker run -i ghcr.io/${{ github.repository_owner }}/bb-streaming-lib:latest function/handler-test.clj
(docker stop bb-http || exit 0)
(docker rm bb-http || exit 0)
docker run -d --name bb-http ghcr.io/${{ github.repository_owner }}/bb-http:latest ./index.clj
if [ "$(docker exec bb-http curl -X POST --data-raw "world" --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != "Hello, world" ]; then
(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 index.clj
if [ "$(docker exec bb-http-map curl -X POST --data-raw '{"foo": "bar", "spam": "eggs"}' --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo","spam"],["bar","eggs"],"application/json",false]' ]; then
exit 4
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 index.clj
if [ "$(docker exec bb-http-map-context curl -X POST --data-raw "world" --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo","spam"],["bar","eggs"],"application/json",true]' ]; then
exit 5
fi
# 1. one arg: text -> text, string with environment var
# 2. two args: json -> json, update map with header
# 2.1. keywords=false
# 2.2. keywords=true
16 changes: 7 additions & 9 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@
:url-ci-status-lychee-link: "{url-proj}/actions/workflows/broken-link-checker.yml"
:img-license: https://img.shields.io/badge/license-MIT-black.svg

= OpenFaaS Babashka template

image:{img-ci-tests-status}[link={url-ci-status-tests}]
image:{img-ci-hadolint-status}[link={url-ci-status-hadolint}]
image:{img-ci-clj-kondo-status}[link={url-ci-status-clj-kondo}]
image:{img-ci-lychee-link-check-status}[link={url-ci-status-lychee-link}]
image:{img-license}[link=LICENSE]
= faas-bb image:{img-ci-tests-status}[link={url-ci-status-tests}] image:{img-ci-hadolint-status}[link={url-ci-status-hadolint}] image:{img-ci-clj-kondo-status}[link={url-ci-status-clj-kondo}] image:{img-ci-lychee-link-check-status}[link={url-ci-status-lychee-link}] image:{img-license}[link=LICENSE]

An https://github.com/openfaas[OpenFaaS] template for writing Functions in https://github.com/babashka/babashka[Babashka].

Expand Down Expand Up @@ -136,8 +130,12 @@ Contributions are welcome! If you find a bug or have an idea for a new feature,

The template may benefit from some common middleware functions, such as those offered in the https://github.com/ring-clojure/ring-defaults/blob/master/src/ring/middleware/defaults.clj[ring-defaults library]. Users are welcome to recommend integrating any middleware they think would be useful for handling common web application needs.

== Third party code

link:template/bb/ring/middleware/json.clj[ring.middleware.json] is derived from https://github.com/ring-clojure/ring-json/blob/master/src/ring/middleware/json.clj[ring-son] to work with Babashka, originally authored by James Reeves and used under the MIT license.

== link:LICENSE[License]

Copyright (c) 2023 Carlos da Cunha Fontes
Copyright (c) 2023 Carlos da Cunha Fontes.

The MIT License
This project is licensed under the MIT License. See link:LICENSE[LICENSE] for details.
1 change: 1 addition & 0 deletions examples/http/bb-map-context/bb.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:paths ["."]}
4 changes: 4 additions & 0 deletions examples/http/bb-map-context/handler.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(ns function.handler)

(defn handler [content {:keys [headers env]}]
[(keys content) (vals content) (:content-type headers) (:keywords env)])
4 changes: 2 additions & 2 deletions examples/http/bb-map/handler.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns function.handler)

(defn handler [content {:keys [headers env]}]
[content (:content-type headers) (:keywords env)])
(defn handler [content]
[(keys content) (vals content)])
6 changes: 6 additions & 0 deletions examples/stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@ functions:
lang: bb
handler: ./http/bb-map
image: ${DOCKER_REGISTRY_IMG_ORG_PATH}/bb-http-map
environment:
keywords: false
bb-http-map-context:
lang: bb
handler: ./http/bb-map-context
image: ${DOCKER_REGISTRY_IMG_ORG_PATH}/bb-http-map-context
environment:
keywords: true
9 changes: 5 additions & 4 deletions template/bb/index.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
(ns index
(ns index ^{:author "Carlos da Cunha Fontes"
:url "https://github.com/ccfontes/faas-bb"
:license {:name "Distributed under the MIT License"
:url "https://github.com/ccfontes/faas-bb/blob/main/LICENSE"}}
(:require
[clojure.walk :refer [keywordize-keys]]
[clojure.string :as str :refer [lower-case]]
Expand Down Expand Up @@ -55,6 +58,4 @@
@(promise))

; TODO:
; e2e tests in CI
; insert aknowledgement in the ring-json middleware
; template pull e2e test
; manually template pull e2e test
6 changes: 5 additions & 1 deletion template/bb/ring/middleware/json.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
(ns ring.middleware.json
^{:author "James Reeves"
:contributors "Modified by Carlos da Cunha Fontes to work with Babashka"
:url "https://github.com/ring-clojure/ring-json"
:license {:name "Distributed under the MIT License, the same as Ring."}}
"Ring middleware for parsing JSON requests and generating JSON responses."
(:require [cheshire.core :as json])
(:import [java.io InputStream]))
Expand Down Expand Up @@ -110,7 +114,7 @@
JSON is malformed. See: wrap-json-params."
[request options]
(if-let [[valid? json] (read-json request options)]
(if valid? (assoc-json-params request json))
(when valid? (assoc-json-params request json))
request))

(defn wrap-json-params
Expand Down
7 changes: 5 additions & 2 deletions template/bb/tests.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
(ns tests
(ns tests ^{:author "Carlos da Cunha Fontes"
:url "https://github.com/ccfontes/faas-bb"
:license {:name "Distributed under the MIT License"
:url "https://github.com/ccfontes/faas-bb/blob/main/LICENSE"}}
(:require
[clojure.test :refer [run-tests]]
[eg :refer [eg]]
Expand All @@ -16,7 +19,7 @@

(eg index/->kebab-case
"" => ""
"Boo_baR" => "bo-bar")
"Boo_baR" => "boo-bar")

(eg index/format-context
{} => {}
Expand Down

0 comments on commit 20aa51f

Please sign in to comment.