You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/02/04 08:40:24 UTC

[GitHub] dubeejw closed pull request #17: Various fixes for swift 4

dubeejw closed pull request #17: Various fixes for swift 4
URL: https://github.com/apache/incubator-openwhisk-runtime-swift/pull/17
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 @@ def error(msg):
 
         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 @@ def build(self, init_message):
 
     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
+    }
+  }
+
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services