This is an automated email from the ASF dual-hosted git repository.
dgrove pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwhisk-runtime-python.git
The following commit(s) were added to refs/heads/master by this push:
new 18270cc Support array result include sequence action (#129)
18270cc is described below
commit 18270cca17d48cef2358c6e8d9ea361ba950a04c
Author: ningyougang <[email protected]>
AuthorDate: Mon Aug 15 23:15:01 2022 +0800
Support array result include sequence action (#129)
---
README.md | 28 ++++++++++++++++++
core/python310Action/Dockerfile | 4 +--
core/python36AiAction/Dockerfile | 8 ++---
core/python39Action/Dockerfile | 4 +--
core/python3Action/Dockerfile | 8 ++---
.../actionContainers/PythonBasicTests.scala | 34 ++++++++++++++++++++++
6 files changed, 74 insertions(+), 12 deletions(-)
diff --git a/README.md b/README.md
index a85e69c..642ad07 100644
--- a/README.md
+++ b/README.md
@@ -32,6 +32,34 @@ The following Python runtime versions (with kind & image
labels) are generated b
This README documents the build, customization and testing of these runtime
images.
+So a very simple `hello world` function would be:
+
+```python
+def main(args):
+ name = args.get("name", "stranger")
+ greeting = "Hello " + name + "!"
+ print(greeting)
+ return {"greeting": greeting}
+```
+
+For the return result, not only support `dictionary` but also support `array`
+
+So a very simple `hello array` function would be:
+
+```python
+def main(args):
+ return ["a", "b"]
+```
+
+And support array result for sequence action as well, the first action's array
result can be used as next action's input parameter.
+
+So the function can be:
+
+```python
+def main(args):
+ return args
+```
+
To learn more about using Python actions to build serverless applications,
check out the main project documentation
[here](https://github.com/apache/openwhisk/blob/master/docs/actions-python.md).
## Build Runtimes
diff --git a/core/python310Action/Dockerfile b/core/python310Action/Dockerfile
index e777425..d34d09b 100644
--- a/core/python310Action/Dockerfile
+++ b/core/python310Action/Dockerfile
@@ -26,12 +26,12 @@ RUN git clone --branch ${GO_PROXY_GITHUB_BRANCH} \
# or build it from a release
FROM golang:1.18 AS builder_release
-ARG [email protected]
+ARG [email protected]
RUN curl -sL \
https://github.com/apache/openwhisk-runtime-go/archive/{$GO_PROXY_RELEASE_VERSION}.tar.gz\
| tar xzf -\
&& cd openwhisk-runtime-go-*/main\
- && GO111MODULE=on go build -o /bin/proxy
+ && GO111MODULE=on CGO_ENABLED=0 go build -o /bin/proxy
FROM python:3.10-buster
diff --git a/core/python36AiAction/Dockerfile b/core/python36AiAction/Dockerfile
index b7c4ac8..c269c86 100644
--- a/core/python36AiAction/Dockerfile
+++ b/core/python36AiAction/Dockerfile
@@ -16,7 +16,7 @@
#
# build go proxy from source
-FROM golang:1.16 AS builder_source
+FROM golang:1.18 AS builder_source
ARG GO_PROXY_GITHUB_USER=apache
ARG GO_PROXY_GITHUB_BRANCH=master
RUN git clone --branch ${GO_PROXY_GITHUB_BRANCH} \
@@ -25,13 +25,13 @@ RUN git clone --branch ${GO_PROXY_GITHUB_BRANCH} \
mv proxy /bin/proxy
# or build it from a release
-FROM golang:1.16 AS builder_release
-ARG [email protected]
+FROM golang:1.18 AS builder_release
+ARG [email protected]
RUN curl -sL \
https://github.com/apache/openwhisk-runtime-go/archive/${GO_PROXY_RELEASE_VERSION}.tar.gz\
| tar xzf -\
&& cd openwhisk-runtime-go-*/main\
- && GO111MODULE=on go build -o /bin/proxy
+ && GO111MODULE=on CGO_ENABLED=0 go build -o /bin/proxy
# Dockerfile for python AI actions, overrides and extends ActionRunner from
actionProxy
FROM tensorflow/tensorflow:1.15.2-py3-jupyter
diff --git a/core/python39Action/Dockerfile b/core/python39Action/Dockerfile
index 339bc04..e09ba3b 100644
--- a/core/python39Action/Dockerfile
+++ b/core/python39Action/Dockerfile
@@ -26,12 +26,12 @@ RUN git clone --branch ${GO_PROXY_GITHUB_BRANCH} \
# or build it from a release
FROM golang:1.18 AS builder_release
-ARG [email protected]
+ARG [email protected]
RUN curl -sL \
https://github.com/apache/openwhisk-runtime-go/archive/{$GO_PROXY_RELEASE_VERSION}.tar.gz\
| tar xzf -\
&& cd openwhisk-runtime-go-*/main\
- && GO111MODULE=on go build -o /bin/proxy
+ && GO111MODULE=on CGO_ENABLED=0 go build -o /bin/proxy
FROM python:3.9-buster
diff --git a/core/python3Action/Dockerfile b/core/python3Action/Dockerfile
index 90aa17b..291b9fb 100644
--- a/core/python3Action/Dockerfile
+++ b/core/python3Action/Dockerfile
@@ -16,7 +16,7 @@
#
# build go proxy from source
-FROM golang:1.16 AS builder_source
+FROM golang:1.18 AS builder_source
ARG GO_PROXY_GITHUB_USER=apache
ARG GO_PROXY_GITHUB_BRANCH=master
RUN git clone --branch ${GO_PROXY_GITHUB_BRANCH} \
@@ -25,13 +25,13 @@ RUN git clone --branch ${GO_PROXY_GITHUB_BRANCH} \
mv proxy /bin/proxy
# or build it from a release
-FROM golang:1.16 AS builder_release
-ARG [email protected]
+FROM golang:1.18 AS builder_release
+ARG [email protected]
RUN curl -sL \
https://github.com/apache/openwhisk-runtime-go/archive/{$GO_PROXY_RELEASE_VERSION}.tar.gz\
| tar xzf -\
&& cd openwhisk-runtime-go-*/main\
- && GO111MODULE=on go build -o /bin/proxy
+ && GO111MODULE=on CGO_ENABLED=0 go build -o /bin/proxy
FROM python:3.7-buster
diff --git
a/tests/src/test/scala/runtime/actionContainers/PythonBasicTests.scala
b/tests/src/test/scala/runtime/actionContainers/PythonBasicTests.scala
index 3e06160..6cd919c 100644
--- a/tests/src/test/scala/runtime/actionContainers/PythonBasicTests.scala
+++ b/tests/src/test/scala/runtime/actionContainers/PythonBasicTests.scala
@@ -317,4 +317,38 @@ abstract class PythonBasicTests extends
BasicActionRunnerTests with WskActorSyst
runRes.get.fields.get("sys").get.toString() should include("python")
}
}
+
+ it should "support return array result" in {
+ withActionContainer() { c =>
+ val code =
+ """
+ |def main(args):
+ | return ["a", "b"]
+ """.stripMargin
+
+ val (initCode, res) = c.init(initPayload(code))
+ initCode should be(200)
+
+ val (runCode, runRes) = c.runForJsArray(runPayload(JsObject()))
+ runCode should be(200)
+ runRes shouldBe Some(JsArray(JsString("a"), JsString("b")))
+ }
+ }
+
+ it should "support array as input param" in {
+ withActionContainer() { c =>
+ val code =
+ """
+ |def main(args):
+ | return args
+ """.stripMargin
+
+ val (initCode, res) = c.init(initPayload(code))
+ initCode should be(200)
+
+ val (runCode, runRes) =
c.runForJsArray(runPayload(JsArray(JsString("a"), JsString("b"))))
+ runCode should be(200)
+ runRes shouldBe Some(JsArray(JsString("a"), JsString("b")))
+ }
+ }
}