forked from apache/openwhisk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Swift 3.1.1 as a kind (apache#2120)
* Experimental branch for 2079, uses ibm swift ubuntu image for 3.1 * Fixes issue apache#2079, add Swift 3.1.1 runtime kind, update Swift dependencies for Watson SDK, KituraNet, SwiftyJson * add apache license * Fix swift311 location and catch docker brake The location of the swift binary for 311 is now in /usr/bin/swift Need to catch docker errors when building by usig && instead of ; * new zip for new swift311 runtime
- Loading branch information
1 parent
01dcd1c
commit 3b5815f
Showing
21 changed files
with
366 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# 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:3.1.1 | ||
|
||
# Set WORKDIR | ||
WORKDIR / | ||
|
||
# Upgrade and install basic Python dependencies | ||
RUN apt-get -y update \ | ||
&& apt-get -y install --fix-missing python2.7 python-gevent python-flask zip | ||
|
||
# Add the action proxy | ||
RUN mkdir -p /actionProxy | ||
ADD actionproxy.py /actionProxy | ||
|
||
# Add files needed to build and run action | ||
RUN mkdir -p /swift3Action | ||
ADD epilogue.swift /swift3Action | ||
ADD buildandrecord.py /swift3Action | ||
ADD swift3runner.py /swift3Action | ||
ADD spm-build /swift3Action/spm-build | ||
|
||
|
||
# Build kitura net | ||
RUN touch /swift3Action/spm-build/main.swift | ||
RUN python /swift3Action/buildandrecord.py && rm /swift3Action/spm-build/.build/release/Action | ||
#RUN cd /swift3Action/spm-build; swift build -v -c release; rm /swift3Action/spm-build/.build/release/Action | ||
ENV FLASK_PROXY_PORT 8080 | ||
|
||
CMD ["/bin/bash", "-c", "cd /swift3Action && PYTHONIOENCODING='utf-8' python -u swift3runner.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
ext.dockerImageName = 'action-swift-v3.1.1' | ||
apply from: '../../gradle/docker.gradle' | ||
distDocker.dependsOn 'copyProxy' | ||
distDocker.dependsOn 'copyEpilogue' | ||
distDocker.dependsOn 'copySwiftRunner' | ||
distDocker.dependsOn 'copyWhisk' | ||
distDocker.dependsOn 'copyWhiskJsonUtils' | ||
distDocker.finalizedBy('cleanup') | ||
|
||
task copyProxy(type: Copy) { | ||
from '../actionProxy/actionproxy.py' | ||
into './actionproxy.py' | ||
} | ||
|
||
task copyEpilogue(type: Copy) { | ||
from '../swift3Action/epilogue.swift' | ||
into '.' | ||
} | ||
|
||
task copySwiftRunner(type: Copy) { | ||
from '../swift3Action/swift3runner.py' | ||
into '.' | ||
} | ||
|
||
task copyWhisk(type: Copy) { | ||
from '../swift3Action/spm-build/_Whisk.swift' | ||
into './spm-build' | ||
} | ||
|
||
task copyWhiskJsonUtils(type: Copy) { | ||
from '../swift3Action/spm-build/_WhiskJSONUtils.swift' | ||
into './spm-build' | ||
} | ||
|
||
task cleanup(type: Delete) { | ||
delete 'actionproxy.py' | ||
delete 'epilogue.swift' | ||
delete 'swift3runner.py' | ||
delete 'spm-build/_Whisk.swift' | ||
delete 'spm-build/_WhiskJSONUtils.swift' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
"""Python to generate build script. | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
""" | ||
from __future__ import print_function | ||
import os | ||
import sys | ||
from subprocess import check_output | ||
|
||
# Settings | ||
COMPILE_PREFIX = "/usr/bin/swiftc -module-name Action " | ||
LINKER_PREFIX = "/usr/bin/swiftc -Xlinker '-rpath=$ORIGIN' '-L/swift3Action/spm-build/.build/release' -o '/swift3Action/spm-build/.build/release/Action'" | ||
GENERATED_BUILD_SCRIPT = "/swift3Action/spm-build/swiftbuildandlink.sh" | ||
SPM_DIRECTORY = "/swift3Action/spm-build" | ||
BUILD_COMMAND = ["swift", "build", "-v", "-c", "release"] | ||
|
||
# Build Swift package and capture step trace | ||
print("Building action") | ||
out = check_output(BUILD_COMMAND, cwd=SPM_DIRECTORY) | ||
print("action built. Decoding compile and link commands") | ||
|
||
# Look for compile and link commands in step trace | ||
compileCommand = None | ||
linkCommand = None | ||
|
||
buildInstructions = out.decode("utf-8").splitlines() | ||
|
||
for instruction in buildInstructions: | ||
if instruction.startswith(COMPILE_PREFIX): | ||
compileCommand = instruction | ||
|
||
# add flag to quiet warnings | ||
compileCommand += " -suppress-warnings" | ||
|
||
elif instruction.startswith(LINKER_PREFIX): | ||
linkCommand = instruction | ||
|
||
# if found, create build script, otherwise exit with error | ||
if compileCommand is not None and linkCommand is not None: | ||
print("Generated OpenWhisk Compile command: %s" % compileCommand) | ||
print("=========") | ||
print("Generated OpenWhisk Link command: %s" % linkCommand) | ||
|
||
with open(GENERATED_BUILD_SCRIPT, "a") as buildScript: | ||
buildScript.write("#!/bin/bash\n") | ||
buildScript.write("echo \"Compiling\"\n") | ||
buildScript.write("%s\n" % compileCommand) | ||
buildScript.write("swiftStatus=$?\n") | ||
buildScript.write("echo swiftc status is $swiftStatus\n") | ||
buildScript.write("if [[ \"$swiftStatus\" -eq \"0\" ]]; then\n") | ||
buildScript.write("echo \"Linking\"\n") | ||
buildScript.write("%s\n" % linkCommand) | ||
buildScript.write("else\n") | ||
buildScript.write(">2& echo \"Action did not compile\"\n") | ||
buildScript.write("exit 1\n") | ||
buildScript.write("fi") | ||
|
||
os.chmod(GENERATED_BUILD_SCRIPT, 0o777) | ||
sys.exit(0) | ||
else: | ||
print("Cannot generate build script: compile or link command not found") | ||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2015-2016 IBM Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "Action", | ||
dependencies: [ | ||
.Package(url: "https://github.com/IBM-Swift/CCurl.git", "0.2.3"), | ||
.Package(url: "https://github.com/IBM-Swift/Kitura-net.git", "1.7.10"), | ||
.Package(url: "https://github.com/IBM-Swift/SwiftyJSON.git", "15.0.1"), | ||
.Package(url: "https://github.com/watson-developer-cloud/swift-sdk.git", "0.16.0") | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
tests/src/test/scala/actionContainers/Swift311ActionContainerTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package actionContainers | ||
|
||
import org.junit.runner.RunWith | ||
import org.scalatest.junit.JUnitRunner | ||
|
||
@RunWith(classOf[JUnitRunner]) | ||
class Swift311ActionContainerTests extends Swift3ActionContainerTests { | ||
override lazy val swiftContainerImageName = "action-swift-v3.1.1" | ||
|
||
override lazy val watsonCode = """ | ||
| import AlchemyDataNewsV1 | ||
| import ConversationV1 | ||
| import DiscoveryV1 | ||
| import DocumentConversionV1 | ||
| import NaturalLanguageClassifierV1 | ||
| import NaturalLanguageUnderstandingV1 | ||
| import PersonalityInsightsV3 | ||
| import RetrieveAndRankV1 | ||
| import ToneAnalyzerV3 | ||
| import TradeoffAnalyticsV1 | ||
| import VisualRecognitionV3 | ||
| | ||
| func main(args: [String:Any]) -> [String:Any] { | ||
| return ["message": "I compiled and was able to import Watson SDKs"] | ||
| } | ||
""".stripMargin | ||
override lazy val swiftBinaryName = "helloSwift311.zip" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.