You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ms...@apache.org on 2019/04/25 04:56:32 UTC

[incubator-openwhisk-devtools] branch master updated: updating starter kit (#247)

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

msciabarra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-devtools.git


The following commit(s) were added to refs/heads/master by this push:
     new aab4ebe  updating starter kit (#247)
aab4ebe is described below

commit aab4ebedf7fb951c6b97207c2c13632e9a35e91b
Author: Michele Sciabarra <30...@users.noreply.github.com>
AuthorDate: Thu Apr 25 06:56:27 2019 +0200

    updating starter kit (#247)
    
    * updating starter kit
    
    * reformatted scala tests
    
    * license header in single test
    
    * scancode fixes
    
    * readme
    
    * licenses again
---
 README.md                                          |  1 +
 actionloop-starter-kit/README.md                   |  4 +-
 actionloop-starter-kit/example/Makefile            | 27 +++++------
 actionloop-starter-kit/example/__main__.py         |  1 +
 actionloop-starter-kit/example/hello.py            |  2 +
 actionloop-starter-kit/python3.7/Dockerfile        |  2 +-
 actionloop-starter-kit/python3.7/Makefile          |  8 ++--
 actionloop-starter-kit/python3.7/lib/launcher.py   |  3 +-
 .../ActionLoopPythonBasicTests.scala               | 23 ++++-----
 .../runtime/actionContainers/SingleTest.scala      | 54 ++++++++++++++++++++++
 10 files changed, 89 insertions(+), 36 deletions(-)

diff --git a/README.md b/README.md
index 0f4a2eb..9d024b6 100644
--- a/README.md
+++ b/README.md
@@ -31,6 +31,7 @@ This repository is part of [Apache OpenWhisk](http://openwhisk.incubator.apache.
 * [node-local](node-local/README.md) allows testing individual OpenWhisk functions locally, using only node.js. This is ideal if you are writing node.js functions to run in OpenWhisk, but need to emulate some of OpenWhisk's behavior in creating `params` and expecting promises.
 * [maven-java](maven-java/README.md) allows testing OpenWhisk Java Actions. This shows how to package the function dependencies e.g. external jar.
 * [knative-build](knative-build/README.md) contains Knative Build Templates along with modified versions of their respective OpenWhisk Action Runtimes that can be used to Build and Serve Knative compatible applications on Kubernetes.
+* [actionloop-starter-kit](actionloop-starter-kit/README.md) contains a starter kit to build a new runtime using the ActionLoop proxy used in Go, Swift, PHP, Python and Rust runtimes.
 
 ## Travis builds
 
diff --git a/actionloop-starter-kit/README.md b/actionloop-starter-kit/README.md
index 5503242..27a75e4 100644
--- a/actionloop-starter-kit/README.md
+++ b/actionloop-starter-kit/README.md
@@ -16,7 +16,9 @@
 # limitations under the License.
 #
 -->
-# ActionLoop Started Kit
+# ActionLoop Starter Kit
 
 Use the content of this folder to build your own ActionLoop based runtime.
 
+
+
diff --git a/actionloop-starter-kit/example/Makefile b/actionloop-starter-kit/example/Makefile
index 67d9468..4d06833 100644
--- a/actionloop-starter-kit/example/Makefile
+++ b/actionloop-starter-kit/example/Makefile
@@ -1,26 +1,27 @@
-IMG=actionloop/actionloop-demo-python-v3.7:latest
+IMG=actionloop-demo-python-v3.7:latest
 ACT=hello-demo-python
+PREFIX=docker.io/openwhisk
 
-src.zip:
+src.zip: main.rb hello.py
 	zip src.zip __main__.py hello.py
 
 bin.zip: src.zip
 	docker run -i $(IMG) -compile main <src.zip >bin.zip
 
-single:
-	wsk action update $(ACT) hello.py --docker $(IMG) --main hello
-
-src-zip: src.zip
-	wsk action update $(ACT) $< --docker $(IMG)
-
-bin-zip: bin.zip
-	wsk action update $(ACT) $< --docker $(IMG)
-
-test:
+test-single:
+	wsk action update $(ACT) hello.py --docker $(PREFIX)/$(IMG) --main hello
 	wsk action invoke $(ACT) -r
 	wsk action invoke $(ACT) -p name Mike -r
 
-.PHONE: single src-zip bin-zip
+test-src-zip: src.zip
+	wsk action update $(ACT) $< --docker $(PREFIX)/$(IMG)
+	wsk action invoke $(ACT) -r
+	wsk action invoke $(ACT) -p name Mike -r
 
+test-bin-zip: bin.zip
+	wsk action update $(ACT) $< --docker $(PREFIX)/$(IMG)
+	wsk action invoke $(ACT) -r
+	wsk action invoke $(ACT) -p name Mike -r
 
+.PHONE: test-single test-src-zip test-bin-zip
 
diff --git a/actionloop-starter-kit/example/__main__.py b/actionloop-starter-kit/example/__main__.py
index c2c04cc..a7187c9 100644
--- a/actionloop-starter-kit/example/__main__.py
+++ b/actionloop-starter-kit/example/__main__.py
@@ -14,6 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
+
 import hello
 
 def main(args):
diff --git a/actionloop-starter-kit/example/hello.py b/actionloop-starter-kit/example/hello.py
index 9f41943..1ad9cc0 100644
--- a/actionloop-starter-kit/example/hello.py
+++ b/actionloop-starter-kit/example/hello.py
@@ -14,7 +14,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
+
 def hello(args):
     name = args["name"] if "name" in args else "world"
     print("name=%s" % name)
     return {"greeting": "Hello, %s" % name }
+
diff --git a/actionloop-starter-kit/python3.7/Dockerfile b/actionloop-starter-kit/python3.7/Dockerfile
index 5b10fc8..625ddff 100644
--- a/actionloop-starter-kit/python3.7/Dockerfile
+++ b/actionloop-starter-kit/python3.7/Dockerfile
@@ -14,7 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-FROM actionloop/actionloop-v2:latest as builder
+FROM openwhisk/actionloop-v2:latest as builder
 FROM python:3.7-alpine
 RUN mkdir -p /proxy/bin /proxy/lib /proxy/action
 WORKDIR /proxy
diff --git a/actionloop-starter-kit/python3.7/Makefile b/actionloop-starter-kit/python3.7/Makefile
index fe9ee2c..900f2d2 100644
--- a/actionloop-starter-kit/python3.7/Makefile
+++ b/actionloop-starter-kit/python3.7/Makefile
@@ -1,6 +1,6 @@
 IMG=actionloop-demo-python-v3.7:latest
 INVOKE=python ../tools/invoke.py
-PREFIX=docker.io/actionloop
+PREFIX=docker.io/openwhisk
 
 build:
 	docker build -t $(IMG) .
@@ -14,10 +14,10 @@ clean:
 	docker rmi -f $(IMG)
 
 start: build
-	docker run -p 8080:8080 -ti -v $(PWD):/proxy $(IMG) 
+	docker run -p 8080:8080 -ti -v $(PWD):/proxy $(IMG)
 
 debug: build
-	docker run -p 8080:8080 -ti --entrypoint=/bin/sh -v $(PWD):/proxy $(IMG) 
+	docker run -p 8080:8080 -ti --entrypoint=/bin/sh -v $(PWD):/proxy $(IMG)
 
 .PHONY: build push clean start debug
 
@@ -33,7 +33,7 @@ test-src-zip:
 	$(INVOKE) run '{}'
 	$(INVOKE) run '{"name":"Mike"}'
 
-test-bin-dir:
+test-bin-zip:
 	$(MAKE) -C ../example bin.zip
 	$(INVOKE) init ../example/bin.zip
 	$(INVOKE) run '{}'
diff --git a/actionloop-starter-kit/python3.7/lib/launcher.py b/actionloop-starter-kit/python3.7/lib/launcher.py
index 7d277b5..95c21c9 100644
--- a/actionloop-starter-kit/python3.7/lib/launcher.py
+++ b/actionloop-starter-kit/python3.7/lib/launcher.py
@@ -24,7 +24,6 @@ import sys, os, json, traceback
 # now import the action as process input/output
 from main__ import main as main
 
-env = os.environ
 out = fdopen(3, "wb")
 while True:
   line = stdin.readline()
@@ -35,7 +34,7 @@ while True:
     if key == "value":
       payload = args["value"]
     else:
-      env["__OW_%s" % key.upper()]= args[key]
+      os.environ["__OW_%s" % key.upper()]= args[key]
   res = {}
   try:
     res = main(payload)
diff --git a/actionloop-starter-kit/tests/src/test/scala/runtime/actionContainers/ActionLoopPythonBasicTests.scala b/actionloop-starter-kit/tests/src/test/scala/runtime/actionContainers/ActionLoopPythonBasicTests.scala
index 784dd15..2fe1098 100644
--- a/actionloop-starter-kit/tests/src/test/scala/runtime/actionContainers/ActionLoopPythonBasicTests.scala
+++ b/actionloop-starter-kit/tests/src/test/scala/runtime/actionContainers/ActionLoopPythonBasicTests.scala
@@ -27,8 +27,7 @@ class ActionLoopPythonBasicTests extends BasicActionRunnerTests with WskActorSys
 
   val image = "actionloop-demo-python-v3.7"
 
-  override def withActionContainer(env: Map[String, String] = Map.empty)(
-    code: ActionContainer => Unit) = {
+  override def withActionContainer(env: Map[String, String] = Map.empty)(code: ActionContainer => Unit) = {
     withContainer(image, env)(code)
   }
 
@@ -39,31 +38,27 @@ class ActionLoopPythonBasicTests extends BasicActionRunnerTests with WskActorSys
 
   override val testNoSourceOrExec = TestConfig("")
 
-
   override val testNotReturningJson =
     TestConfig("""
                  |def main(args):
                  |    return "not a json object"
                """.stripMargin)
 
-  override val testEcho = TestConfig(
-    """|import sys
+  override val testEcho = TestConfig("""|import sys
        |def main(args):
        |   print("hello stdout", file=sys.stdout)
        |   print("hello stderr", file=sys.stderr)
        |   return args
     """.stripMargin)
 
-  override val testUnicode = TestConfig(
-    """|def main(args):
+  override val testUnicode = TestConfig("""|def main(args):
        |  delimiter = args['delimiter']
        |  msg = u"%s ☃ %s" % (delimiter, delimiter)
        |  print(msg)
        |  return { "winter": msg }
     """.stripMargin)
 
-  override val testEnv = TestConfig(
-    """|import os
+  override val testEnv = TestConfig("""|import os
        |def main(args):
        |  env = os.environ
        |  return {
@@ -76,19 +71,17 @@ class ActionLoopPythonBasicTests extends BasicActionRunnerTests with WskActorSys
        |  }
     """.stripMargin)
 
-
-  override val testInitCannotBeCalledMoreThanOnce = TestConfig(
-    s"""|def main(args):
+  override val testInitCannotBeCalledMoreThanOnce = TestConfig(s"""|def main(args):
         |  return args
     """.stripMargin)
 
   override val testEntryPointOtherThanMain = TestConfig(
     s"""|def niam(args):
         |   return args
-    """.stripMargin, main = "niam")
+    """.stripMargin,
+    main = "niam")
 
-  override val testLargeInput = TestConfig(
-    s"""|def main(args):
+  override val testLargeInput = TestConfig(s"""|def main(args):
         |  return args
     """.stripMargin)
 }
diff --git a/actionloop-starter-kit/tests/src/test/scala/runtime/actionContainers/SingleTest.scala b/actionloop-starter-kit/tests/src/test/scala/runtime/actionContainers/SingleTest.scala
new file mode 100644
index 0000000..769a1fc
--- /dev/null
+++ b/actionloop-starter-kit/tests/src/test/scala/runtime/actionContainers/SingleTest.scala
@@ -0,0 +1,54 @@
+/*
+ * 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 actionContainers.ActionContainer.withContainer
+import actionContainers.{ActionContainer, ActionProxyContainerTestUtils}
+import common.WskActorSystem
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+import spray.json.{JsonParser}
+
+@RunWith(classOf[JUnitRunner])
+class SingleTest extends ActionProxyContainerTestUtils with WskActorSystem {
+  lazy val imageName = "actionloop-demo-python-v3.7"
+
+  def withActionContainer(env: Map[String, String] = Map.empty)(code: ActionContainer => Unit) = {
+    withContainer(imageName, env)(code)
+  }
+
+  behavior of imageName
+
+  val code =
+    """|import sys
+       |def main(args):
+       |   print("hello stdout", file=sys.stdout)
+       |   print("hello stderr", file=sys.stderr)
+       |   return args
+       |""".stripMargin
+
+  val data = JsonParser("""{"name":"Mike"}""")
+
+  it should "return an echo of the input" in {
+    val (out, err) = withActionContainer() { c =>
+      val (initCode, _) = c.init(initPayload(code))
+      initCode should be(200)
+      val (runCode, runRes) = c.run(runPayload(data))
+      runCode should be(200)
+    }
+  }
+}