Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions core/python310Action/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 GO_PROXY_RELEASE_VERSION=1.18@1.19.0
ARG GO_PROXY_RELEASE_VERSION=1.18@1.20.0
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

Expand Down
8 changes: 4 additions & 4 deletions core/python36AiAction/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
Expand All @@ -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 GO_PROXY_RELEASE_VERSION=1.16@1.19.0
FROM golang:1.18 AS builder_release
ARG GO_PROXY_RELEASE_VERSION=1.18@1.20.0
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
Expand Down
4 changes: 2 additions & 2 deletions core/python39Action/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 GO_PROXY_RELEASE_VERSION=1.18@1.19.0
ARG GO_PROXY_RELEASE_VERSION=1.18@1.20.0
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

Expand Down
8 changes: 4 additions & 4 deletions core/python3Action/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
Expand All @@ -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 GO_PROXY_RELEASE_VERSION=1.16@1.19.0
FROM golang:1.18 AS builder_release
ARG GO_PROXY_RELEASE_VERSION=1.18@1.20.0
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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
}
}
}