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/14 21:42:35 UTC
[incubator-openwhisk-runtime-ruby] branch master updated:
actionloop ruby (#20)
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-runtime-ruby.git
The following commit(s) were added to refs/heads/master by this push:
new 5d598f9 actionloop ruby (#20)
5d598f9 is described below
commit 5d598f98ac5c77bd3c9b259c7921e9d7f4c60e3a
Author: Michele Sciabarra <30...@users.noreply.github.com>
AuthorDate: Sun Apr 14 23:42:31 2019 +0200
actionloop ruby (#20)
* actionloop ruby
* whitespace :(
* whitespace, again :(((
* update docker
* different way to update docker
* os-release
* installing the right docker for trusty
* missing sudo
* missing bin/compile
* formatting scala...
* tests and licenses
* reformat scala
---
.travis.yml | 8 +-
.../setup.sh => core/ruby2.6ActionLoop/Dockerfile | 28 +++----
core/ruby2.6ActionLoop/bin/compile | 79 +++++++++++++++++++
.../ruby2.6ActionLoop/build.gradle | 21 +----
core/ruby2.6ActionLoop/lib/launcher.rb | 58 ++++++++++++++
settings.gradle | 1 +
.../Ruby26ActionLoopContainerTests.scala | 91 ++++++++++++++++++++++
tools/travis/setup.sh | 9 +++
8 files changed, 257 insertions(+), 38 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index cdc2109..4909a5f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,6 +9,7 @@ scala:
services:
- docker
before_install:
+- "cat /etc/os-release"
- "./tools/travis/setup.sh"
install: true
script:
@@ -21,7 +22,12 @@ deploy:
all_branches: true
repo: apache/incubator-openwhisk-runtime-ruby
- provider: script
- script: "./tools/travis/publish.sh openwhisk ruby2.5Action latest"
+ script: "./tools/travis/publish.sh openwhisk ruby2.5Action latest"
+ on:
+ branch: master
+ repo: apache/incubator-openwhisk-runtime-ruby
+- provider: script
+ script: "./tools/travis/publish.sh openwhisk ruby2.6ActionLoop latest"
on:
branch: master
repo: apache/incubator-openwhisk-runtime-ruby
diff --git a/tools/travis/setup.sh b/core/ruby2.6ActionLoop/Dockerfile
old mode 100755
new mode 100644
similarity index 63%
copy from tools/travis/setup.sh
copy to core/ruby2.6ActionLoop/Dockerfile
index 3424cdb..c1ab75f
--- a/tools/travis/setup.sh
+++ b/core/ruby2.6ActionLoop/Dockerfile
@@ -1,4 +1,3 @@
-#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
@@ -15,20 +14,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-
-set -e
-
-# Build script for Travis-CI.
-
-SCRIPTDIR=$(cd $(dirname "$0") && pwd)
-ROOTDIR="$SCRIPTDIR/../.."
-HOMEDIR="$SCRIPTDIR/../../../"
-
-# clone OpenWhisk utilities repo. in order to run scanCode
-cd $HOMEDIR
-git clone https://github.com/apache/incubator-openwhisk-utilities.git
-
-# clone main openwhisk repo. for testing purposes
-git clone --depth=1 https://github.com/apache/incubator-openwhisk.git openwhisk
-cd openwhisk
-./tools/travis/setup.sh
+FROM openwhisk/actionloop-v2:latest as builder
+FROM ruby:2.6.2-alpine3.9
+RUN mkdir -p /proxy/bin /proxy/lib /proxy/action
+WORKDIR /proxy
+COPY --from=builder bin/proxy /bin/proxy
+ADD lib/launcher.rb /proxy/lib/launcher.rb
+ADD bin/compile /proxy/bin/compile
+RUN apk update && apk add python3
+ENV OW_COMPILER=/proxy/bin/compile
+ENTRYPOINT ["/bin/proxy"]
diff --git a/core/ruby2.6ActionLoop/bin/compile b/core/ruby2.6ActionLoop/bin/compile
new file mode 100755
index 0000000..7ad0bf6
--- /dev/null
+++ b/core/ruby2.6ActionLoop/bin/compile
@@ -0,0 +1,79 @@
+#!/usr/bin/env python3
+"""Python Action Builder
+#
+# 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, sys, codecs, shutil
+from os.path import abspath, exists, dirname
+
+# write a file creating intermediate directories
+def write_file(file, body, executable=False):
+ os.makedirs(dirname(file), mode=0o755, exist_ok=True)
+ with open(file, mode="w", encoding="utf-8") as f:
+ f.write(body)
+ if executable:
+ os.chmod(file, 0o755)
+
+# copy a file eventually replacing a substring
+def copy_replace(src, dst, match=None, replacement=""):
+ with codecs.open(src, 'r', 'utf-8') as s:
+ body = s.read()
+ if match:
+ body = body.replace(match, replacement)
+ write_file(dst, body)
+
+# assemble sources
+def sources(launcher, main, src_dir):
+ # move exec in the right place if exists
+ src_file = "%s/exec" % src_dir
+ if exists(src_file):
+ copy_replace(src_file, "%s/main__.rb" % src_dir)
+
+ # move main.rb in the right place if it exists
+ src_file = "%s/main.rb" % src_dir
+ if exists(src_file):
+ copy_replace(src_file, "%s/main__.rb" % src_dir)
+
+ # write the boilerplate in a temp dir
+ copy_replace(launcher, "%s/exec__.rb" % src_dir,
+ "res = main(payload)",
+ "res = %s(payload)" % main )
+
+# compile sources
+def build(src_dir, tgt_dir):
+ # in general, compile your program into an executable format
+ # for scripting languages, move sources and create a launcher
+ # move away the action dir and replace with the new
+ shutil.rmtree(tgt_dir)
+ shutil.move(src_dir, tgt_dir)
+ write_file("%s/exec" % tgt_dir, """#!/bin/sh
+cd "$(dirname $0)"
+exec /usr/local/bin/ruby exec__.rb
+""")
+
+if __name__ == '__main__':
+ if len(sys.argv) < 4:
+ sys.stdout.write("usage: <main-function> <source-dir> <target-dir>\n")
+ sys.stdout.flush()
+ sys.exit(1)
+ launcher = "%s/lib/launcher.rb" % dirname(dirname(sys.argv[0]))
+ sources(launcher, sys.argv[1], abspath(sys.argv[2]))
+ build(abspath(sys.argv[2]), abspath(sys.argv[3]))
+ sys.stdout.flush()
+ sys.stderr.flush()
diff --git a/settings.gradle b/core/ruby2.6ActionLoop/build.gradle
similarity index 66%
copy from settings.gradle
copy to core/ruby2.6ActionLoop/build.gradle
index bc382b2..594ae1a 100644
--- a/settings.gradle
+++ b/core/ruby2.6ActionLoop/build.gradle
@@ -15,22 +15,5 @@
* limitations under the License.
*/
-include 'tests'
-
-include 'core:ruby2.5Action'
-
-rootProject.name = 'runtime-ruby'
-
-gradle.ext.openwhisk = [
- version: '1.0.0-SNAPSHOT'
-]
-
-gradle.ext.scala = [
- version: '2.12.7',
- compileFlags: ['-feature', '-unchecked', '-deprecation', '-Xfatal-warnings', '-Ywarn-unused-import']
-]
-
-gradle.ext.scalafmt = [
- version: '1.5.0',
- config: new File(rootProject.projectDir, '.scalafmt.conf')
-]
+ext.dockerImageName = 'actionloop-ruby-v2.6'
+apply from: '../../gradle/docker.gradle'
diff --git a/core/ruby2.6ActionLoop/lib/launcher.rb b/core/ruby2.6ActionLoop/lib/launcher.rb
new file mode 100644
index 0000000..91664f9
--- /dev/null
+++ b/core/ruby2.6ActionLoop/lib/launcher.rb
@@ -0,0 +1,58 @@
+#
+# 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.
+#
+require "logger"
+require "json"
+
+# requiring user's action code
+require "./main__"
+
+# open our file descriptor, this allows us to talk to the go-proxy parent process
+# code gets executed via file descriptor #3
+#out = File.for_fd(3)
+out = IO.new(3)
+
+# run this until process gets killed
+while true
+ # JSON arguments get passed via STDIN
+ line = STDIN.gets()
+ break unless line
+
+ # parse JSON arguments that come in via the value parameter
+ args = JSON.parse(line)
+ payload = {}
+ args.each do |key, value|
+ if key == "value"
+ payload = value
+ else
+ # set environment variables for other keys
+ ENV["__OW_#{key.upcase}"] = value
+ end
+ end
+ # execute the user's action code
+ res = {}
+ begin
+ res = main(payload)
+ rescue Exception => e
+ puts "exception: #{e}"
+ res ["error"] = "#{e}"
+ end
+
+ STDOUT.flush()
+ STDERR.flush()
+ out.puts(res.to_json)
+ out.flush()
+end
diff --git a/settings.gradle b/settings.gradle
index bc382b2..94c85fd 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -18,6 +18,7 @@
include 'tests'
include 'core:ruby2.5Action'
+include 'core:ruby2.6ActionLoop'
rootProject.name = 'runtime-ruby'
diff --git a/tests/src/test/scala/actionContainers/Ruby26ActionLoopContainerTests.scala b/tests/src/test/scala/actionContainers/Ruby26ActionLoopContainerTests.scala
new file mode 100644
index 0000000..de8caec
--- /dev/null
+++ b/tests/src/test/scala/actionContainers/Ruby26ActionLoopContainerTests.scala
@@ -0,0 +1,91 @@
+/*
+ * 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, BasicActionRunnerTests}
+import common.WskActorSystem
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+
+@RunWith(classOf[JUnitRunner])
+class Ruby26ActionLoopContainerTests extends BasicActionRunnerTests with WskActorSystem {
+
+ val image = "actionloop-ruby-v2.6"
+
+ override def withActionContainer(env: Map[String, String] = Map.empty)(code: ActionContainer => Unit) = {
+ withContainer(image, env)(code)
+ }
+
+ def withActionLoopContainer(code: ActionContainer => Unit) =
+ withContainer(image)(code)
+
+ behavior of image
+
+ override val testNoSourceOrExec = TestConfig("")
+
+ override val testNotReturningJson =
+ TestConfig("""|def main(args)
+ | "not a json object"
+ |end
+ |""".stripMargin)
+
+ override val testEcho = TestConfig("""|def main(args)
+ | puts 'hello stdout'
+ | warn 'hello stderr'
+ | args
+ |end
+ |""".stripMargin)
+
+ override val testUnicode = TestConfig("""|def main(args)
+ | str = args['delimiter'] + " ☃ " + args['delimiter']
+ | print str + "\n"
+ | {"winter" => str}
+ |end
+ |""".stripMargin)
+
+ override val testEnv = TestConfig(
+ """|def main(args)
+ | {
+ | "api_host" => ENV['__OW_API_HOST'],
+ | "api_key" => ENV['__OW_API_KEY'],
+ | "namespace" => ENV['__OW_NAMESPACE'],
+ | "action_name" => ENV['__OW_ACTION_NAME'],
+ | "activation_id" => ENV['__OW_ACTIVATION_ID'],
+ | "deadline" => ENV['__OW_DEADLINE']
+ | }
+ |end
+ |""".stripMargin,
+ enforceEmptyOutputStream = false)
+
+ override val testInitCannotBeCalledMoreThanOnce = TestConfig(s"""|def main(args)
+ | args
+ |end
+ |""".stripMargin)
+
+ override val testEntryPointOtherThanMain = TestConfig(
+ s"""|def niam(args)
+ | args
+ |end
+ |""".stripMargin,
+ main = "niam")
+
+ override val testLargeInput = TestConfig(s"""|def main(args)
+ | args
+ |end
+ |""".stripMargin)
+}
diff --git a/tools/travis/setup.sh b/tools/travis/setup.sh
index 3424cdb..a4e2031 100755
--- a/tools/travis/setup.sh
+++ b/tools/travis/setup.sh
@@ -18,6 +18,15 @@
set -e
+# upgrade docker
+sudo apt-get -y update
+sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
+curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
+sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
+sudo apt-get update -y
+sudo apt-get remove docker docker-engine
+sudo apt-get -y install docker-ce=17.06.2~ce-0~ubuntu
+
# Build script for Travis-CI.
SCRIPTDIR=$(cd $(dirname "$0") && pwd)