You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ja...@apache.org on 2018/02/14 18:35:01 UTC

[incubator-openwhisk-runtime-swift] branch master updated: add swift 4.1 experimental using beta build (#22)

This is an automated email from the ASF dual-hosted git repository.

jamesthomas 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 fc4d28c  add swift 4.1 experimental using beta build (#22)
fc4d28c is described below

commit fc4d28c50b4f5035b0d67e298b054845533f7392
Author: Carlos Santana <cs...@gmail.com>
AuthorDate: Wed Feb 14 13:34:59 2018 -0500

    add swift 4.1 experimental using beta build (#22)
---
 .gitignore                                         |   6 +-
 README.md                                          |   4 ++
 ansible/environments/local/group_vars/all          |   6 ++
 core/swift41Action/Dockerfile                      |  75 ++++++++++++++++++++
 core/swift41Action/build.gradle                    |  36 ++++++++++
 core/swift41Action/buildandrecord.py               |  77 +++++++++++++++++++++
 settings.gradle                                    |   1 +
 tests/dat/build.sh                                 |   2 +
 tests/dat/build/swift4.1/HelloSwift4.zip           | Bin 0 -> 11161 bytes
 tests/dat/build/swift4.1/SwiftyRequest.zip         | Bin 0 -> 153630 bytes
 .../Swift40ActionContainerTests.scala              |   2 +-
 .../Swift41ActionContainerTests.scala              |  28 ++++++++
 tests/src/test/scala/sdk/Swift41SDKTests.scala     |  26 +++++++
 tools/build/compile.sh                             |   5 ++
 tools/travis/build.sh                              |   1 +
 tools/travis/publish.sh                            |   5 +-
 16 files changed, 270 insertions(+), 4 deletions(-)

diff --git a/.gitignore b/.gitignore
index 6d89211..92a5d97 100644
--- a/.gitignore
+++ b/.gitignore
@@ -68,6 +68,8 @@ ansible/roles/nginx/files/*cert.pem
 
 # .zip files must be explicited whitelisted
 !tests/dat/build/swift311/HelloSwift3.zip
-!tests/dat/build/swift4/HelloSwift4.zip
-!tests/dat/build/swift4/SwiftyRequest.zip
+!tests/dat/build/swift4.0/HelloSwift4.zip
+!tests/dat/build/swift4.0/SwiftyRequest.zip
+!tests/dat/build/swift4.1/HelloSwift4.zip
+!tests/dat/build/swift4.1/SwiftyRequest.zip
 
diff --git a/README.md b/README.md
index 06cb22f..7ee82ac 100644
--- a/README.md
+++ b/README.md
@@ -150,6 +150,10 @@ docker login
 ./gradlew core:swift40Action:distDocker -PdockerImagePrefix=$prefix-user -PdockerRegistry=docker.io 
 ```
 
+### Swift 4.1 Experimental
+We have a runtime for swift 4.1, is experimental as we are trying beta builds released by Swift org.
+Follow same insructions for Swift 4.0 above and replace the kind wih `swift:4.1` and image with `openwhisk/action-swift-v4.0`
+
 
 ### Using Swift 3.1.1
 To use as a docker action
diff --git a/ansible/environments/local/group_vars/all b/ansible/environments/local/group_vars/all
index 66e70f7..3eb2358 100755
--- a/ansible/environments/local/group_vars/all
+++ b/ansible/environments/local/group_vars/all
@@ -49,5 +49,11 @@ runtimes_manifest:
       image:
         name: "action-swift-v4.0"
       deprecated: false
+    - kind: "swift:4.1"
+      default: false
+      image:
+        name: "action-swift-v4.1"
+      deprecated: false
+
   blackboxes:
     - name: "dockerskeleton"
diff --git a/core/swift41Action/Dockerfile b/core/swift41Action/Dockerfile
new file mode 100644
index 0000000..c7a336a
--- /dev/null
+++ b/core/swift41Action/Dockerfile
@@ -0,0 +1,75 @@
+# TODO Replace this dockerfile and extend from official image when 4.1 is released
+FROM ibmcom/ubuntu:14.04
+LABEL Description="Linux Ubuntu 14.04 image with the Swift binaries and tools."
+
+USER root
+
+# Set environment variables for image
+ENV SWIFT_SNAPSHOT swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-13-a
+ENV SWIFT_SNAPSHOT_LOWERCASE swift-4.1-branch
+ENV UBUNTU_VERSION ubuntu14.04
+ENV UBUNTU_VERSION_NO_DOTS ubuntu1404
+ENV WORK_DIR /
+
+# Set WORKDIR
+WORKDIR ${WORK_DIR}
+
+# Linux OS utils and libraries and set clang 3.8 as default
+RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y \
+  build-essential \
+  clang-3.8 \
+  git \
+  libpython2.7 \
+  libicu-dev \
+  wget \
+  libcurl4-openssl-dev \
+  vim \
+  && apt-get clean \
+  && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
+  && update-alternatives --quiet --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.8 100 \
+  && update-alternatives --quiet --install /usr/bin/clang clang /usr/bin/clang-3.8 100 \
+  && echo "set -o vi" >> /root/.bashrc
+
+# Install Swift compiler
+RUN wget https://swift.org/builds/$SWIFT_SNAPSHOT_LOWERCASE/$UBUNTU_VERSION_NO_DOTS/$SWIFT_SNAPSHOT/$SWIFT_SNAPSHOT-$UBUNTU_VERSION.tar.gz \
+    https://swift.org/builds/$SWIFT_SNAPSHOT_LOWERCASE/$UBUNTU_VERSION_NO_DOTS/$SWIFT_SNAPSHOT/$SWIFT_SNAPSHOT-$UBUNTU_VERSION.tar.gz.sig \
+  && gpg --keyserver hkp://pool.sks-keyservers.net \
+      --recv-keys \
+      '7463 A81A 4B2E EA1B 551F  FBCF D441 C977 412B 37AD' \
+      '1BE1 E29A 084C B305 F397  D62A 9F59 7F4D 21A5 6D5F' \
+      'A3BA FD35 56A5 9079 C068  94BD 63BC 1CFE 91D3 06C6' \
+      '5E4D F843 FB06 5D7F 7E24  FBA2 EF54 30F0 71E1 B235' \
+      '8513 444E 2DA3 6B7C 1659  AF4D 7638 F1FB 2B2B 08C4' \
+  && gpg --keyserver hkp://pool.sks-keyservers.net --refresh-keys  \
+  && gpg --verify $SWIFT_SNAPSHOT-$UBUNTU_VERSION.tar.gz.sig \
+  && tar xzvf $SWIFT_SNAPSHOT-$UBUNTU_VERSION.tar.gz --strip-components=1 \
+  && rm $SWIFT_SNAPSHOT-$UBUNTU_VERSION.tar.gz \
+  && rm $SWIFT_SNAPSHOT-$UBUNTU_VERSION.tar.gz.sig \
+  && chmod -R go+r /usr/lib/swift \
+  && swift --version
+
+
+# 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
+ADD https://raw.githubusercontent.com/apache/incubator-openwhisk-runtime-docker/dockerskeleton%401.1.0/core/actionProxy/actionproxy.py /actionProxy/actionproxy.py
+
+# Add files needed to build and run action
+RUN mkdir -p /swift4Action/spm-build/Sources/Action
+ADD epilogue.swift /swift4Action
+ADD buildandrecord.py /swift4Action
+ADD swift4runner.py /swift4Action
+ADD spm-build/Package.swift /swift4Action/spm-build
+ADD spm-build/_Whisk.swift /swift4Action/spm-build/Sources/Action
+
+
+# Build
+RUN touch /swift4Action/spm-build/Sources/Action/main.swift
+RUN python /swift4Action/buildandrecord.py && rm /swift4Action/spm-build/.build/release/Action
+#RUN cd /swift4Action/spm-build; swift build -v -c release; rm /swift4Action/spm-build/.build/release/Action
+ENV FLASK_PROXY_PORT 8080
+EXPOSE 8080
+
+CMD ["/bin/bash", "-c", "cd /swift4Action && PYTHONIOENCODING='utf-8' python -u swift4runner.py"]
\ No newline at end of file
diff --git a/core/swift41Action/build.gradle b/core/swift41Action/build.gradle
new file mode 100755
index 0000000..895dc46
--- /dev/null
+++ b/core/swift41Action/build.gradle
@@ -0,0 +1,36 @@
+ext.dockerImageName = 'action-swift-v4.1'
+apply from: '../../gradle/docker.gradle'
+
+distDocker.dependsOn 'copyEpilogue'
+distDocker.dependsOn 'copySwiftRunner'
+distDocker.dependsOn 'copyWhisk'
+distDocker.dependsOn 'copyPackageSwift'
+distDocker.finalizedBy('cleanup')
+
+
+task copyEpilogue(type: Copy) {
+    from '../swift40Action/epilogue.swift'
+    into '.'
+}
+
+task copySwiftRunner(type: Copy) {
+    from '../swift40Action/swift4runner.py'
+    into '.'
+}
+
+task copyWhisk(type: Copy) {
+    from '../swift40Action/spm-build/_Whisk.swift'
+    into './spm-build'
+}
+
+task copyPackageSwift(type: Copy) {
+    from '../swift40Action/spm-build/Package.swift'
+    into './spm-build'
+}
+
+task cleanup(type: Delete) {
+    delete 'epilogue.swift'
+    delete 'swift4runner.py'
+    delete 'spm-build/_Whisk.swift'
+    delete 'spm-build/Package.swift'
+}
diff --git a/core/swift41Action/buildandrecord.py b/core/swift41Action/buildandrecord.py
new file mode 100755
index 0000000..9a47163
--- /dev/null
+++ b/core/swift41Action/buildandrecord.py
@@ -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 -target x86_64-unknown-linux -sdk / -L /swift4Action/spm-build/.build/x86_64-unknown-linux/release -o /swift4Action/spm-build/.build/x86_64-unknown-linux/release/Action -module-name Action -emit-executable -Xlinker '-rpath=$ORIGIN'"
+GENERATED_BUILD_SCRIPT = "/swift4Action/spm-build/swiftbuildandlink.sh"
+SPM_DIRECTORY = "/swift4Action/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)
diff --git a/settings.gradle b/settings.gradle
index ef62d3b..3ebed6d 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -11,6 +11,7 @@ include 'tests'
 include 'core:swift3.1.1Action'
 
 include 'core:swift40Action'
+include 'core:swift41Action'
 
 rootProject.name = 'runtime-swift'
 
diff --git a/tests/dat/build.sh b/tests/dat/build.sh
index 9abee43..1fbd0c1 100755
--- a/tests/dat/build.sh
+++ b/tests/dat/build.sh
@@ -4,3 +4,5 @@ set -e
 ../../tools/build/compile.sh  HelloSwift3 swift:3.1.1 "-v"
 ../../tools/build/compile.sh  HelloSwift4 swift:4.0 "-v"
 ../../tools/build/compile.sh  SwiftyRequest swift:4.0 "-v"
+../../tools/build/compile.sh  HelloSwift4 swift:4.1 "-v"
+../../tools/build/compile.sh  SwiftyRequest swift:4.1 "-v"
diff --git a/tests/dat/build/swift4.1/HelloSwift4.zip b/tests/dat/build/swift4.1/HelloSwift4.zip
new file mode 100644
index 0000000..22cb502
Binary files /dev/null and b/tests/dat/build/swift4.1/HelloSwift4.zip differ
diff --git a/tests/dat/build/swift4.1/SwiftyRequest.zip b/tests/dat/build/swift4.1/SwiftyRequest.zip
new file mode 100644
index 0000000..819b65a
Binary files /dev/null and b/tests/dat/build/swift4.1/SwiftyRequest.zip differ
diff --git a/tests/src/test/scala/actionContainers/Swift40ActionContainerTests.scala b/tests/src/test/scala/actionContainers/Swift40ActionContainerTests.scala
index 586b912..f1a84ac 100644
--- a/tests/src/test/scala/actionContainers/Swift40ActionContainerTests.scala
+++ b/tests/src/test/scala/actionContainers/Swift40ActionContainerTests.scala
@@ -27,7 +27,7 @@ class Swift40ActionContainerTests extends SwiftActionContainerTests {
 
   override lazy val swiftContainerImageName = "action-swift-v4.0"
   override lazy val swiftBinaryName = System.getProperty("user.dir") + "/dat/build/swift4.0/HelloSwift4.zip"
-  val partyCompile = System.getProperty("user.dir") + "/dat/build/swift4.0/SwiftyRequest.zip"
+  lazy val partyCompile = System.getProperty("user.dir") + "/dat/build/swift4.0/SwiftyRequest.zip"
 
   val httpCode = """
        | import Dispatch
diff --git a/tests/src/test/scala/actionContainers/Swift41ActionContainerTests.scala b/tests/src/test/scala/actionContainers/Swift41ActionContainerTests.scala
new file mode 100644
index 0000000..5530f64
--- /dev/null
+++ b/tests/src/test/scala/actionContainers/Swift41ActionContainerTests.scala
@@ -0,0 +1,28 @@
+/*
+ * 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 runtime.actionContainers
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+
+@RunWith(classOf[JUnitRunner])
+class Swift41ActionContainerTests extends Swift40ActionContainerTests {
+  override lazy val swiftContainerImageName = "action-swift-v4.1"
+  override lazy val swiftBinaryName = System.getProperty("user.dir") + "/dat/build/swift4.1/HelloSwift4.zip"
+  override lazy val partyCompile = System.getProperty("user.dir") + "/dat/build/swift4.1/SwiftyRequest.zip"
+}
diff --git a/tests/src/test/scala/sdk/Swift41SDKTests.scala b/tests/src/test/scala/sdk/Swift41SDKTests.scala
new file mode 100644
index 0000000..267f15a
--- /dev/null
+++ b/tests/src/test/scala/sdk/Swift41SDKTests.scala
@@ -0,0 +1,26 @@
+/*
+ * 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 runtime.sdk
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+
+@RunWith(classOf[JUnitRunner])
+class Swift41SDKTests extends Swift40SDKTests {
+  override lazy val actionKind = "swift:4.1"
+}
diff --git a/tools/build/compile.sh b/tools/build/compile.sh
index c75646e..952feeb 100755
--- a/tools/build/compile.sh
+++ b/tools/build/compile.sh
@@ -20,6 +20,11 @@ elif [ ${2} == "swift:4.0" ]; then
   BASE_PATH="/swift4Action"
   DEST_SOURCE="/$BASE_PATH/spm-build/Sources/Action"
   OUTPUT_DIR="build/swift4.0"
+elif [ ${2} == "swift:4.1" ]; then
+  RUNTIME="action-swift-v4.1"
+  BASE_PATH="/swift4Action"
+  DEST_SOURCE="/$BASE_PATH/spm-build/Sources/Action"
+  OUTPUT_DIR="build/swift4.1"
 else
   echo "Error: Kind $2 not recognize"
   exit 3
diff --git a/tools/travis/build.sh b/tools/travis/build.sh
index 409ea99..f0aa297 100755
--- a/tools/travis/build.sh
+++ b/tools/travis/build.sh
@@ -16,6 +16,7 @@ cd $ROOTDIR
 TERM=dumb ./gradlew \
 :core:swift3.1.1Action:distDocker \
 :core:swift40Action:distDocker \
+:core:swift41Action:distDocker \
 -PdockerImagePrefix=${IMAGE_PREFIX}
 
 
diff --git a/tools/travis/publish.sh b/tools/travis/publish.sh
index 0cac35c..97f2ed0 100755
--- a/tools/travis/publish.sh
+++ b/tools/travis/publish.sh
@@ -15,9 +15,12 @@ IMAGE_TAG=$3
 
 if [ ${RUNTIME_VERSION} == "3.1.1" ]; then
   RUNTIME="swift3.1.1Action"
-elif [ ${RUNTIME_VERSION} == "4" ]; then
+elif [ ${RUNTIME_VERSION} == "4.0" ]; then
   RUNTIME="swift40Action"
 fi
+elif [ ${RUNTIME_VERSION} == "4.1" ]; then
+  RUNTIME="swift41Action"
+fi
 
 if [[ ! -z ${DOCKER_USER} ]] && [[ ! -z ${DOCKER_PASSWORD} ]]; then
 docker login -u "${DOCKER_USER}" -p "${DOCKER_PASSWORD}"

-- 
To stop receiving notification emails like this one, please contact
jamesthomas@apache.org.