Skip to content
Snippets Groups Projects
Commit 1b58ebe7 authored by Rodric Rabbah's avatar Rodric Rabbah Committed by Carlos Santana
Browse files

Remove swift 2 action proxy.

Remove rotted script.
parent ce31fda1
No related branches found
No related tags found
No related merge requests found
......@@ -48,10 +48,6 @@ ansible/tmp/*
ansible/roles/nginx/files/*.csr
ansible/roles/nginx/files/*cert.pem
# Action proxies copied during build
core/swiftAction/actionproxy.py
core/swift3Action/actionproxy.py
# .zip files must be explicited whitelisted
*.zip
!tests/dat/actions/blackbox.zip
......
# Dockerfile for swift3 actions, overrides and extends ActionRunner from actionProxy
# This Dockerfile is partially based on: https://github.com/swiftdocker/docker-swift/
FROM buildpack-deps:trusty
ENV DEBIAN_FRONTEND noninteractive
# Upgrade and install basic Python dependencies
RUN apt-get -y purge \
&& apt-get -y update \
&& apt-get -y install --fix-missing python2.7 python-gevent python-flask \
\
# Upgrade and install Swift dependencies
&& apt-get -y install --fix-missing build-essential wget clang libedit-dev libicu52 libxml2-dev \
\
# Clean up
&& apt-get clean
# Install Swift keys
RUN wget --no-verbose -O - https://swift.org/keys/all-keys.asc | gpg --import - && \
gpg --keyserver hkp://pool.sks-keyservers.net --refresh-keys Swift
# Install Swift Ubuntu 14.04 Snapshot
ENV SWIFT_VERSION 2.2-SNAPSHOT-2016-01-11-a
ENV SWIFT_PLATFORM ubuntu14.04
RUN SWIFT_ARCHIVE_NAME=swift-$SWIFT_VERSION-$SWIFT_PLATFORM && \
SWIFT_URL=https://swift.org/builds/$(echo "$SWIFT_PLATFORM" | tr -d .)/swift-$SWIFT_VERSION/$SWIFT_ARCHIVE_NAME.tar.gz && \
wget --no-verbose $SWIFT_URL && \
wget --no-verbose $SWIFT_URL.sig && \
gpg --verify $SWIFT_ARCHIVE_NAME.tar.gz.sig && \
tar -xzf $SWIFT_ARCHIVE_NAME.tar.gz --directory / --strip-components=1 && \
rm -rf $SWIFT_ARCHIVE_NAME* /tmp/* /var/tmp/*
# Add the action proxy
RUN mkdir -p /actionProxy
ADD actionproxy.py /actionProxy
# Add swift action runner
RUN mkdir -p /swiftAction
RUN touch /swiftAction/action.swift
ADD epilogue.swift /swiftAction
ADD swiftrunner.py /swiftAction
ENV FLASK_PROXY_PORT 8080
CMD ["/bin/bash", "-c", "cd swiftAction && python -u swiftrunner.py"]
ext.dockerImageName = 'swiftaction'
apply from: '../../gradle/docker.gradle'
distDocker.dependsOn 'copyProxy'
distDocker.finalizedBy('rmProxy')
task copyProxy(type: Copy) {
from '../actionProxy/actionproxy.py'
into './actionproxy.py'
}
task rmProxy(type: Delete) {
delete 'actionproxy.py'
}
/*
* 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.
*/
// Deliberate whitespaces above.
/* This code is appended to user-supplied action code.
It reads from the standard input, deserializes into JSON and invokes the
main function. Currently, actions print strings to stdout. This can evolve once
JSON serialization is available in Foundation. */
import Foundation
func _whisk_json2dict(txt: String) -> [String:Any]? {
if let data = txt.dataUsingEncoding(NSUTF8StringEncoding) {
do {
return try NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments) as? [String:Any]
} catch {
return nil
}
}
return nil
}
class _Whisk_JSONSerialization {
enum JSONSerializationError: ErrorType {
case UnsupportedValue(value: Any)
}
private class func escStr(str: String) -> String {
return (str
.bridge()
.stringByReplacingOccurrencesOfString("\\", withString: "\\\\")
.bridge()
.stringByReplacingOccurrencesOfString("\"", withString: "\\\""))
}
class func serialize(value: Any) throws -> String {
if let _ = value as? NSNull {
return "null"
}
if let str = value as? String {
return "\"\(escStr(str))\""
}
if let num = value as? Double {
return "\(num)"
}
if let num = value as? Int {
return "\(num)"
}
if let b = value as? Bool {
return b ? "true" : "false"
}
// More numeric types should go above.
let mirror = Mirror(reflecting: value)
if mirror.displayStyle == .Collection {
return try serializeArray(mirror.children.map({ return $0.value }))
}
if mirror.displayStyle == .Dictionary {
return try serializeObject(mirror.children.map({ return $0.value }))
}
print("Couldn't handle \(value) of type \(value.dynamicType)")
throw JSONSerializationError.UnsupportedValue(value: value)
}
private class func serializeArray(array: [Any]) throws -> String {
if array.count == 0 {
return "[]"
}
var out = "["
var sep = " "
for e in array {
let es = try serialize(e)
out = out + sep + es
sep = ", "
}
out = out + " ]"
return out
}
private class func serializeObject(pairs: [Any]) throws -> String {
if pairs.count == 0 {
return "{}"
}
var out = "{"
var sep = " "
for pair in pairs {
let pairMirror = Mirror(reflecting: pair)
if pairMirror.displayStyle == .Tuple && pairMirror.children.count == 2 {
let g = pairMirror.children.generate()
let k = g.next()!.value
let v = g.next()!.value
let ks = escStr(k as! String)
let vs = try serialize(v)
out = out + sep + "\"\(ks)\": " + vs
sep = ", "
} else {
throw JSONSerializationError.UnsupportedValue(value: pairs)
}
}
out = out + " }"
return out
}
}
func _run_main(mainFunction: [String: Any] -> [String: Any]) -> Void {
let env = NSProcessInfo.processInfo().environment
let inputStr: String = env["WHISK_INPUT"] ?? "{}"
if let parsed = _whisk_json2dict(inputStr) {
let result = mainFunction(parsed)
do {
try print(_Whisk_JSONSerialization.serialize(result))
} catch {
print("Serialization failed (\(result)).")
}
} else {
print("Error: couldn't parse JSON input.")
}
}
#
# 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 sys
import subprocess
import codecs
import json
sys.path.append('../actionProxy')
from actionproxy import ActionRunner, main, setRunner
SRC_EPILOGUE_FILE = "./epilogue.swift"
DEST_SCRIPT_FILE = "/swiftAction/action.swift"
DEST_BIN_FILE = "/swiftAction/action"
BUILD_PROCESS = [ "swiftc", "-O", DEST_SCRIPT_FILE, "-o", DEST_BIN_FILE ]
class SwiftRunner(ActionRunner):
def __init__(self):
ActionRunner.__init__(self, DEST_SCRIPT_FILE, DEST_BIN_FILE)
def epilogue(self, fp, init_message):
if "main" in init_message:
main_function = init_message["main"]
else:
main_function = "main"
with codecs.open(SRC_EPILOGUE_FILE, "r", "utf-8") as ep:
fp.write(ep.read())
fp.write("_run_main(%s)\n" % main_function)
def build(self):
p = subprocess.Popen(BUILD_PROCESS)
(o, e) = p.communicate()
if o is not None:
sys.stdout.write(o)
if e is not None:
sys.stderr.write(e)
def env(self, message):
env = ActionRunner.env(self, message)
args = message.get('value', {}) if message else {}
env['WHISK_INPUT'] = json.dumps(args)
return env
if __name__ == "__main__":
setRunner(SwiftRunner())
main()
......@@ -7,7 +7,6 @@ include 'core:nodejsAction'
include 'core:nodejs6Action'
include 'core:actionProxy'
include 'core:pythonAction'
include 'core:swiftAction'
include 'core:swift3Action'
include 'core:javaAction'
......
......@@ -41,7 +41,6 @@ test.dependsOn([
':core:actionProxy:distDocker',
':core:pythonAction:distDocker',
':core:javaAction:distDocker',
':core:swiftAction:distDocker',
':core:swift3Action:distDocker',
':sdk:docker:distDocker',
':tests:dat:blackbox:badaction:distDocker',
......
......@@ -76,7 +76,7 @@ class SwiftActionContainerTests extends BasicActionRunnerTests with WskActorSyst
| }
""".stripMargin
// Helpers specific to swiftaction
// Helpers specific to swift actions
override def withActionContainer(env: Map[String, String] = Map.empty)(code: ActionContainer => Unit) = {
withContainer(swiftContainerImageName, env)(code)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment