This is an automated email from the ASF dual-hosted git repository. dubeejw pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-swift.git
The following commit(s) were added to refs/heads/master by this push: new 08dcc42 Various fixes for swift 4 (#17) 08dcc42 is described below commit 08dcc4240e0f111ed5e6b51fe26195cadc206436 Author: Carlos Santana <csantan...@gmail.com> AuthorDate: Sun Feb 4 03:40:20 2018 -0500 Various fixes for swift 4 (#17) * update to swift 4.0.3 * allow large input params for swift4 * fix typos in readme * update test to use 1MB value --- README.md | 5 ++-- core/actionProxy/actionproxy.py | 29 ++++++++++++++------- core/swift4Action/Dockerfile | 2 +- core/swift4Action/epilogue.swift | 3 +-- core/swift4Action/swift4runner.py | 2 -- tests/dat/build.sh | 5 +--- tests/dat/build/swift4/HelloSwift4.zip | Bin 10806 -> 10670 bytes tests/dat/build/swift4/SwiftyRequest.zip | Bin 123392 -> 160343 bytes .../Swift4ActionContainerTests.scala | 17 ++++++++++++ 9 files changed, 43 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 26b44e0..1ce1104 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Apache OpenWhisk runtimes for swift + [![Build Status](https://travis-ci.org/apache/incubator-openwhisk-runtime-swift.svg?branch=master)](https://travis-ci.org/apache/incubator-openwhisk-runtime-swift) @@ -110,7 +111,7 @@ let package = Package( ### Migrating from Swift 3 to Swift 4 ### Helper compile.sh helper script -When compiling and packaging your swift 4 now there are a couple of differences +When compiling and packaging your swift 4 action, there are a couple of differences. All your source code needs to be copy to `/swift4Action/spm-build/Sources/Action/` instead of `/swift3Action/spm-build/` You Package.swift needs to have the first line with a comment indicating swift4 tooling and format ``` @@ -199,7 +200,7 @@ wskdev fresh -t local-swift To use as docker action push to your own dockerhub account ``` -docker tag whisk/swift8action $user_prefix/action-swift-v3.1.1 +docker tag whisk/action-swift-v3.1.1 $user_prefix/action-swift-v3.1.1 docker push $user_prefix/action-swift-v3.1.1 ``` Then create the action using your the image from dockerhub diff --git a/core/actionProxy/actionproxy.py b/core/actionProxy/actionproxy.py index 10ee2a9..7021615 100644 --- a/core/actionProxy/actionproxy.py +++ b/core/actionProxy/actionproxy.py @@ -128,18 +128,29 @@ class ActionRunner: try: input = json.dumps(args) - p = subprocess.Popen( - [self.binary, input], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - env=env) + if len(input) > 131071: # MAX_ARG_STRLEN (131071) linux/binfmts.h + # pass argument via stdin + p = subprocess.Popen( + [self.binary], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + env=env) + else: + # pass argument via stdin and command parameter + p = subprocess.Popen( + [self.binary, input], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + env=env) + # run the process and wait until it completes. + # stdout/stderr will always be set because we passed PIPEs to Popen + (o, e) = p.communicate(input=input.encode()) + except Exception as e: return error(e) - # run the process and wait until it completes. - # stdout/stderr will always be set because we passed PIPEs to Popen - (o, e) = p.communicate() - # stdout/stderr may be either text or bytes, depending on Python # version, so if bytes, decode to text. Note that in Python 2 # a string will match both types; so also skip decoding in that case diff --git a/core/swift4Action/Dockerfile b/core/swift4Action/Dockerfile index bc8b7ee..71a28ac 100755 --- a/core/swift4Action/Dockerfile +++ b/core/swift4Action/Dockerfile @@ -1,6 +1,6 @@ # Dockerfile for swift actions, overrides and extends ActionRunner from actionProxy # This Dockerfile is partially based on: https://github.com/IBM-Swift/swift-ubuntu-docker/blob/master/swift-development/Dockerfile -FROM ibmcom/swift-ubuntu:4.0 +FROM ibmcom/swift-ubuntu:4.0.3 # Set WORKDIR WORKDIR / diff --git a/core/swift4Action/epilogue.swift b/core/swift4Action/epilogue.swift index e6a9b15..17a4fb3 100644 --- a/core/swift4Action/epilogue.swift +++ b/core/swift4Action/epilogue.swift @@ -1,8 +1,7 @@ // Imports import Foundation -let env = ProcessInfo.processInfo.environment -let inputStr: String = env["WHISK_INPUT"] ?? "{}" +let inputStr: String = readLine() ?? "{}" let json = inputStr.data(using: .utf8, allowLossyConversion: true)! diff --git a/core/swift4Action/swift4runner.py b/core/swift4Action/swift4runner.py index d74a748..3071ac9 100644 --- a/core/swift4Action/swift4runner.py +++ b/core/swift4Action/swift4runner.py @@ -104,8 +104,6 @@ class Swift4Runner(ActionRunner): def env(self, message): env = ActionRunner.env(self, message) - args = message.get('value', {}) if message else {} - env['WHISK_INPUT'] = json.dumps(args) return env diff --git a/tests/dat/build.sh b/tests/dat/build.sh index 4ddad8f..e52dd67 100755 --- a/tests/dat/build.sh +++ b/tests/dat/build.sh @@ -1,9 +1,6 @@ #!/bin/bash set -e - ../../tools/build/compile.sh HelloSwift3 swift:3.1.1 "-v" - ../../tools/build/compile.sh HelloSwift4 swift:4 "-v" - - +../../tools/build/compile.sh SwiftyRequest swift:4 "-v" diff --git a/tests/dat/build/swift4/HelloSwift4.zip b/tests/dat/build/swift4/HelloSwift4.zip index 0b919c0..b230a07 100644 Binary files a/tests/dat/build/swift4/HelloSwift4.zip and b/tests/dat/build/swift4/HelloSwift4.zip differ diff --git a/tests/dat/build/swift4/SwiftyRequest.zip b/tests/dat/build/swift4/SwiftyRequest.zip index a43fab6..78ed395 100644 Binary files a/tests/dat/build/swift4/SwiftyRequest.zip and b/tests/dat/build/swift4/SwiftyRequest.zip differ diff --git a/tests/src/test/scala/actionContainers/Swift4ActionContainerTests.scala b/tests/src/test/scala/actionContainers/Swift4ActionContainerTests.scala index 9ad15ac..ada14ee 100644 --- a/tests/src/test/scala/actionContainers/Swift4ActionContainerTests.scala +++ b/tests/src/test/scala/actionContainers/Swift4ActionContainerTests.scala @@ -91,4 +91,21 @@ class Swift4ActionContainerTests extends SwiftActionContainerTests { }) } + it should "receive a large (1MB) argument" in { + withActionContainer() { c => + val code = """ + | func main(args: [String: Any]) -> [String: Any] { + | return args + | } + |""".stripMargin + + val (initCode, initRes) = c.init(initPayload(code)) + initCode should be(200) + + val arg = JsObject("arg" -> JsString(("a" * 1048561))) + val (_, runRes) = c.run(runPayload(arg)) + runRes.get shouldBe arg + } + } + } -- To stop receiving notification emails like this one, please contact dube...@apache.org.