Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes for swift 4 #17

Merged
merged 4 commits into from
Feb 4, 2018
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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down Expand Up @@ -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
```
Expand Down Expand Up @@ -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
Expand Down
29 changes: 20 additions & 9 deletions core/actionProxy/actionproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/swift4Action/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 /
Expand Down
3 changes: 1 addition & 2 deletions core/swift4Action/epilogue.swift
Original file line number Diff line number Diff line change
@@ -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)!


Expand Down
2 changes: 0 additions & 2 deletions core/swift4Action/swift4runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
5 changes: 1 addition & 4 deletions tests/dat/build.sh
Original file line number Diff line number Diff line change
@@ -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"
Binary file modified tests/dat/build/swift4/HelloSwift4.zip
Binary file not shown.
Binary file modified tests/dat/build/swift4/SwiftyRequest.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

}