Skip to content

Commit 18270cc

Browse files
authored
Support array result include sequence action (#129)
1 parent d239ef5 commit 18270cc

File tree

6 files changed

+74
-12
lines changed

6 files changed

+74
-12
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,34 @@ The following Python runtime versions (with kind & image labels) are generated b
3232

3333
This README documents the build, customization and testing of these runtime images.
3434

35+
So a very simple `hello world` function would be:
36+
37+
```python
38+
def main(args):
39+
name = args.get("name", "stranger")
40+
greeting = "Hello " + name + "!"
41+
print(greeting)
42+
return {"greeting": greeting}
43+
```
44+
45+
For the return result, not only support `dictionary` but also support `array`
46+
47+
So a very simple `hello array` function would be:
48+
49+
```python
50+
def main(args):
51+
return ["a", "b"]
52+
```
53+
54+
And support array result for sequence action as well, the first action's array result can be used as next action's input parameter.
55+
56+
So the function can be:
57+
58+
```python
59+
def main(args):
60+
return args
61+
```
62+
3563
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).
3664

3765
## Build Runtimes

core/python310Action/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ RUN git clone --branch ${GO_PROXY_GITHUB_BRANCH} \
2626

2727
# or build it from a release
2828
FROM golang:1.18 AS builder_release
29-
ARG GO_PROXY_RELEASE_VERSION=1.18@1.19.0
29+
ARG GO_PROXY_RELEASE_VERSION=1.18@1.20.0
3030
RUN curl -sL \
3131
https://github.com/apache/openwhisk-runtime-go/archive/{$GO_PROXY_RELEASE_VERSION}.tar.gz\
3232
| tar xzf -\
3333
&& cd openwhisk-runtime-go-*/main\
34-
&& GO111MODULE=on go build -o /bin/proxy
34+
&& GO111MODULE=on CGO_ENABLED=0 go build -o /bin/proxy
3535

3636
FROM python:3.10-buster
3737

core/python36AiAction/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#
1717

1818
# build go proxy from source
19-
FROM golang:1.16 AS builder_source
19+
FROM golang:1.18 AS builder_source
2020
ARG GO_PROXY_GITHUB_USER=apache
2121
ARG GO_PROXY_GITHUB_BRANCH=master
2222
RUN git clone --branch ${GO_PROXY_GITHUB_BRANCH} \
@@ -25,13 +25,13 @@ RUN git clone --branch ${GO_PROXY_GITHUB_BRANCH} \
2525
mv proxy /bin/proxy
2626

2727
# or build it from a release
28-
FROM golang:1.16 AS builder_release
29-
ARG GO_PROXY_RELEASE_VERSION=1.16@1.19.0
28+
FROM golang:1.18 AS builder_release
29+
ARG GO_PROXY_RELEASE_VERSION=1.18@1.20.0
3030
RUN curl -sL \
3131
https://github.com/apache/openwhisk-runtime-go/archive/${GO_PROXY_RELEASE_VERSION}.tar.gz\
3232
| tar xzf -\
3333
&& cd openwhisk-runtime-go-*/main\
34-
&& GO111MODULE=on go build -o /bin/proxy
34+
&& GO111MODULE=on CGO_ENABLED=0 go build -o /bin/proxy
3535

3636
# Dockerfile for python AI actions, overrides and extends ActionRunner from actionProxy
3737
FROM tensorflow/tensorflow:1.15.2-py3-jupyter

core/python39Action/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ RUN git clone --branch ${GO_PROXY_GITHUB_BRANCH} \
2626

2727
# or build it from a release
2828
FROM golang:1.18 AS builder_release
29-
ARG GO_PROXY_RELEASE_VERSION=1.18@1.19.0
29+
ARG GO_PROXY_RELEASE_VERSION=1.18@1.20.0
3030
RUN curl -sL \
3131
https://github.com/apache/openwhisk-runtime-go/archive/{$GO_PROXY_RELEASE_VERSION}.tar.gz\
3232
| tar xzf -\
3333
&& cd openwhisk-runtime-go-*/main\
34-
&& GO111MODULE=on go build -o /bin/proxy
34+
&& GO111MODULE=on CGO_ENABLED=0 go build -o /bin/proxy
3535

3636
FROM python:3.9-buster
3737

core/python3Action/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#
1717

1818
# build go proxy from source
19-
FROM golang:1.16 AS builder_source
19+
FROM golang:1.18 AS builder_source
2020
ARG GO_PROXY_GITHUB_USER=apache
2121
ARG GO_PROXY_GITHUB_BRANCH=master
2222
RUN git clone --branch ${GO_PROXY_GITHUB_BRANCH} \
@@ -25,13 +25,13 @@ RUN git clone --branch ${GO_PROXY_GITHUB_BRANCH} \
2525
mv proxy /bin/proxy
2626

2727
# or build it from a release
28-
FROM golang:1.16 AS builder_release
29-
ARG GO_PROXY_RELEASE_VERSION=1.16@1.19.0
28+
FROM golang:1.18 AS builder_release
29+
ARG GO_PROXY_RELEASE_VERSION=1.18@1.20.0
3030
RUN curl -sL \
3131
https://github.com/apache/openwhisk-runtime-go/archive/{$GO_PROXY_RELEASE_VERSION}.tar.gz\
3232
| tar xzf -\
3333
&& cd openwhisk-runtime-go-*/main\
34-
&& GO111MODULE=on go build -o /bin/proxy
34+
&& GO111MODULE=on CGO_ENABLED=0 go build -o /bin/proxy
3535

3636
FROM python:3.7-buster
3737

tests/src/test/scala/runtime/actionContainers/PythonBasicTests.scala

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,38 @@ abstract class PythonBasicTests extends BasicActionRunnerTests with WskActorSyst
317317
runRes.get.fields.get("sys").get.toString() should include("python")
318318
}
319319
}
320+
321+
it should "support return array result" in {
322+
withActionContainer() { c =>
323+
val code =
324+
"""
325+
|def main(args):
326+
| return ["a", "b"]
327+
""".stripMargin
328+
329+
val (initCode, res) = c.init(initPayload(code))
330+
initCode should be(200)
331+
332+
val (runCode, runRes) = c.runForJsArray(runPayload(JsObject()))
333+
runCode should be(200)
334+
runRes shouldBe Some(JsArray(JsString("a"), JsString("b")))
335+
}
336+
}
337+
338+
it should "support array as input param" in {
339+
withActionContainer() { c =>
340+
val code =
341+
"""
342+
|def main(args):
343+
| return args
344+
""".stripMargin
345+
346+
val (initCode, res) = c.init(initPayload(code))
347+
initCode should be(200)
348+
349+
val (runCode, runRes) = c.runForJsArray(runPayload(JsArray(JsString("a"), JsString("b"))))
350+
runCode should be(200)
351+
runRes shouldBe Some(JsArray(JsString("a"), JsString("b")))
352+
}
353+
}
320354
}

0 commit comments

Comments
 (0)