From 5b4bf5964e86c4ba4fb15175de450a8ced0b9103 Mon Sep 17 00:00:00 2001 From: Vishal Date: Sat, 1 May 2021 15:42:35 +0530 Subject: [PATCH] Moving out Environments to own repo (#1810) Moved out environments and examples out of main Fission repo to their own repo. This is to allow changes to environment releases to be independent of main Fission releases. --- .github/workflows/push_pr.yaml | 14 +- .travis.yml | 61 -- environments/binary/Dockerfile | 18 - environments/binary/README.md | 59 -- environments/binary/builder/Dockerfile | 4 - environments/binary/builder/build.sh | 13 - environments/binary/env.go | 45 - environments/binary/server.go | 178 ---- environments/dotnet/.gitignore | 6 - environments/dotnet/Dockerfile | 15 - environments/dotnet/ExecutorModule.cs | 82 -- environments/dotnet/FissionCompiler.cs | 75 -- environments/dotnet/FissionContext.cs | 114 --- environments/dotnet/Function.cs | 28 - environments/dotnet/Program.cs | 21 - environments/dotnet/README.md | 270 ------ environments/dotnet/fission-dotnet.csproj | 21 - environments/dotnet/project-build.sh | 3 - environments/dotnet20/.dockerignore | 1 - environments/dotnet20/Dockerfile | 15 - environments/dotnet20/ExecutorModule.cs | 179 ---- environments/dotnet20/FissionCompiler.cs | 224 ----- environments/dotnet20/FissionContext.cs | 130 --- environments/dotnet20/Function.cs | 28 - environments/dotnet20/Model/BuilderRequest.cs | 27 - environments/dotnet20/Model/DllInfo.cs | 16 - .../dotnet20/Model/EnvironmentSettings.cs | 16 - .../dotnet20/Model/FunctionSpecification.cs | 37 - environments/dotnet20/Program.cs | 21 - environments/dotnet20/README.md | 365 --------- .../dotnet20/Utility/EnvironmentExtension.cs | 33 - .../dotnet20/Utility/EnvironmentHelper.cs | 117 --- .../dotnet20/Utility/ObjectConverter.cs | 28 - environments/dotnet20/builder/Builder.cs | 55 -- environments/dotnet20/builder/Builder.csproj | 40 - environments/dotnet20/builder/Builder.sln | 25 - .../builder/BuilderEngine/BuilderEngine.cs | 306 ------- environments/dotnet20/builder/Dockerfile | 37 - .../dotnet20/builder/Model/BuilderSettings.cs | 19 - .../dotnet20/builder/Model/ExcludeDll.cs | 12 - .../dotnet20/builder/Model/FissionContext.cs | 137 ---- .../builder/Model/FunctionSpecification.cs | 40 - .../dotnet20/builder/Model/IncludeNuget.cs | 12 - environments/dotnet20/builder/README.md | 175 ---- .../builder/Utility/BuilderExtensions.cs | 21 - .../dotnet20/builder/Utility/BuilderHelper.cs | 180 ---- .../dotnet20/builder/Utility/Logger.cs | 111 --- .../builder/Utility/ObjectConverter.cs | 31 - environments/dotnet20/builder/build.sh | 17 - .../dotnet20/builder/builderSettings.json | 11 - environments/dotnet20/builder/log4net.config | 28 - .../dotnet20/builder/nugetSettings.json | 37 - environments/dotnet20/dotnet20.sln | 25 - environments/dotnet20/envsettings.json | 7 - environments/dotnet20/fission-dotnet20.csproj | 34 - environments/dotnet20/project-build.sh | 3 - environments/go/Dockerfile | 24 - environments/go/Dockerfile-1.11.4 | 24 - environments/go/Dockerfile-1.12 | 24 - environments/go/Dockerfile-1.13 | 24 - environments/go/Dockerfile-1.14 | 24 - environments/go/README.md | 38 - environments/go/builder/Dockerfile | 13 - environments/go/builder/Dockerfile-1.11.4 | 13 - environments/go/builder/Dockerfile-1.12 | 14 - environments/go/builder/Dockerfile-1.13 | 14 - environments/go/builder/Dockerfile-1.14 | 14 - environments/go/builder/build.sh | 45 - environments/go/context/context.go | 10 - environments/go/server.go | 203 ----- environments/jvm-jersey/.gitignore | 2 - environments/jvm-jersey/Dockerfile | 15 - environments/jvm-jersey/Dockerfile-11 | 15 - environments/jvm-jersey/README.md | 68 -- environments/jvm-jersey/builder/Dockerfile | 48 -- environments/jvm-jersey/builder/Dockerfile-11 | 43 - environments/jvm-jersey/builder/build.sh | 4 - environments/jvm-jersey/pom.xml | 86 -- .../java/io/fission/FunctionLoadRequest.java | 35 - .../main/java/io/fission/JerseyServer.java | 146 ---- .../src/main/java/io/fission/Main.java | 50 -- environments/jvm/.gitignore | 7 - environments/jvm/Dockerfile | 16 - environments/jvm/README.md | 70 -- environments/jvm/builder/Dockerfile | 48 -- environments/jvm/builder/build.sh | 4 - environments/jvm/pom.xml | 50 -- .../java/io/fission/FunctionLoadRequest.java | 32 - .../jvm/src/main/java/io/fission/Server.java | 122 --- environments/nodejs/.gitignore | 1 - environments/nodejs/Dockerfile | 18 - environments/nodejs/Dockerfile-12.16 | 15 - environments/nodejs/Dockerfile-debian | 18 - environments/nodejs/README.md | 47 -- environments/nodejs/builder/Dockerfile | 11 - environments/nodejs/builder/Dockerfile-12.16 | 11 - environments/nodejs/builder/build.sh | 3 - environments/nodejs/package.json | 30 - environments/nodejs/server.js | 168 ---- environments/nodejs/test/test.js | 9 - environments/nodejs/test/test.sh | 31 - environments/perl/Dockerfile | 9 - environments/perl/README.md | 38 - environments/perl/server.pl | 46 -- environments/php7/Dockerfile | 75 -- environments/php7/README.md | 58 -- environments/php7/builder/Dockerfile | 71 -- environments/php7/builder/defaultBuildCmd | 9 - environments/php7/composer.json | 12 - environments/php7/composer.lock | 769 ------------------ environments/php7/server.php | 91 --- environments/python/Dockerfile | 17 - environments/python/Dockerfile-2.7 | 15 - environments/python/README.md | 67 -- environments/python/builder/Dockerfile | 11 - environments/python/builder/defaultBuildCmd | 8 - environments/python/requirements.txt | 9 - environments/python/server.py | 143 ---- environments/ruby/Dockerfile | 11 - environments/ruby/Gemfile | 5 - environments/ruby/Gemfile.lock | 20 - environments/ruby/README.md | 54 -- environments/ruby/builder/Dockerfile | 12 - environments/ruby/builder/defaultBuildCmd | 9 - environments/ruby/fission/context.rb | 22 - environments/ruby/fission/handler.rb | 23 - environments/ruby/fission/request.rb | 31 - environments/ruby/fission/specializer.rb | 84 -- environments/ruby/server.rb | 33 - environments/tensorflow-serving/Dockerfile | 23 - environments/tensorflow-serving/README.md | 29 - environments/tensorflow-serving/server.go | 231 ------ examples/binary/README.md | 80 -- examples/binary/echo.sh | 4 - examples/binary/headers.sh | 3 - examples/binary/hello.go | 12 - examples/binary/hello.sh | 3 - examples/dotnet/arguments.cs | 11 - examples/dotnet/helloworld.cs | 9 - examples/dotnet/requestbody.cs | 24 - examples/dotnet/requestheaders.cs | 17 - examples/dotnet20/arguments.cs | 11 - examples/dotnet20/echo.cs | 10 - examples/dotnet20/helloworld.cs | 9 - examples/dotnet20/requestbody.cs | 24 - examples/dotnet20/requestheaders.cs | 17 - examples/go/README.md | 23 - examples/go/hello.go | 11 - examples/go/module-example/README.md | 35 - examples/go/module-example/go.mod | 3 - examples/go/module-example/go.sum | 1 - examples/go/module-example/main.go | 13 - examples/go/specs/env.yaml | 12 - .../go/specs/fission-deployment-config.yaml | 6 - examples/go/specs/function-hello.yaml | 39 - examples/jvm-jersey/java/.gitignore | 4 - examples/jvm-jersey/java/README.md | 60 -- examples/jvm-jersey/java/build.sh | 5 - examples/jvm-jersey/java/pom.xml | 76 -- examples/jvm-jersey/java/specs/README | 42 - examples/jvm-jersey/java/specs/env-java.yaml | 17 - .../java/specs/fission-deployment-config.yaml | 7 - .../jvm-jersey/java/specs/function-hello.yaml | 27 - .../java/specs/package-hellojava.yaml | 26 - .../src/main/java/io/fission/HelloWorld.java | 25 - .../test/java/io/fission/HelloWorldTest.java | 25 - examples/jvm/java/.gitignore | 4 - examples/jvm/java/README.md | 60 -- examples/jvm/java/build.sh | 5 - examples/jvm/java/pom.xml | 72 -- examples/jvm/java/specs/README | 42 - examples/jvm/java/specs/env-java.yaml | 17 - .../java/specs/fission-deployment-config.yaml | 7 - examples/jvm/java/specs/function-hello.yaml | 27 - .../jvm/java/specs/package-hellojava.yaml | 26 - .../src/main/java/io/fission/HelloWorld.java | 16 - .../test/java/io/fission/HelloWorldTest.java | 24 - .../message-queue/nats-streaming/README.md | 42 - .../message-queue/nats-streaming/hello.go | 13 - .../nats-streaming/mqtrigger/go.mod | 12 - .../nats-streaming/mqtrigger/go.sum | 104 --- .../nats-streaming/mqtrigger/main.go | 39 - .../message-queue/nats-streaming/specs/README | 42 - .../nats-streaming/specs/env-go.yaml | 17 - .../specs/fission-deployment-config.yaml | 7 - .../nats-streaming/specs/function-hello.yaml | 54 -- .../specs/function-publisher.yaml | 27 - .../specs/package-publisher.yaml | 25 - examples/nodejs/README.md | 131 --- examples/nodejs/README_V1.md | 105 --- examples/nodejs/hello-callback.js | 4 - examples/nodejs/hello.js | 7 - examples/nodejs/index.js | 1 - examples/nodejs/kubeEventsSlack.js | 67 -- examples/nodejs/multi-entry.js | 13 - examples/nodejs/package.json | 30 - examples/nodejs/weather.js | 40 - examples/perl/hello.pm | 36 - examples/php7/hello.php | 3 - examples/php7/hellopsr.php | 12 - examples/php7/multifile/README.md | 69 -- examples/php7/multifile/composer.json | 14 - .../php7/multifile/handlers/FileReader.php | 16 - examples/php7/multifile/handlers/message.txt | 1 - examples/php7/stock.php | 47 -- examples/python/README.md | 29 - examples/python/guestbook/add.py | 18 - examples/python/guestbook/deploy.sh | 18 - examples/python/guestbook/get.py | 28 - examples/python/guestbook/redis.yaml | 45 - examples/python/hello.py | 2 - examples/python/multifile/README.md | 62 -- examples/python/multifile/__init__.py | 0 examples/python/multifile/main.py | 11 - examples/python/multifile/message.txt | 1 - examples/python/multifile/readfile.py | 3 - examples/python/requestdata.py | 7 - examples/python/sourcepkg/__init__.py | 0 examples/python/sourcepkg/build.sh | 2 - examples/python/sourcepkg/requirements.txt | 1 - examples/python/sourcepkg/user.py | 11 - examples/python/statuscode.py | 4 - examples/ruby/README.md | 115 --- examples/ruby/events_to_slack.rb | 33 - examples/ruby/hello.rb | 4 - examples/ruby/parse/Gemfile | 7 - examples/ruby/parse/Gemfile.lock | 15 - examples/ruby/parse/parse.rb | 13 - examples/ruby/request_data.rb | 20 - .../spec-example/hello-spec-exmaple/README.md | 11 - .../hello-spec-exmaple/hello/__init__.py | 0 .../hello-spec-exmaple/hello/build.sh | 9 - .../hello-spec-exmaple/hello/hello.py | 4 - .../hello-spec-exmaple/hello/requirements.txt | 1 - .../hello-spec-exmaple/specs/env.yaml | 12 - .../specs/fission-deployment-config.yaml | 3 - .../hello-spec-exmaple/specs/hello.yaml | 46 -- .../hello/hello.js | 11 - .../hello/package.json | 16 - .../specs/README | 42 - .../specs/env-node.yaml | 21 - .../specs/fission-deployment-config.yaml | 7 - .../specs/function-hello.yaml | 54 -- .../spec-example/podspec-example/README.md | 24 - .../spec-example/podspec-example/specs/README | 42 - .../podspec-example/specs/env-python.yaml | 25 - .../specs/fission-deployment-config.yaml | 7 - examples/tensorflow-serving/README.md | 24 - .../half_plus_two/00000123/saved_model.pb | Bin 9337 -> 0 bytes .../variables/variables.data-00000-of-00001 | Bin 12 -> 0 bytes .../00000123/variables/variables.index | Bin 151 -> 0 bytes go.mod | 1 + 252 files changed, 8 insertions(+), 10139 deletions(-) delete mode 100644 .travis.yml delete mode 100644 environments/binary/Dockerfile delete mode 100644 environments/binary/README.md delete mode 100644 environments/binary/builder/Dockerfile delete mode 100755 environments/binary/builder/build.sh delete mode 100644 environments/binary/env.go delete mode 100644 environments/binary/server.go delete mode 100644 environments/dotnet/.gitignore delete mode 100644 environments/dotnet/Dockerfile delete mode 100644 environments/dotnet/ExecutorModule.cs delete mode 100644 environments/dotnet/FissionCompiler.cs delete mode 100644 environments/dotnet/FissionContext.cs delete mode 100644 environments/dotnet/Function.cs delete mode 100755 environments/dotnet/Program.cs delete mode 100644 environments/dotnet/README.md delete mode 100755 environments/dotnet/fission-dotnet.csproj delete mode 100755 environments/dotnet/project-build.sh delete mode 100644 environments/dotnet20/.dockerignore delete mode 100644 environments/dotnet20/Dockerfile delete mode 100644 environments/dotnet20/ExecutorModule.cs delete mode 100644 environments/dotnet20/FissionCompiler.cs delete mode 100644 environments/dotnet20/FissionContext.cs delete mode 100644 environments/dotnet20/Function.cs delete mode 100644 environments/dotnet20/Model/BuilderRequest.cs delete mode 100644 environments/dotnet20/Model/DllInfo.cs delete mode 100644 environments/dotnet20/Model/EnvironmentSettings.cs delete mode 100644 environments/dotnet20/Model/FunctionSpecification.cs delete mode 100644 environments/dotnet20/Program.cs delete mode 100644 environments/dotnet20/README.md delete mode 100644 environments/dotnet20/Utility/EnvironmentExtension.cs delete mode 100644 environments/dotnet20/Utility/EnvironmentHelper.cs delete mode 100644 environments/dotnet20/Utility/ObjectConverter.cs delete mode 100644 environments/dotnet20/builder/Builder.cs delete mode 100644 environments/dotnet20/builder/Builder.csproj delete mode 100644 environments/dotnet20/builder/Builder.sln delete mode 100644 environments/dotnet20/builder/BuilderEngine/BuilderEngine.cs delete mode 100644 environments/dotnet20/builder/Dockerfile delete mode 100644 environments/dotnet20/builder/Model/BuilderSettings.cs delete mode 100644 environments/dotnet20/builder/Model/ExcludeDll.cs delete mode 100644 environments/dotnet20/builder/Model/FissionContext.cs delete mode 100644 environments/dotnet20/builder/Model/FunctionSpecification.cs delete mode 100644 environments/dotnet20/builder/Model/IncludeNuget.cs delete mode 100644 environments/dotnet20/builder/README.md delete mode 100644 environments/dotnet20/builder/Utility/BuilderExtensions.cs delete mode 100644 environments/dotnet20/builder/Utility/BuilderHelper.cs delete mode 100644 environments/dotnet20/builder/Utility/Logger.cs delete mode 100644 environments/dotnet20/builder/Utility/ObjectConverter.cs delete mode 100644 environments/dotnet20/builder/build.sh delete mode 100644 environments/dotnet20/builder/builderSettings.json delete mode 100644 environments/dotnet20/builder/log4net.config delete mode 100644 environments/dotnet20/builder/nugetSettings.json delete mode 100644 environments/dotnet20/dotnet20.sln delete mode 100644 environments/dotnet20/envsettings.json delete mode 100644 environments/dotnet20/fission-dotnet20.csproj delete mode 100755 environments/dotnet20/project-build.sh delete mode 100644 environments/go/Dockerfile delete mode 100644 environments/go/Dockerfile-1.11.4 delete mode 100644 environments/go/Dockerfile-1.12 delete mode 100644 environments/go/Dockerfile-1.13 delete mode 100644 environments/go/Dockerfile-1.14 delete mode 100644 environments/go/README.md delete mode 100644 environments/go/builder/Dockerfile delete mode 100644 environments/go/builder/Dockerfile-1.11.4 delete mode 100644 environments/go/builder/Dockerfile-1.12 delete mode 100644 environments/go/builder/Dockerfile-1.13 delete mode 100644 environments/go/builder/Dockerfile-1.14 delete mode 100755 environments/go/builder/build.sh delete mode 100644 environments/go/context/context.go delete mode 100644 environments/go/server.go delete mode 100644 environments/jvm-jersey/.gitignore delete mode 100644 environments/jvm-jersey/Dockerfile delete mode 100644 environments/jvm-jersey/Dockerfile-11 delete mode 100644 environments/jvm-jersey/README.md delete mode 100644 environments/jvm-jersey/builder/Dockerfile delete mode 100644 environments/jvm-jersey/builder/Dockerfile-11 delete mode 100755 environments/jvm-jersey/builder/build.sh delete mode 100644 environments/jvm-jersey/pom.xml delete mode 100644 environments/jvm-jersey/src/main/java/io/fission/FunctionLoadRequest.java delete mode 100644 environments/jvm-jersey/src/main/java/io/fission/JerseyServer.java delete mode 100644 environments/jvm-jersey/src/main/java/io/fission/Main.java delete mode 100644 environments/jvm/.gitignore delete mode 100644 environments/jvm/Dockerfile delete mode 100644 environments/jvm/README.md delete mode 100644 environments/jvm/builder/Dockerfile delete mode 100755 environments/jvm/builder/build.sh delete mode 100644 environments/jvm/pom.xml delete mode 100644 environments/jvm/src/main/java/io/fission/FunctionLoadRequest.java delete mode 100644 environments/jvm/src/main/java/io/fission/Server.java delete mode 100644 environments/nodejs/.gitignore delete mode 100644 environments/nodejs/Dockerfile delete mode 100644 environments/nodejs/Dockerfile-12.16 delete mode 100644 environments/nodejs/Dockerfile-debian delete mode 100644 environments/nodejs/README.md delete mode 100644 environments/nodejs/builder/Dockerfile delete mode 100644 environments/nodejs/builder/Dockerfile-12.16 delete mode 100755 environments/nodejs/builder/build.sh delete mode 100644 environments/nodejs/package.json delete mode 100644 environments/nodejs/server.js delete mode 100644 environments/nodejs/test/test.js delete mode 100755 environments/nodejs/test/test.sh delete mode 100644 environments/perl/Dockerfile delete mode 100644 environments/perl/README.md delete mode 100755 environments/perl/server.pl delete mode 100644 environments/php7/Dockerfile delete mode 100644 environments/php7/README.md delete mode 100644 environments/php7/builder/Dockerfile delete mode 100755 environments/php7/builder/defaultBuildCmd delete mode 100644 environments/php7/composer.json delete mode 100644 environments/php7/composer.lock delete mode 100644 environments/php7/server.php delete mode 100644 environments/python/Dockerfile delete mode 100644 environments/python/Dockerfile-2.7 delete mode 100644 environments/python/README.md delete mode 100644 environments/python/builder/Dockerfile delete mode 100755 environments/python/builder/defaultBuildCmd delete mode 100644 environments/python/requirements.txt delete mode 100644 environments/python/server.py delete mode 100644 environments/ruby/Dockerfile delete mode 100644 environments/ruby/Gemfile delete mode 100644 environments/ruby/Gemfile.lock delete mode 100644 environments/ruby/README.md delete mode 100644 environments/ruby/builder/Dockerfile delete mode 100755 environments/ruby/builder/defaultBuildCmd delete mode 100644 environments/ruby/fission/context.rb delete mode 100644 environments/ruby/fission/handler.rb delete mode 100644 environments/ruby/fission/request.rb delete mode 100644 environments/ruby/fission/specializer.rb delete mode 100644 environments/ruby/server.rb delete mode 100644 environments/tensorflow-serving/Dockerfile delete mode 100644 environments/tensorflow-serving/README.md delete mode 100644 environments/tensorflow-serving/server.go delete mode 100644 examples/binary/README.md delete mode 100644 examples/binary/echo.sh delete mode 100644 examples/binary/headers.sh delete mode 100644 examples/binary/hello.go delete mode 100644 examples/binary/hello.sh delete mode 100644 examples/dotnet/arguments.cs delete mode 100644 examples/dotnet/helloworld.cs delete mode 100644 examples/dotnet/requestbody.cs delete mode 100644 examples/dotnet/requestheaders.cs delete mode 100644 examples/dotnet20/arguments.cs delete mode 100644 examples/dotnet20/echo.cs delete mode 100644 examples/dotnet20/helloworld.cs delete mode 100644 examples/dotnet20/requestbody.cs delete mode 100644 examples/dotnet20/requestheaders.cs delete mode 100644 examples/go/README.md delete mode 100644 examples/go/hello.go delete mode 100644 examples/go/module-example/README.md delete mode 100644 examples/go/module-example/go.mod delete mode 100644 examples/go/module-example/go.sum delete mode 100644 examples/go/module-example/main.go delete mode 100644 examples/go/specs/env.yaml delete mode 100644 examples/go/specs/fission-deployment-config.yaml delete mode 100644 examples/go/specs/function-hello.yaml delete mode 100644 examples/jvm-jersey/java/.gitignore delete mode 100644 examples/jvm-jersey/java/README.md delete mode 100755 examples/jvm-jersey/java/build.sh delete mode 100644 examples/jvm-jersey/java/pom.xml delete mode 100644 examples/jvm-jersey/java/specs/README delete mode 100644 examples/jvm-jersey/java/specs/env-java.yaml delete mode 100644 examples/jvm-jersey/java/specs/fission-deployment-config.yaml delete mode 100644 examples/jvm-jersey/java/specs/function-hello.yaml delete mode 100644 examples/jvm-jersey/java/specs/package-hellojava.yaml delete mode 100644 examples/jvm-jersey/java/src/main/java/io/fission/HelloWorld.java delete mode 100644 examples/jvm-jersey/java/src/test/java/io/fission/HelloWorldTest.java delete mode 100644 examples/jvm/java/.gitignore delete mode 100644 examples/jvm/java/README.md delete mode 100755 examples/jvm/java/build.sh delete mode 100644 examples/jvm/java/pom.xml delete mode 100644 examples/jvm/java/specs/README delete mode 100644 examples/jvm/java/specs/env-java.yaml delete mode 100644 examples/jvm/java/specs/fission-deployment-config.yaml delete mode 100644 examples/jvm/java/specs/function-hello.yaml delete mode 100644 examples/jvm/java/specs/package-hellojava.yaml delete mode 100644 examples/jvm/java/src/main/java/io/fission/HelloWorld.java delete mode 100644 examples/jvm/java/src/test/java/io/fission/HelloWorldTest.java delete mode 100644 examples/message-queue/nats-streaming/README.md delete mode 100644 examples/message-queue/nats-streaming/hello.go delete mode 100644 examples/message-queue/nats-streaming/mqtrigger/go.mod delete mode 100644 examples/message-queue/nats-streaming/mqtrigger/go.sum delete mode 100644 examples/message-queue/nats-streaming/mqtrigger/main.go delete mode 100644 examples/message-queue/nats-streaming/specs/README delete mode 100644 examples/message-queue/nats-streaming/specs/env-go.yaml delete mode 100644 examples/message-queue/nats-streaming/specs/fission-deployment-config.yaml delete mode 100644 examples/message-queue/nats-streaming/specs/function-hello.yaml delete mode 100644 examples/message-queue/nats-streaming/specs/function-publisher.yaml delete mode 100644 examples/message-queue/nats-streaming/specs/package-publisher.yaml delete mode 100644 examples/nodejs/README.md delete mode 100644 examples/nodejs/README_V1.md delete mode 100644 examples/nodejs/hello-callback.js delete mode 100644 examples/nodejs/hello.js delete mode 100644 examples/nodejs/index.js delete mode 100644 examples/nodejs/kubeEventsSlack.js delete mode 100644 examples/nodejs/multi-entry.js delete mode 100644 examples/nodejs/package.json delete mode 100644 examples/nodejs/weather.js delete mode 100644 examples/perl/hello.pm delete mode 100644 examples/php7/hello.php delete mode 100644 examples/php7/hellopsr.php delete mode 100644 examples/php7/multifile/README.md delete mode 100644 examples/php7/multifile/composer.json delete mode 100644 examples/php7/multifile/handlers/FileReader.php delete mode 100644 examples/php7/multifile/handlers/message.txt delete mode 100644 examples/php7/stock.php delete mode 100644 examples/python/README.md delete mode 100644 examples/python/guestbook/add.py delete mode 100755 examples/python/guestbook/deploy.sh delete mode 100644 examples/python/guestbook/get.py delete mode 100644 examples/python/guestbook/redis.yaml delete mode 100644 examples/python/hello.py delete mode 100644 examples/python/multifile/README.md delete mode 100644 examples/python/multifile/__init__.py delete mode 100644 examples/python/multifile/main.py delete mode 100644 examples/python/multifile/message.txt delete mode 100644 examples/python/multifile/readfile.py delete mode 100644 examples/python/requestdata.py delete mode 100644 examples/python/sourcepkg/__init__.py delete mode 100755 examples/python/sourcepkg/build.sh delete mode 100644 examples/python/sourcepkg/requirements.txt delete mode 100644 examples/python/sourcepkg/user.py delete mode 100644 examples/python/statuscode.py delete mode 100644 examples/ruby/README.md delete mode 100644 examples/ruby/events_to_slack.rb delete mode 100644 examples/ruby/hello.rb delete mode 100644 examples/ruby/parse/Gemfile delete mode 100644 examples/ruby/parse/Gemfile.lock delete mode 100644 examples/ruby/parse/parse.rb delete mode 100644 examples/ruby/request_data.rb delete mode 100644 examples/spec-example/hello-spec-exmaple/README.md delete mode 100644 examples/spec-example/hello-spec-exmaple/hello/__init__.py delete mode 100755 examples/spec-example/hello-spec-exmaple/hello/build.sh delete mode 100644 examples/spec-example/hello-spec-exmaple/hello/hello.py delete mode 100644 examples/spec-example/hello-spec-exmaple/hello/requirements.txt delete mode 100644 examples/spec-example/hello-spec-exmaple/specs/env.yaml delete mode 100644 examples/spec-example/hello-spec-exmaple/specs/fission-deployment-config.yaml delete mode 100644 examples/spec-example/hello-spec-exmaple/specs/hello.yaml delete mode 100644 examples/spec-example/nodejs-bodyParser-limit-example/hello/hello.js delete mode 100644 examples/spec-example/nodejs-bodyParser-limit-example/hello/package.json delete mode 100644 examples/spec-example/nodejs-bodyParser-limit-example/specs/README delete mode 100644 examples/spec-example/nodejs-bodyParser-limit-example/specs/env-node.yaml delete mode 100644 examples/spec-example/nodejs-bodyParser-limit-example/specs/fission-deployment-config.yaml delete mode 100644 examples/spec-example/nodejs-bodyParser-limit-example/specs/function-hello.yaml delete mode 100644 examples/spec-example/podspec-example/README.md delete mode 100644 examples/spec-example/podspec-example/specs/README delete mode 100644 examples/spec-example/podspec-example/specs/env-python.yaml delete mode 100644 examples/spec-example/podspec-example/specs/fission-deployment-config.yaml delete mode 100644 examples/tensorflow-serving/README.md delete mode 100644 examples/tensorflow-serving/half_plus_two/00000123/saved_model.pb delete mode 100644 examples/tensorflow-serving/half_plus_two/00000123/variables/variables.data-00000-of-00001 delete mode 100644 examples/tensorflow-serving/half_plus_two/00000123/variables/variables.index diff --git a/.github/workflows/push_pr.yaml b/.github/workflows/push_pr.yaml index 54e55098..fb2f7c62 100644 --- a/.github/workflows/push_pr.yaml +++ b/.github/workflows/push_pr.yaml @@ -14,10 +14,16 @@ jobs: - name: Checkout sources uses: actions/checkout@v2.3.4 + - name: Checkout sources + uses: actions/checkout@v2.3.4 + with: + repository: fission/examples + path: examples + - name: setup go uses: actions/setup-go@v2.1.3 with: - go-version: '1.12.17' + go-version: '1.14.0' - name: Helm installation uses: Azure/setup-helm@v1 @@ -64,12 +70,6 @@ jobs: go build -o fission cmd/fission-cli/main.go sudo mv fission /usr/local/bin fission version - - # - name: Skip & install fission - # run: kubectl create ns fission && helm install --namespace fission --name-template fission https://github.com/fission/fission/releases/download/1.11.2/fission-all-1.11.2.tgz --set pruneInterval=1 - - # - name: Skip & install cli - # run: curl -Lo fission https://github.com/fission/fission/releases/download/1.11.2/fission-cli-linux && chmod +x fission && sudo mv fission /usr/local/bin/ - name: Port-forward fission components run: | diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a081345a..00000000 --- a/.travis.yml +++ /dev/null @@ -1,61 +0,0 @@ -sudo: required - -dist: trusty - -branches: - only: - - master - -language: go - -go: - - 1.12.x - -env: - - KUBECONFIG=${HOME}/.kube/config PATH=$HOME/k8scli:$HOME/tool:$HOME/google-cloud-sdk/bin:${PATH} GO111MODULE=on DOCKER_CACHE_DIR=${HOME}/docker/ - -cache: - directories: - - $HOME/google-cloud-sdk/ - - $HOME/k8scli - - $HOME/tool - - $HOME/.cache/go-build - - $HOME/gopath/pkg/mod - -services: - - docker - -before_install: - - sudo apt-get update -# - sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce - - sudo apt-get -y install apache2-utils parallel realpath - - sudo sysctl net.ipv6.conf.all.disable_ipv6=0 - -install: - - hack/travis-kube-setup.sh - -before_script: - - cd ${TRAVIS_BUILD_DIR} - - go mod download - - hack/verify-staticcheck.sh - - hack/verify-gofmt.sh - - hack/verify-govet.sh - - helm lint charts/fission-all/ charts/fission-core/ - - hack/runtests.sh - - test/build.sh - -script: - - cd ${TRAVIS_BUILD_DIR} - - test/test.sh - - test/upgrade/fission_upgrade_test.sh - -after_script: - - bash <(curl -s https://codecov.io/bash) - - kubectl --namespace default delete configmap -l travisID=${TRAVIS_BUILD_ID} # remove in-test configmap to indicate this CI build finished - -notifications: - slack: - rooms: - secure: YZ34vsfw1TtftJypg1MyP4+ihONI4gaxeS3FghBQli6+EezjzcxOXyj5VD+x0ucXfDeTaDrFfmVN0SAGObOoZUE+ea9KAoTo50tRLaD9kwOTACiekZalC4uuBguH0D1/A6vlbU8dchsr9mvIhbisG6mTncdPtqGYYHtyBQme6ngmmHbVAQFZcIBHmNuDb/HWhSr8KMEuyB6+mBXLYELHnXnf26cOhdGNaagqCOJTiemX85RGwIuOPxyBhKDFMLyHohDT7FJMH/qijveE6YgOYTQC5nYc2Np1KvC7hQkIu4nuyczyYlrNQl/TWv+SVI8PjIs0PYuCuD3gUqoVEi8d94HbrOPzFEpbwDS9P4qL39DGmco1Q56Vqxe6sRI0vDWPb5gCP1lSgs3PMECVn7Wor/pTvcL+C+U2jLwWJUl0vbyWCL7ngl/3iTssV7qBpUrI7Oclwp8LrQo9fPj0DL4gE9rNanpEWjQ6yPGaysIL1zLHtRghhm52A22NJGp71jkS2KEpLi6ZWFYjMeuXw5eOQFhqFlzyRJOmLYa3B607TLWuyo2L2CxAfMmq0FGfemvrkLZIWtlQKK4y9ImpsURwaGT2XCtThFtHl77wEss913nC+T2dX3O5Bl0UmxFd5S3mVM109I8c4lDosxnAjRfS9MheFlrG0gjSJSBCw57x7f0= - on_success: change - on_failure: always diff --git a/environments/binary/Dockerfile b/environments/binary/Dockerfile deleted file mode 100644 index 5c0ac2f4..00000000 --- a/environments/binary/Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM golang:onbuild - -WORKDIR /go -COPY *.go /go/ - -RUN GOOS=linux GOARCH=386 go build -o server . - -FROM alpine:3.5 - -WORKDIR /app - -RUN apk update -RUN apk add coreutils binutils findutils grep - -COPY --from=0 /go/server /app/server - -EXPOSE 8888 -ENTRYPOINT ["./server"] diff --git a/environments/binary/README.md b/environments/binary/README.md deleted file mode 100644 index cf576006..00000000 --- a/environments/binary/README.md +++ /dev/null @@ -1,59 +0,0 @@ -# Binary Environment Examples - -The `binary` runtime is a go server that uses a subprocess to invoke executables or execute shell scripts. - -Use Cases -- Execute bash scripts -- Execute arbitrary binaries (such as common sysadmin tools) -- Get support in _any_ programming language by executing the generated executable. - - -⚠️ **Words of Caution** ⚠️ - -The environment runs on an alpine image with some additional utility command line tools installed, such as 'grep'. -However, in case you want to make use of more esoteric command line tools, you should add the relevant apk to the -Dockerfile and build a new binary environment. See 'Compiling' for instructions. - -When executing functions using binaries, **ensure that the executable is built for the right architecture**. -Using the default binary environment this means that the binary should be build for Linux. - -Looking for ready-to-run examples? See the [binary examples directory](../../examples/binary). - -## Usage -To get started with the latest binary environment: - -```bash -fission env create --name binary --image fission/binary-env --builder fission/binary-builder -``` - -The interface to the executable used by this environment is somewhat similar to a [CGI interface](https://en.wikipedia.org/wiki/Common_Gateway_Interface). -This means that any HTTP headers are converted to environment variables of the form "HTTP_". For example these -are some of frequently occurring headers: - -```bash -# Request Metadata -CONTENT_LENGTH -REQUEST_URI -REQUEST_METHOD - -# HTTP Headers -HTTP_ACCEPT -HTTP_USER-AGENT -HTTP_CONTENT-TYPE -# ... -``` - -The body of HTTP piped over the STDIN to the executable. -All output that is provided to the server over the STDOUT will be transformed into the HTTP response. - -## Compiling - -To build the runtime environment: -```bash -docker build --tag=${USER}/binary-env . -``` - -To build the builder environment: -```bash -(cd builder/ && docker build --tag=${USER}/binary-builder .) -``` diff --git a/environments/binary/builder/Dockerfile b/environments/binary/builder/Dockerfile deleted file mode 100644 index 99cefe26..00000000 --- a/environments/binary/builder/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -ARG BUILDER_IMAGE=fission/builder:latest -FROM ${BUILDER_IMAGE} - -ADD build.sh /usr/local/bin/build diff --git a/environments/binary/builder/build.sh b/environments/binary/builder/build.sh deleted file mode 100755 index c70eb663..00000000 --- a/environments/binary/builder/build.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -apk update - -CWD=$(pwd) - -if [ -f ${SRC_PKG}/build.sh ]; then - cd ${SRC_PKG} - ./build.sh - cd ${CWD} -fi - -cp -rf ${SRC_PKG} ${DEPLOY_PKG} diff --git a/environments/binary/env.go b/environments/binary/env.go deleted file mode 100644 index 2e66c2cd..00000000 --- a/environments/binary/env.go +++ /dev/null @@ -1,45 +0,0 @@ -package main - -import ( - "fmt" - "strings" -) - -// Utility functions for working with environment variables -type Env struct { - Vars []*EnvVar -} - -type EnvVar struct { - Key string - Val string -} - -func FromString(rawEnvVar string) *EnvVar { - parts := strings.SplitN(rawEnvVar, "=", 2) - return &EnvVar{parts[0], parts[1]} -} - -func (ev *EnvVar) ToString() string { - return fmt.Sprintf("%s=%s", ev.Key, ev.Val) -} - -func (e *Env) SetEnv(envVar *EnvVar) { - e.Vars = append(e.Vars, envVar) -} - -func (e *Env) ToStringEnv() []string { - var result []string - for _, envVar := range e.Vars { - result = append(result, envVar.ToString()) - } - return result -} - -func NewEnv(stringEnv []string) *Env { - env := &Env{} - for _, rawEnvVar := range stringEnv { - env.SetEnv(FromString(rawEnvVar)) - } - return env -} diff --git a/environments/binary/server.go b/environments/binary/server.go deleted file mode 100644 index 2ea99a04..00000000 --- a/environments/binary/server.go +++ /dev/null @@ -1,178 +0,0 @@ -package main - -import ( - "encoding/json" - "flag" - "fmt" - "io" - "io/ioutil" - "net/http" - "os" - "os/exec" - "path/filepath" - "strings" -) - -const ( - DEFAULT_CODE_PATH = "/userfunc/user" - DEFAULT_INTERNAL_CODE_PATH = "/bin/userfunc" -) - -var specialized bool - -type ( - BinaryServer struct { - fetchedCodePath string - internalCodePath string - } - - FunctionLoadRequest struct { - // FilePath is an absolute filesystem path to the - // function. What exactly is stored here is - // env-specific. Optional. - FilePath string `json:"filepath"` - - // FunctionName has an environment-specific meaning; - // usually, it defines a function within a module - // containing multiple functions. Optional; default is - // environment-specific. - FunctionName string `json:"functionName"` - - // URL to expose this function at. Optional; defaults - // to "/". - URL string `json:"url"` - } -) - -func (bs *BinaryServer) SpecializeHandler(w http.ResponseWriter, r *http.Request) { - if specialized { - w.WriteHeader(http.StatusBadRequest) - w.Write([]byte("Not a generic container")) - return - } - - request := FunctionLoadRequest{} - - codePath := bs.fetchedCodePath - err := json.NewDecoder(r.Body).Decode(&request) - switch { - case err == io.EOF: - case err != nil: - panic(err) - } - - if request.FilePath != "" { - fileStat, err := os.Stat(request.FilePath) - if err != nil { - panic(err) - } - - codePath = request.FilePath - switch mode := fileStat.Mode(); { - case mode.IsDir(): - codePath = filepath.Join(request.FilePath, request.FunctionName) - } - } - - _, err = os.Stat(codePath) - if err != nil { - if os.IsNotExist(err) { - w.WriteHeader(http.StatusNotFound) - w.Write([]byte(codePath + ": not found")) - return - } else { - panic(err) - } - } - - // Future: Check if executable is correct architecture/executable. - - // Copy the executable to ensure that file is executable and immutable. - userFunc, err := ioutil.ReadFile(codePath) - if err != nil { - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte("Failed to read executable.")) - return - } - err = ioutil.WriteFile(bs.internalCodePath, userFunc, 0555) - if err != nil { - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte("Failed to write executable to target location.")) - return - } - - fmt.Println("Specializing ...") - specialized = true - fmt.Println("Done") -} - -func (bs *BinaryServer) InvocationHandler(w http.ResponseWriter, r *http.Request) { - if !specialized { - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte("Generic container: no requests supported")) - return - } - - // CGI-like passing of environment variables - execEnv := NewEnv(nil) - execEnv.SetEnv(&EnvVar{"REQUEST_METHOD", r.Method}) - execEnv.SetEnv(&EnvVar{"REQUEST_URI", r.RequestURI}) - execEnv.SetEnv(&EnvVar{"CONTENT_LENGTH", fmt.Sprintf("%d", r.ContentLength)}) - - for header, val := range r.Header { - execEnv.SetEnv(&EnvVar{fmt.Sprintf("HTTP_%s", strings.ToUpper(header)), val[0]}) - } - - // Future: could be improved by keeping subprocess open while environment is specialized - cmd := exec.Command(bs.internalCodePath) - cmd.Env = execEnv.ToStringEnv() - - if r.ContentLength != 0 { - fmt.Println(r.ContentLength) - stdin, err := cmd.StdinPipe() - if err != nil { - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte(fmt.Sprintf("Failed to get STDIN pipe: %s", err))) - panic(err) - } - _, err = io.Copy(stdin, r.Body) - if err != nil { - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte(fmt.Sprintf("Failed to pipe input: %s", err))) - } - stdin.Close() - } - - out, err := cmd.Output() - if err != nil { - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte(fmt.Sprintf("Function error: %s", err))) - return - } - - w.WriteHeader(http.StatusOK) - w.Write(out) -} - -func main() { - codePath := flag.String("c", DEFAULT_CODE_PATH, "Path to expected fetched executable.") - internalCodePath := flag.String("i", DEFAULT_INTERNAL_CODE_PATH, "Path to specialized executable.") - flag.Parse() - absInternalCodePath, err := filepath.Abs(*internalCodePath) - if err != nil { - panic(err) - } - fmt.Printf("Using fetched code path: %s\n", *codePath) - fmt.Printf("Using internal code path: %s\n", absInternalCodePath) - - server := &BinaryServer{*codePath, absInternalCodePath} - http.HandleFunc("/", server.InvocationHandler) - http.HandleFunc("/specialize", server.SpecializeHandler) - http.HandleFunc("/v2/specialize", server.SpecializeHandler) - - fmt.Println("Listening on 8888 ...") - err = http.ListenAndServe(":8888", nil) - if err != nil { - panic(err) - } -} diff --git a/environments/dotnet/.gitignore b/environments/dotnet/.gitignore deleted file mode 100644 index 8a82e2f6..00000000 --- a/environments/dotnet/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -bin/* -obj/* -out/* -.vscode/* -project.lock* -TODO_dotnet \ No newline at end of file diff --git a/environments/dotnet/Dockerfile b/environments/dotnet/Dockerfile deleted file mode 100644 index 09decded..00000000 --- a/environments/dotnet/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM microsoft/dotnet:1.1-sdk AS builder - -COPY * /proj/ -RUN cd /proj && ./project-build.sh - -# Build env image -FROM microsoft/dotnet:1.1.0-runtime - -WORKDIR /fission-workdir -COPY --from=builder /proj/out . -EXPOSE 8888 - -ENTRYPOINT ["dotnet"] - -CMD ["fission-dotnet.dll"] diff --git a/environments/dotnet/ExecutorModule.cs b/environments/dotnet/ExecutorModule.cs deleted file mode 100644 index 311140fb..00000000 --- a/environments/dotnet/ExecutorModule.cs +++ /dev/null @@ -1,82 +0,0 @@ -using Fission.DotNetCore.Compiler; -using Fission.DotNetCore.Api; -using System.Collections.Generic; -using Nancy; -using System.IO; -using System; - -namespace Fission.DotNetCore -{ - public class ExecutorModule : NancyModule - { -#if DEBUG - private const string CODE_PATH = "/tmp/func.cs"; -#else - private const string CODE_PATH = "/userfunc/user"; -#endif - private static Function _userFunc; - private static Logger _logger = new Logger(); - - public ExecutorModule() - { - Post("/specialize", args => Specialize()); - Get("/", _ => Run()); - Post("/", _ => Run()); - Put("/", _ => Run()); - Head("/", _ => Run()); - Options("/", _ => Run()); - Delete("/", _ => Run()); - } - - private object Specialize() - { - var errors = new List(); - if (File.Exists(CODE_PATH)) - { - var code = File.ReadAllText(CODE_PATH); - _userFunc = FissionCompiler.Compile(code, out errors); - if (_userFunc == null) - { - var errstr = string.Join(Environment.NewLine, errors); - _logger.WriteError(errstr); - var response = (Response)errstr; - response.StatusCode = HttpStatusCode.InternalServerError; - return response; - - } - return null; - } - else - { - var errstr = $"Unable to locate code at '{CODE_PATH}'"; - _logger.WriteError(errstr); - var response = (Response)errstr; - response.StatusCode = HttpStatusCode.InternalServerError; - return response; - } - } - - private object Run() - { - if (_userFunc == null) - { - var response = (Response)"Generic container: no requests supported"; - response.StatusCode = HttpStatusCode.InternalServerError; - return response; - } - - try - { - return _userFunc.Invoke(FissionContext.Build(Request, new Logger())); - } - catch (Exception e) - { - _logger.WriteError(e.ToString()); - var response = (Response)e.Message; - response.StatusCode = HttpStatusCode.BadRequest; - return response; - } - } - } -} - diff --git a/environments/dotnet/FissionCompiler.cs b/environments/dotnet/FissionCompiler.cs deleted file mode 100644 index f4dc4ee6..00000000 --- a/environments/dotnet/FissionCompiler.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Runtime.Loader; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.Emit; - -namespace Fission.DotNetCore.Compiler -{ - //adapted from this article http://www.tugberkugurlu.com/archive/compiling-c-sharp-code-into-memory-and-executing-it-with-roslyn - class FissionCompiler - { - public static Function Compile(string code, out List errors) - { - errors = new List(); - - SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(code); - - string assemblyName = Path.GetRandomFileName(); - - var coreDir = Directory.GetParent(typeof(Enumerable).GetTypeInfo().Assembly.Location); - - List references = new List - { - MetadataReference.CreateFromFile(coreDir.FullName + Path.DirectorySeparatorChar + "mscorlib.dll"), - MetadataReference.CreateFromFile(typeof(object).GetTypeInfo().Assembly.Location), - MetadataReference.CreateFromFile(Assembly.GetEntryAssembly().Location), - MetadataReference.CreateFromFile(typeof(System.Runtime.Serialization.Json.DataContractJsonSerializer).GetTypeInfo().Assembly.Location) - }; - - foreach (var referencedAssembly in Assembly.GetEntryAssembly().GetReferencedAssemblies()) - { - var assembly = Assembly.Load(referencedAssembly); - references.Add(MetadataReference.CreateFromFile(assembly.Location)); - } - - CSharpCompilation compilation = CSharpCompilation.Create( - assemblyName, - syntaxTrees: new[] { syntaxTree }, - references: references, - options: new CSharpCompilationOptions( - OutputKind.DynamicallyLinkedLibrary, - optimizationLevel: OptimizationLevel.Release)); - - using (var ms = new MemoryStream()) - { - EmitResult result = compilation.Emit(ms); - - if (!result.Success) - { - IEnumerable failures = result.Diagnostics.Where(diagnostic => - diagnostic.IsWarningAsError || - diagnostic.Severity == DiagnosticSeverity.Error).ToList(); - - foreach (Diagnostic diagnostic in failures) - { - errors.Add($"{diagnostic.Id}: {diagnostic.GetMessage()}"); - } - } - else - { - ms.Seek(0, SeekOrigin.Begin); - - Assembly assembly = AssemblyLoadContext.Default.LoadFromStream(ms); - var type = assembly.GetType("FissionFunction"); - var info = type.GetMember("Execute").First() as MethodInfo; - return new Function(assembly, type, info); - } - } - return null; - } - } -} diff --git a/environments/dotnet/FissionContext.cs b/environments/dotnet/FissionContext.cs deleted file mode 100644 index b4117531..00000000 --- a/environments/dotnet/FissionContext.cs +++ /dev/null @@ -1,114 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Security.Cryptography.X509Certificates; -using System.Text; -using Nancy; - -namespace Fission.DotNetCore.Api -{ - public class FissionContext - { - public FissionContext(Dictionary args, Logger logger, FissionHttpRequest request) - { - if (args == null) throw new ArgumentNullException(nameof(args)); - if (logger == null) throw new ArgumentNullException(nameof(logger)); - if (request == null) throw new ArgumentNullException(nameof(request)); - Arguments = args; - Logger = logger; - Request = request; - } - - public Dictionary Arguments { get; private set; } - - public FissionHttpRequest Request { get; private set; } - - public Logger Logger { get; private set; } - - public static FissionContext Build(Request request, Logger logger) - { - return new FissionContext(((DynamicDictionary)request.Query).ToDictionary(), - logger, - new FissionHttpRequest(request)); - } - } - - public class Logger - { - public void Write(Severity severity, string format, params object[] args) - { - Console.WriteLine($"{DateTime.Now.ToString("MM/dd/yy H:mm:ss zzz")} {severity}: " + format, args); - } - - public void WriteInfo(string format, params object[] args) - { - Write(Severity.Info, format, args); - } - - public void WriteWarning(string format, params object[] args) - { - Write(Severity.Warning, format, args); - } - - public void WriteError(string format, params object[] args) - { - Write(Severity.Error, format, args); - } - - public void WriteCritical(string format, params object[] args) - { - Write(Severity.Critical, format, args); - } - - public void WriteVerbose(string format, params object[] args) - { - Write(Severity.Verbose, format, args); - } - } - - public enum Severity - { - Info, - Warning, - Error, - Critical, - Verbose - } - - public class FissionHttpRequest - { - private readonly Request _request; - internal FissionHttpRequest(Request request) - { - if (request == null) throw new ArgumentNullException(nameof(request)); - _request = request; - } - - public Stream Body { get { return _request.Body; } } - - public string BodyAsString() - { - int length = (int)_request.Body.Length; - byte[] data = new byte[length]; - _request.Body.Read(data, 0, length); - return Encoding.UTF8.GetString(data); - } - - public Dictionary> Headers - { - get - { - var headers = new Dictionary>(); - foreach (var kv in _request.Headers) - { - headers.Add(kv.Key, kv.Value); - } - return headers; - } - } - - public X509Certificate Certificate { get { return _request.ClientCertificate; } } - public string Url { get { return _request.Url.ToString(); } } - public string Method { get { return _request.Method; } } - } -} \ No newline at end of file diff --git a/environments/dotnet/Function.cs b/environments/dotnet/Function.cs deleted file mode 100644 index f8b5f724..00000000 --- a/environments/dotnet/Function.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Reflection; -using Fission.DotNetCore.Api; - -namespace Fission.DotNetCore.Compiler -{ - class Function - { - private readonly Assembly _assembly; - private readonly Type _type; - private readonly MethodInfo _info; - - public Function(Assembly assembly, Type type, MethodInfo info) - { - if (info == null) throw new ArgumentNullException(nameof(info)); - if (assembly == null) throw new ArgumentNullException(nameof(assembly)); - if (type == null) throw new ArgumentNullException(nameof(type)); - _assembly = assembly; - _type = type; - _info = info; - } - - public object Invoke(FissionContext context) - { - return _info.Invoke(_assembly.CreateInstance(_type.FullName), new[] { context }); - } - } -} diff --git a/environments/dotnet/Program.cs b/environments/dotnet/Program.cs deleted file mode 100755 index 85dc1628..00000000 --- a/environments/dotnet/Program.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.IO; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Nancy.Owin; - -namespace Fission.DotNetCore -{ - public class Program - { - public static void Main(string[] args) - { - var host = new WebHostBuilder() - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseKestrel() - .UseUrls("http://*:8888") - .Configure(app => app.UseOwin(x => x.UseNancy())) - .Build(); - host.Run(); - } - } -} diff --git a/environments/dotnet/README.md b/environments/dotnet/README.md deleted file mode 100644 index 8991474f..00000000 --- a/environments/dotnet/README.md +++ /dev/null @@ -1,270 +0,0 @@ -# Fission: dotnet C# Environment - -This is a simple dotnet C# environment for Fission. - -It's a Docker image containing the dotnet 1.1.0 runtime. The image -uses Kestrel with Nancy to host the internal web server and uses -Roslyn to compile the uploaded code. - -The image supports compiling and running code with types defined in -mscorlib and does not at present support other library references. -One workaround for this would be to add the references to this project's -project.json file and rebuild the container. - -The environment works via convention where you create a C# class -called FissionFunction which has a method named Execute taking a single -parameter, a FissionContext object. - -The FissionContext object gives access to the arguments and other items -like logging. Please see FissionContext.cs for public API. - -Example of simplest possible class to be executed: - -``` -using System; -using Fission.DotNetCore.Api; - -public class FissionFunction { - public string Execute(FissionContext context) { - return null; - } -} -``` - -Please see examples below, or if you are looking for ready-to-run examples, see -the [DotNet examples directory](../../examples/dotnet). - -## Rebuilding and pushing the image - -To rebuild the image you will have to install Docker with version higher than 17.05+ -in order to support multi-stage builds feature. - -### Rebuild containers - -Move to the directory containing the source and start the container build process: - -``` -docker build -t USER/dotnet-env . -``` - -After the build finishes push the new image to a Docker registry using the -standard procedure. - -## Echo example - -### Setup fission environment -First you need to setup the fission according to your cluster setup as -specified here: https://github.com/fission/fission - - -### Create the class to run - -Secondly you need to create a file /tmp/func.cs containing the following code: - -``` -using System; -using Fission.DotNetCore.Api; - -public class FissionFunction -{ - public string Execute(FissionContext context){ - context.Logger.WriteInfo("executing.. {0}", context.Arguments["text"]); - return (string)context.Arguments["text"]; - } -} -``` -### Run the example - -Lastly to run the example: - -``` -$ fission env create --name dotnet --image fission/dotnet-env - -$ fission function create --name echo --env dotnet --code /tmp/func.cs - -$ fission route create --method GET --url /echo --function echo - -$ curl http://$FISSION_ROUTER/echo?text=hello%20world! - hello world -``` - -## Addition service example - -### Setup fission environment -First you need to setup the fission according to your cluster setup as -specified here: https://github.com/fission/fission - - -### Create the class to run - -Secondly you need to create a file /tmp/func.cs containing the following code: - -``` -using System; -using Fission.DotNetCore.Api; - -public class FissionFunction -{ - public string Execute(FissionContext context){ - var x = Convert.ToInt32(context.Arguments["x"]); - var y = Convert.ToInt32(context.Arguments["y"]); - return (x+y).ToString(); - } -} -``` -### Run the example - -Lastly to run the example: - -``` -$ fission env create --name dotnet --image fission/dotnet-env - -$ fission function create --name addition --env dotnet --code /tmp/func.cs - -$ fission route create --method GET --url /add --function addition - -$ curl "http://$FISSION_ROUTER/add?x=30&y=12" - 42 -``` - -## Accessing http request information example - -### Setup fission environment -First you need to setup the fission according to your cluster setup as -specified here: https://github.com/fission/fission - - -### Create the class to run - -Secondly you need to create a file /tmp/func.cs containing the following code: - -``` -using System; -using Fission.DotNetCore.Api; - -public class FissionFunction -{ - public string Execute(FissionContext context){ - var buffer = new System.Text.StringBuilder(); - foreach(var header in context.Request.Headers){ - buffer.AppendLine(header.Key); - foreach(var item in header.Value){ - buffer.AppendLine($"\t{item}"); - } - } - buffer.AppendLine($"Url: {context.Request.Url}, method: {context.Request.Method}"); - return buffer.ToString(); - } -} - -``` -### Run the example - -Lastly to run the example: - -``` -$ fission env create --name dotnet --image fission/dotnet-env - -$ fission function create --name httpinfo --env dotnet --code /tmp/func.cs - -$ fission route create --method GET --url /http_info --function httpinfo - -$ curl "http://$FISSION_ROUTER/http_info" -Accept - */*;q=1 -Host - fissionserver:8888 -User-Agent - curl/7.47.0 -Url: http://fissionserver:8888, method: GET - -``` - -## Accessing http request body example - -### Setup fission environment -First you need to setup the fission according to your cluster setup as -specified here: https://github.com/fission/fission - - -### Create the class to run - -Secondly you need to create a file /tmp/func.cs containing the following code: - -``` -using System.IO; -using System.Runtime.Serialization.Json; -using Fission.DotNetCore.Api; - -public class FissionFunction -{ - public string Execute(FissionContext context) - { - var person = Person.Deserialize(context.Request.Body); - return $"Hello, my name is {person.Name} and I am {person.Age} years old."; - } -} - -public class Person -{ - public string Name { get; set; } - public int Age { get; set; } - - public static Person Deserialize(Stream json) - { - var serializer = new DataContractJsonSerializer(typeof(Person)); - return (Person)serializer.ReadObject(json); - } -} - -``` -### Run the example - -Lastly to run the example: - -``` -$ fission env create --name dotnet --image fission/dotnet-env - -$ fission function create --name httpbody --env dotnet --code /tmp/func.cs - -$ fission route create --method GET --url /http_body --function httpbody - -$ curl -XPOST "http://$FISSION_ROUTER/http_body" -d '{ "Name":"Arthur", "Age":42}' -Hello, my name is Arthur and I am 42 years old. - -``` - - -## Developing/debugging the enviroment locally - -The easiest way to debug the environment is to open the directory in -Visual Studio Code (VSCode) as that will setup debugger for you the -first time. - -Remember to install the excellent extension -"C# for Visual Studio Code(powered by OmniSharp)" to get statement completion - -The class ExecutorModule contain preprocessor directive overriding where -the input code file should be found: - -``` -#if DEBUG - private const string CODE_PATH = "/tmp/func.cs"; -#else - private const string CODE_PATH = "/userfunc/user"; -#endif -``` - -So what you need to do is: -1. Open the directory in VSCode. -This will prompt restore of packages and query is debugger setup is needed. Accept both prompts. -2. Press F5 to start the web server. Set breakpoints etc.. -3. Add a code file containing valid C# at /tmp/func.cs -4. Specialize the service with curl via post -``` -$ curl -XPOST http://localhost:8888/specialize -``` -5. Call your function with curl -``` -$ curl -XGET http://localhost:8888 -``` diff --git a/environments/dotnet/fission-dotnet.csproj b/environments/dotnet/fission-dotnet.csproj deleted file mode 100755 index 84ecb3d1..00000000 --- a/environments/dotnet/fission-dotnet.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - netcoreapp1.0 - fission-dotnet - Exe - dotnet - $(PackageTargetFallback);netstandard1.3 - 1.1.0 - - - - - - - - - - - - diff --git a/environments/dotnet/project-build.sh b/environments/dotnet/project-build.sh deleted file mode 100755 index e4d19b7f..00000000 --- a/environments/dotnet/project-build.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -dotnet restore fission-dotnet.csproj -dotnet publish fission-dotnet.csproj -c Release -o out diff --git a/environments/dotnet20/.dockerignore b/environments/dotnet20/.dockerignore deleted file mode 100644 index b05c21cd..00000000 --- a/environments/dotnet20/.dockerignore +++ /dev/null @@ -1 +0,0 @@ -builder \ No newline at end of file diff --git a/environments/dotnet20/Dockerfile b/environments/dotnet20/Dockerfile deleted file mode 100644 index 3391236d..00000000 --- a/environments/dotnet20/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM microsoft/dotnet:2.0.0-sdk AS builder - -COPY * /proj/ -RUN cd /proj && ./project-build.sh - -# Build env image -FROM microsoft/dotnet:2.0-runtime - -WORKDIR /fission-workdir -COPY --from=builder /proj/out . -EXPOSE 8888 - -ENTRYPOINT ["dotnet"] - -CMD ["fission-dotnet20.dll"] diff --git a/environments/dotnet20/ExecutorModule.cs b/environments/dotnet20/ExecutorModule.cs deleted file mode 100644 index d3780ac9..00000000 --- a/environments/dotnet20/ExecutorModule.cs +++ /dev/null @@ -1,179 +0,0 @@ -using Fission.DotNetCore.Compiler; -using Fission.DotNetCore.Api; -using System.Collections.Generic; -using Nancy; -using System.IO; -using System; -using Nancy.IO; -using Fission.DotNetCore.Utilty; -using Fission.DotNetCore.Model; -using Nancy.Extensions; - -namespace Fission.DotNetCore -{ - public class ExecutorModule : NancyModule - { - private static string PackagePath = string.Empty; -#if DEBUG - private const string CODE_PATH = "/tmp/func.cs"; -#else - private const string CODE_PATH = "/userfunc/user"; -#endif - private static Function _userFunc; - private static Logger _logger = new Logger(); - - public ExecutorModule() - { - Post("/specialize", args => Specialize()); - Post("/v2/specialize", args => Specializev2()); - Get("/", _ => Run()); - Post("/", _ => Run()); - Put("/", _ => Run()); - Head("/", _ => Run()); - Options("/", _ => Run()); - Delete("/", _ => Run()); - } - - private object Specializev2() - { - Console.WriteLine("Call Reached at /v2/specialize"); - - try - { - var errors = new List(); - var oinfo = new List(); - var _request = Request; - var _body = Request.Body; - // Request.Body.Position = 0; use it only if request has already been read before that - var _requestBodystring = RequestStream.FromStream(Request.Body).AsString(); - Console.WriteLine($"Request received by endpoint from builder : {_requestBodystring}"); - BuilderRequest builderRequest = EnvironmentHelper.Instance.GetBuilderRequest(_requestBodystring); - if (builderRequest == null) - { - Console.WriteLine("Error : Unable to parse builder request!!"); - throw new Exception("Error : Unable to parse builder request!!"); - } - - string functionPath = string.Empty; - // functionPath = Path.Combine(builderRequest.filepath, $"{builderRequest.functionName}.cs"); - - PackagePath = builderRequest.filepath; - //following will enable us to skip --entrypoint flag during function creation - if (!string.IsNullOrWhiteSpace(builderRequest.functionName)) - { - functionPath = Path.Combine(builderRequest.filepath, $"{builderRequest.functionName}.cs"); - } - else - { - functionPath = Path.Combine(builderRequest.filepath, EnvironmentHelper.Instance.environmentSettings.functionBodyFileName); - } - - Console.WriteLine($"Going to read function body from path : {functionPath}"); - - if (File.Exists(functionPath)) - { - var code = File.ReadAllText(functionPath); - try - { - FissionCompiler fissionCompiler = new FissionCompiler(builderRequest.filepath); - _userFunc = fissionCompiler.Compilev2(code, out errors, out oinfo); - } - catch (Exception ex) - { - Console.WriteLine($"Error getting _userFunc :{ex.Message} , Trace : {ex.StackTrace}"); - } - if (_userFunc == null) - { - var errstr = string.Join(Environment.NewLine, errors); - _logger.WriteError(errstr); - Console.WriteLine($"Error _userFunc is null :{errstr}"); - var response = (Response)errstr; - response.StatusCode = HttpStatusCode.InternalServerError; - return response; - - } - else - { - //try to retrun few details - var infostr = string.Join(Environment.NewLine, oinfo); - _logger.WriteInfo(infostr); - var response = (Response)infostr; - response.StatusCode = HttpStatusCode.OK; - return response; - } - } - else - { - var errstr = $"Unable to locate code at '{functionPath}'"; - _logger.WriteError(errstr); - var response = (Response)errstr; - response.StatusCode = HttpStatusCode.InternalServerError; - return response; - } - } - catch (Exception ex) - { - Console.WriteLine($"Exception occurred {ex.Message} | {ex.StackTrace}"); - var errstr = $"Exception occurred {ex.Message} | {ex.StackTrace}"; - _logger.WriteError(errstr); - var response = (Response)errstr; - response.StatusCode = HttpStatusCode.InternalServerError; - return response; - } - } - - private object Specialize() - { - var errors = new List(); - if (File.Exists(CODE_PATH)) - { - var code = File.ReadAllText(CODE_PATH); - _userFunc = FissionCompiler.Compile(code, out errors); - if (_userFunc == null) - { - var errstr = string.Join(Environment.NewLine, errors); - _logger.WriteError(errstr); - var response = (Response)errstr; - response.StatusCode = HttpStatusCode.InternalServerError; - return response; - - } - return null; - } - else - { - var errstr = $"Unable to locate code at '{CODE_PATH}'"; - _logger.WriteError(errstr); - var response = (Response)errstr; - response.StatusCode = HttpStatusCode.InternalServerError; - return response; - } - } - - private object Run() - { - if (_userFunc == null) - { - var response = (Response)"Generic container: no requests supported"; - response.StatusCode = HttpStatusCode.InternalServerError; - return response; - } - - try - { - var context = FissionContext.Build(Request, new Logger()); - //set the package path ,as that will be required to get appsetting files from package - context.PackagePath = PackagePath; - return _userFunc.Invoke(context); - } - catch (Exception e) - { - _logger.WriteError(e.ToString()); - var response = (Response)e.Message; - response.StatusCode = HttpStatusCode.BadRequest; - return response; - } - } - } -} - diff --git a/environments/dotnet20/FissionCompiler.cs b/environments/dotnet20/FissionCompiler.cs deleted file mode 100644 index a08f8789..00000000 --- a/environments/dotnet20/FissionCompiler.cs +++ /dev/null @@ -1,224 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Runtime.Loader; -using Fission.DotNetCore.Model; -using Fission.DotNetCore.Utilty; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.Emit; - -namespace Fission.DotNetCore.Compiler -{ - //adapted from this article http://www.tugberkugurlu.com/archive/compiling-c-sharp-code-into-memory-and-executing-it-with-roslyn - class FissionCompiler - { - string packagepath = string.Empty; - FunctionSpecification functionSpecification = null; - public FissionCompiler(string _packagePath) - { - this.packagepath = _packagePath; - } - public static Function Compile(string code, out List errors) - { - errors = new List(); - - SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(code); - - string assemblyName = Path.GetRandomFileName(); - - var coreDir = Directory.GetParent(typeof(Enumerable).GetTypeInfo().Assembly.Location); - - List references = new List - { - MetadataReference.CreateFromFile(coreDir.FullName + Path.DirectorySeparatorChar + "mscorlib.dll"), - MetadataReference.CreateFromFile(typeof(object).GetTypeInfo().Assembly.Location), - MetadataReference.CreateFromFile(Assembly.GetEntryAssembly().Location), - MetadataReference.CreateFromFile(typeof(System.Runtime.Serialization.Json.DataContractJsonSerializer).GetTypeInfo().Assembly.Location) - }; - - foreach (var referencedAssembly in Assembly.GetEntryAssembly().GetReferencedAssemblies()) - { - var assembly = Assembly.Load(referencedAssembly); - references.Add(MetadataReference.CreateFromFile(assembly.Location)); - } - - CSharpCompilation compilation = CSharpCompilation.Create( - assemblyName, - syntaxTrees: new[] { syntaxTree }, - references: references, - options: new CSharpCompilationOptions( - OutputKind.DynamicallyLinkedLibrary, - optimizationLevel: OptimizationLevel.Release)); - - using (var ms = new MemoryStream()) - { - EmitResult result = compilation.Emit(ms); - - if (!result.Success) - { - IEnumerable failures = result.Diagnostics.Where(diagnostic => - diagnostic.IsWarningAsError || - diagnostic.Severity == DiagnosticSeverity.Error).ToList(); - - foreach (Diagnostic diagnostic in failures) - { - errors.Add($"{diagnostic.Id}: {diagnostic.GetMessage()}"); - } - } - else - { - ms.Seek(0, SeekOrigin.Begin); - - Assembly assembly = AssemblyLoadContext.Default.LoadFromStream(ms); - //support for Namespace , as well as backward compatibility for existing functions - var type = assembly.GetTypes().FirstOrDefault(x => x.Name.EndsWith("FissionFunction")); - var info = type.GetMember("Execute").First() as MethodInfo; - return new Function(assembly, type, info); - } - } - return null; - } - - public Function Compilev2(string code, out List errors, out List oinfo) - { - errors = new List(); - oinfo = new List(); - - #region syntext tree and default reference build - SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(code); - - string assemblyName = Path.GetRandomFileName(); - - var coreDir = Directory.GetParent(typeof(Enumerable).GetTypeInfo().Assembly.Location); - - Console.WriteLine("Adding core references !!"); - List references = new List - { - MetadataReference.CreateFromFile(coreDir.FullName + Path.DirectorySeparatorChar + "mscorlib.dll"), - MetadataReference.CreateFromFile(coreDir.FullName + Path.DirectorySeparatorChar + "netstandard.dll"), - MetadataReference.CreateFromFile(typeof(object).GetTypeInfo().Assembly.Location), - MetadataReference.CreateFromFile(Assembly.GetEntryAssembly().Location), - MetadataReference.CreateFromFile(typeof(System.Runtime.Serialization.Json.DataContractJsonSerializer).GetTypeInfo().Assembly.Location) - }; - - Console.WriteLine("Adding parent assembly based references !!"); - foreach (var referencedAssembly in Assembly.GetEntryAssembly().GetReferencedAssemblies()) - { - var assembly = Assembly.Load(referencedAssembly); - references.Add(MetadataReference.CreateFromFile(assembly.Location)); - } - - #endregion - - #region load function specs based dlls - - Console.WriteLine($"going to get function specification..."); - //load all available dlls from deployment folder in dllinfo object - functionSpecification = EnvironmentHelper.Instance.GetFunctionSpecs(packagepath); - - Console.WriteLine($"going to get package dlls..."); - //iterate and all all libraries mentioned - foreach (var library in functionSpecification.libraries) - { - string dllCompletePath = Path.Combine(packagepath, library.path).GetrelevantPathAsPerOS(); - references.Add(MetadataReference.CreateFromFile(dllCompletePath)); - Console.WriteLine($"referred folder based dll : {dllCompletePath} from package {library.nugetPackage}"); - } - Console.WriteLine($"referred all available dlls!!"); - oinfo.Add("referred all available dlls!!"); - - #endregion - - #region dynamic resolve handler registration - AppDomain currentDomain = AppDomain.CurrentDomain; - currentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; - - #endregion - - #region function compile - - Console.WriteLine($"Trying to Compile"); - CSharpCompilation compilation = CSharpCompilation.Create( - assemblyName, - syntaxTrees: new[] { syntaxTree }, - references: references, - options: new CSharpCompilationOptions( - OutputKind.DynamicallyLinkedLibrary, - optimizationLevel: OptimizationLevel.Release)); - - using (var ms = new MemoryStream()) - { - EmitResult result = compilation.Emit(ms); - - if (!result.Success) - { - Console.WriteLine($"Compile Failed , see pod logs for more details"); - IEnumerable failures = result.Diagnostics.Where(diagnostic => - diagnostic.IsWarningAsError || - diagnostic.Severity == DiagnosticSeverity.Error).ToList(); - - foreach (Diagnostic diagnostic in failures) - { - errors.Add($"{diagnostic.Id}: {diagnostic.GetMessage()}"); - Console.WriteLine($"COMPILE ERROR :{diagnostic.Id}: {diagnostic.GetMessage()}", "ERROR"); - } - } - else - { - oinfo.Add("COMPILE SUCCESS!!"); - Console.WriteLine($"COMPILE SUCCESS!!"); - - ms.Seek(0, SeekOrigin.Begin); - - Assembly assembly = AssemblyLoadContext.Default.LoadFromStream(ms); - //var type = assembly.GetType("FissionFunction"); - //support for Namespace , as well as backward compatibility for existing functions - var type = assembly.GetTypes().FirstOrDefault(x => x.Name.EndsWith("FissionFunction")); - //assembly.GetTypes().Where(x=>x.Name.ToLower().EndsWith("FissionFunction".ToLower())).FirstOrDefault(); - var info = type.GetMember("Execute").First() as MethodInfo; - return new Function(assembly, type, info); - } - } - return null; - - #endregion - } - - private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) - { - //This handler is called only when the common language runtime tries to bind to the assembly and fails. - - Console.WriteLine($"Dynamically trying to load dll {(args.Name.Substring(0, args.Name.IndexOf(",")).ToString() + ".dll").ToLower()} in parent assembaly"); - - //Retrieve the list of referenced assemblies in an array of AssemblyName. - Assembly MyAssembly = null, objExecutingAssemblies; - string strTempAssmbPath_relative = "", strTempAssmbPath_absolute = ""; - - objExecutingAssemblies = Assembly.GetExecutingAssembly(); - AssemblyName[] arrReferencedAssmbNames = objExecutingAssemblies.GetReferencedAssemblies(); - - ////Loop through the array of referenced assembly names. - - //load all available dlls from deployment folder in dllinfo object - if (functionSpecification.libraries.Any(x => x.name.ToLower() == (args.Name.Substring(0, args.Name.IndexOf(",")).ToString() + ".dll").ToLower())) - { - strTempAssmbPath_relative = functionSpecification.libraries.Where(x => x.name.ToLower() == (args.Name.Substring(0, args.Name.IndexOf(",")).ToString() + ".dll").ToLower()).FirstOrDefault().path; - strTempAssmbPath_absolute = Path.Combine(packagepath, strTempAssmbPath_relative); - Console.WriteLine($"loading dll in parent assembly :{strTempAssmbPath_absolute.GetrelevantPathAsPerOS()}"); - //Load the assembly from the specified path. - MyAssembly = Assembly.LoadFile(strTempAssmbPath_absolute.GetrelevantPathAsPerOS()); - Console.WriteLine($"Load success for :{strTempAssmbPath_absolute.GetrelevantPathAsPerOS()}"); - } - - if (MyAssembly == null) - { - Console.WriteLine($"WARNING !!! unabel to locate dll :{(args.Name.Substring(0, args.Name.IndexOf(",")).ToString() + ".dll").ToLower()} ", "WARNING"); - } - //Return the loaded assembly. - return MyAssembly; - } - } -} diff --git a/environments/dotnet20/FissionContext.cs b/environments/dotnet20/FissionContext.cs deleted file mode 100644 index e31f6c4c..00000000 --- a/environments/dotnet20/FissionContext.cs +++ /dev/null @@ -1,130 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Security.Cryptography.X509Certificates; -using System.Text; -using Nancy; -using Newtonsoft.Json; - - -namespace Fission.DotNetCore.Api -{ - public class FissionContext - { - public string PackagePath { get; set; } - public FissionContext(Dictionary args, Logger logger, FissionHttpRequest request) - { - if (args == null) throw new ArgumentNullException(nameof(args)); - if (logger == null) throw new ArgumentNullException(nameof(logger)); - if (request == null) throw new ArgumentNullException(nameof(request)); - Arguments = args; - Logger = logger; - Request = request; - } - - public Dictionary Arguments { get; private set; } - - public FissionHttpRequest Request { get; private set; } - - public Logger Logger { get; private set; } - - public static FissionContext Build(Request request, Logger logger) - { - return new FissionContext(((DynamicDictionary)request.Query).ToDictionary(), - logger, - new FissionHttpRequest(request)); - } - //this is to support aditional setting file read from source/deployment package via function - public T GetSettings(string relativePath) - { - var filePath = Path.Combine(this.PackagePath, relativePath); - Console.WriteLine($"Going to Get Setting from :{filePath}"); - string json = GetSettingsJson(filePath); - return JsonConvert.DeserializeObject(json); - } - - private string GetSettingsJson(string relativePath) - { - return File.ReadAllText(Path.Combine(this.PackagePath, relativePath)); - } - } - - public class Logger - { - public void Write(Severity severity, string format, params object[] args) - { - Console.WriteLine($"{DateTime.Now.ToString("MM/dd/yy H:mm:ss zzz")} {severity}: " + format, args); - } - - public void WriteInfo(string format, params object[] args) - { - Write(Severity.Info, format, args); - } - - public void WriteWarning(string format, params object[] args) - { - Write(Severity.Warning, format, args); - } - - public void WriteError(string format, params object[] args) - { - Write(Severity.Error, format, args); - } - - public void WriteCritical(string format, params object[] args) - { - Write(Severity.Critical, format, args); - } - - public void WriteVerbose(string format, params object[] args) - { - Write(Severity.Verbose, format, args); - } - } - - public enum Severity - { - Info, - Warning, - Error, - Critical, - Verbose - } - - public class FissionHttpRequest - { - private readonly Request _request; - internal FissionHttpRequest(Request request) - { - if (request == null) throw new ArgumentNullException(nameof(request)); - _request = request; - } - - public Stream Body { get { return _request.Body; } } - - public string BodyAsString() - { - int length = (int)_request.Body.Length; - byte[] data = new byte[length]; - _request.Body.Read(data, 0, length); - return Encoding.UTF8.GetString(data); - } - - public Dictionary> Headers - { - get - { - var headers = new Dictionary>(); - foreach (var kv in _request.Headers) - { - headers.Add(kv.Key, kv.Value); - } - return headers; - } - } - - public X509Certificate Certificate { get { return _request.ClientCertificate; } } - public string Url { get { return _request.Url.ToString(); } } - public string Method { get { return _request.Method; } } - } -} diff --git a/environments/dotnet20/Function.cs b/environments/dotnet20/Function.cs deleted file mode 100644 index f8b5f724..00000000 --- a/environments/dotnet20/Function.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Reflection; -using Fission.DotNetCore.Api; - -namespace Fission.DotNetCore.Compiler -{ - class Function - { - private readonly Assembly _assembly; - private readonly Type _type; - private readonly MethodInfo _info; - - public Function(Assembly assembly, Type type, MethodInfo info) - { - if (info == null) throw new ArgumentNullException(nameof(info)); - if (assembly == null) throw new ArgumentNullException(nameof(assembly)); - if (type == null) throw new ArgumentNullException(nameof(type)); - _assembly = assembly; - _type = type; - _info = info; - } - - public object Invoke(FissionContext context) - { - return _info.Invoke(_assembly.CreateInstance(_type.FullName), new[] { context }); - } - } -} diff --git a/environments/dotnet20/Model/BuilderRequest.cs b/environments/dotnet20/Model/BuilderRequest.cs deleted file mode 100644 index bcaa6fc8..00000000 --- a/environments/dotnet20/Model/BuilderRequest.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Fission.DotNetCore.Model -{ - public class BuilderRequest - { - /// - /// this is folder path of deployment package which contains all deployment content copied to env - /// - public string filepath { get; set; } - public string functionName { get; set; } - public string url { get; set; } - public FunctionMetadata FunctionMetadata { get; set; } - } - public class FunctionMetadata - { - public string name { get; set; } - public string @namespace { get; set; } - public string selfLink { get; set; } - public string uid { get; set; } - public string resourceVersion { get; set; } - public int generation { get; set; } - public DateTime creationTimestamp { get; set; } - } -} diff --git a/environments/dotnet20/Model/DllInfo.cs b/environments/dotnet20/Model/DllInfo.cs deleted file mode 100644 index c5695b60..00000000 --- a/environments/dotnet20/Model/DllInfo.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Fission.DotNetCore.Model -{ - public class DllInfo - { - public string name { get; set; } - public string rootPackage { get; set; } - public string framework { get; set; } - - public string processor { get; set; } - public string path { get; set; } - } -} diff --git a/environments/dotnet20/Model/EnvironmentSettings.cs b/environments/dotnet20/Model/EnvironmentSettings.cs deleted file mode 100644 index 61c3acae..00000000 --- a/environments/dotnet20/Model/EnvironmentSettings.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Fission.DotNetCore.Model -{ - public class EnvironmentSettings - { - public string LogDirectory { get; set; } - - public string DllDirectory { get; set; } - public string functionBodyFileName { get; set; } - public string functionSpecFileName { get; set; } - public bool RunningOnwindows { get; set; } - } -} diff --git a/environments/dotnet20/Model/FunctionSpecification.cs b/environments/dotnet20/Model/FunctionSpecification.cs deleted file mode 100644 index a8bc58a4..00000000 --- a/environments/dotnet20/Model/FunctionSpecification.cs +++ /dev/null @@ -1,37 +0,0 @@ -using Fission.DotNetCore.Model; -using System; -using System.Collections.Generic; -using System.Text; - -namespace Fission.DotNetCore.Model -{ - public class FunctionSpecification - { - public FunctionSpecification() - { - this.libraries = new List(); - } - public string functionName { get; set; } - public List libraries { get; set; } - public string hash { get; set; } - public string certificatePath { get; set; } - } - public class Library - { - public Library() - { - - } - - public Library(DllInfo dllInfo) - { - this.name = dllInfo.name; - this.nugetPackage = dllInfo.rootPackage; - this.path = dllInfo.path; - } - public string name { get; set; } - //public string version { get; set; } - public string path { get; set; } - public string nugetPackage { get; set; } - } -} diff --git a/environments/dotnet20/Program.cs b/environments/dotnet20/Program.cs deleted file mode 100644 index 85dc1628..00000000 --- a/environments/dotnet20/Program.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.IO; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Nancy.Owin; - -namespace Fission.DotNetCore -{ - public class Program - { - public static void Main(string[] args) - { - var host = new WebHostBuilder() - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseKestrel() - .UseUrls("http://*:8888") - .Configure(app => app.UseOwin(x => x.UseNancy())) - .Build(); - host.Run(); - } - } -} diff --git a/environments/dotnet20/README.md b/environments/dotnet20/README.md deleted file mode 100644 index 191faec4..00000000 --- a/environments/dotnet20/README.md +++ /dev/null @@ -1,365 +0,0 @@ -# Fission: dotnet 2.0 C# Environment - -This is a simple dotnet core 2.0 C# environment for Fission. - -It's a Docker image containing the dotnet 2.0.0 runtime. The image -uses Kestrel with Nancy to host the internal web server and uses -Roslyn to compile the uploaded code. - -The image supports compiling and running code with types defined in -mscorlib and does not at present support other library references. -One workaround for this would be to add the references to this project's -project.json file and rebuild the container. - -The environment works via convention where you create a C# class -called FissionFunction which has a method named Execute taking a single -parameter, a FissionContext object. - -The FissionContext object gives access to the arguments and other items -like logging. Please see FissionContext.cs for public API. - -Example of simplest possible class to be executed: - -``` -using System; -using Fission.DotNetCore.Api; - -public class FissionFunction { - public string Execute(FissionContext context) { - return null; - } -} -``` - -Please see examples below, or if you are looking for ready-to-run examples, see -the [DotNet20 examples directory](../../examples/dotnet20). - -## Rebuilding and pushing the image - -To rebuild the image you will have to install Docker with version higher than 17.05+ -in order to support multi-stage builds feature. - -### Rebuild containers - -Move to the directory containing the source and start the container build process: - -``` -docker build -t USER/dotnet20-env . -``` - -After the build finishes push the new image to a Docker registry using the -standard procedure. - -## Echo example - -### Setup fission environment -First you need to setup the fission according to your cluster setup as -specified here: https://github.com/fission/fission - - -### Create the class to run - -Secondly you need to create a file /tmp/func.cs containing the following code: - -``` -using System; -using Fission.DotNetCore.Api; - -public class FissionFunction -{ - public string Execute(FissionContext context){ - context.Logger.WriteInfo("executing.. {0}", context.Arguments["text"]); - return (string)context.Arguments["text"]; - } -} -``` -### Run the example - -Lastly to run the example: - -``` -$ fission env create --name dotnet --image fission/dotnet20-env - -$ fission function create --name echo --env dotnet --code /tmp/func.cs - -$ fission route create --method GET --url /echo --function echo - -$ curl http://$FISSION_ROUTER/echo?text=hello%20world! - hello world -``` - -## Addition service example - -### Setup fission environment -First you need to setup the fission according to your cluster setup as -specified here: https://github.com/fission/fission - - -### Create the class to run - -Secondly you need to create a file /tmp/func.cs containing the following code: - -``` -using System; -using Fission.DotNetCore.Api; - -public class FissionFunction -{ - public string Execute(FissionContext context){ - var x = Convert.ToInt32(context.Arguments["x"]); - var y = Convert.ToInt32(context.Arguments["y"]); - return (x+y).ToString(); - } -} -``` -### Run the example - -Lastly to run the example: - -``` -$ fission env create --name dotnet --image fission/dotnet20-env - -$ fission function create --name addition --env dotnet --code /tmp/func.cs - -$ fission route create --method GET --url /add --function addition - -$ curl "http://$FISSION_ROUTER/add?x=30&y=12" - 42 -``` - -## Accessing http request information example - -### Setup fission environment -First you need to setup the fission according to your cluster setup as -specified here: https://github.com/fission/fission - - -### Create the class to run - -Secondly you need to create a file /tmp/func.cs containing the following code: - -``` -using System; -using Fission.DotNetCore.Api; - -public class FissionFunction -{ - public string Execute(FissionContext context){ - var buffer = new System.Text.StringBuilder(); - foreach(var header in context.Request.Headers){ - buffer.AppendLine(header.Key); - foreach(var item in header.Value){ - buffer.AppendLine($"\t{item}"); - } - } - buffer.AppendLine($"Url: {context.Request.Url}, method: {context.Request.Method}"); - return buffer.ToString(); - } -} - -``` -### Run the example - -Lastly to run the example: - -``` -$ fission env create --name dotnet --image fission/dotnet20-env - -$ fission function create --name httpinfo --env dotnet --code /tmp/func.cs - -$ fission route create --method GET --url /http_info --function httpinfo - -$ curl "http://$FISSION_ROUTER/http_info" -Accept - */*;q=1 -Host - fissionserver:8888 -User-Agent - curl/7.47.0 -Url: http://fissionserver:8888, method: GET - -``` - -## Accessing http request body example - -### Setup fission environment -First you need to setup the fission according to your cluster setup as -specified here: https://github.com/fission/fission - - -### Create the class to run - -Secondly you need to create a file /tmp/func.cs containing the following code: - -``` -using System.IO; -using System.Runtime.Serialization.Json; -using Fission.DotNetCore.Api; - -public class FissionFunction -{ - public string Execute(FissionContext context) - { - var person = Person.Deserialize(context.Request.Body); - return $"Hello, my name is {person.Name} and I am {person.Age} years old."; - } -} - -public class Person -{ - public string Name { get; set; } - public int Age { get; set; } - - public static Person Deserialize(Stream json) - { - var serializer = new DataContractJsonSerializer(typeof(Person)); - return (Person)serializer.ReadObject(json); - } -} - -``` -### Run the example - -Lastly to run the example: - -``` -$ fission env create --name dotnet --image fission/dotnet20-env - -$ fission function create --name httpbody --env dotnet --code /tmp/func.cs - -$ fission route create --method GET --url /http_body --function httpbody - -$ curl -XPOST "http://$FISSION_ROUTER/http_body" -d '{ "Name":"Arthur", "Age":42}' -Hello, my name is Arthur and I am 42 years old. - -``` - - -## Developing/debugging the environment locally - -The easiest way to debug the environment is to open the directory in -Visual Studio Code (VSCode) as that will setup debugger for you the -first time. - -Remember to install the excellent extension -"C# for Visual Studio Code(powered by OmniSharp)" to get statement completion - -The class ExecutorModule contain preprocessor directive overriding where -the input code file should be found: - -``` -#if DEBUG - private const string CODE_PATH = "/tmp/func.cs"; -#else - private const string CODE_PATH = "/userfunc/user"; -#endif -``` - -So what you need to do is: -1. Open the directory in VSCode. -This will prompt restore of packages and query is debugger setup is needed. Accept both prompts. -2. Press F5 to start the web server. Set breakpoints etc.. -3. Add a code file containing valid C# at /tmp/func.cs -4. Specialize the service with curl via post -``` -$ curl -XPOST http://localhost:8888/specialize -``` -5. Call your function with curl -``` -$ curl -XGET http://localhost:8888 -``` - -## Few Additional Features - -**1. NameSpace support :** - -Now , You can use namespace for Fission function class and have many other classes in same namespace , this is also backward compatible , however main execution class would always be *FissionFunction* and its method *Execute* - -``` - using System; - using Fission.DotNetCore.Api; - - - public class FissionFunction - { - public string Execute(FissionContext context){ - //original logic - } - public string AnotherClass(string myVal){ - //do something - } - } -``` - -**2. Additional **setting/configuration file** support :** - -Now , with Fission V2 end point with builder , in source package you can have additional setting -files which can be read by fission function . -Lets say you are writing a function and you need some configurable option and setting to be available in function and thus you want to use some additional configuration file , then you can also achieve the same by having a JSON based configuration file and a corresponding POCO Class for the same. - -Please use https://csharp2json.io/ & http://json2csharp.com/ to create correct POCO class for you JSON configuration file. - -Here is an example of a such file which we want to use in function , lets say your package.zip contains : - -``` - Source Package zip : - --source.zip - |--Func.cs - |--nuget.txt - |--exclude.txt - |--mysetting.json - |--....MiscFiles(optional) - |--....MiscFiles(optional) -``` - -here is what ***mysetting.json*** looks like : - -``` - { - "name": "Alpha", - "sendGridEndPoints": - [ - { "port": 1002 }, - { "port": 3004 } - ] - } -``` - -here is what ***func.cs*** looks like : - -``` -using System; -using Fission.DotNetCore.Api; - -namespace FuncNameSpace - { - public class FissionFunction - { - public string Execute(FissionContext context){ - string res="initial value"; - context.Logger.WriteInfo("Staring..... "); - var settings =context.GetSettings("mysetting.json"); - context.Logger.WriteInfo($"SendGridEndPoint port : {settings.SendGridEndPoints[0].port} ..... "); - res=settings.SendGridEndPoints[0].port; - context.Logger.WriteInfo("Done!!"); - return res; - } - } - - public class SendGridSettings - { - public string name { get; set; } - public System.Collections.Generic.List SendGridEndPoints { get; set; } - } - - public class SendGridEndPoint - { - public string port { get; set; } - } - } - -``` -**3. Nuget support :** - -with use of fission builder we can now add various compatible nugets with our deployment package so that it can be leverage via our function code. Please go through detailed documentation of [fission builder for dotnet 2.0 environment](https://github.com/fission/fission/tree/master/environments/dotnet20/builder). - \ No newline at end of file diff --git a/environments/dotnet20/Utility/EnvironmentExtension.cs b/environments/dotnet20/Utility/EnvironmentExtension.cs deleted file mode 100644 index c4967285..00000000 --- a/environments/dotnet20/Utility/EnvironmentExtension.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; - -namespace Fission.DotNetCore.Utilty -{ - public static class EnvironmentExtension - { - - public static IEnumerable DistinctBy( - this IEnumerable source, - Func keySelector) - { - var knownKeys = new HashSet(); - return source.Where(element => knownKeys.Add(keySelector(element))); - } - public static string GetrelevantPathAsPerOS(this string curruntPath) - { - if (EnvironmentHelper.Instance.environmentSettings.RunningOnwindows && curruntPath.Contains("\\")) - { - return curruntPath; - } - else - { - return curruntPath.Replace("\\", "/"); - } - } - } - - -} diff --git a/environments/dotnet20/Utility/EnvironmentHelper.cs b/environments/dotnet20/Utility/EnvironmentHelper.cs deleted file mode 100644 index e7af6105..00000000 --- a/environments/dotnet20/Utility/EnvironmentHelper.cs +++ /dev/null @@ -1,117 +0,0 @@ -using Fission.DotNetCore.Api; -using Fission.DotNetCore.Model; - -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Text; - -namespace Fission.DotNetCore.Utilty -{ - public sealed class EnvironmentHelper - { - private static readonly Lazy lazy = - new Lazy(() => new EnvironmentHelper()); - - public static EnvironmentHelper Instance { get { return lazy.Value; } } - - public EnvironmentSettings environmentSettings - { - get - { - if (_envSettings == null) - { - string watcherSettingsjson = GetEnvironmentSettingsJson(); - _envSettings = ObjectConverter.Instance.GetWatcherSettingsFromJson(watcherSettingsjson); - } - return _envSettings; - } - set - { - _envSettings = value; - } - } - - private EnvironmentSettings _envSettings; - - - static EnvironmentHelper() - { - } - private EnvironmentHelper() - { - } - - public void writeToFile(string msg) - { - - using (StreamWriter sw = new StreamWriter("main.log",true)) - { - sw.AutoFlush = true; - sw.WriteLine($"{DateTime.Now} : {msg}"); - - } - - } - - private string GetEnvironmentSettingsJson() - { - var baselocation = AppDomain.CurrentDomain.BaseDirectory; - var FileLocation = baselocation + "envsettings.json"; - - return File.ReadAllText(FileLocation); - } - - public BuilderRequest GetBuilderRequest(string json) - { - BuilderRequest builderRequest = new BuilderRequest(); - try - { - builderRequest = JsonConvert.DeserializeObject(json); - } - catch(Exception ex) - { - Console.WriteLine("Error : Unable to intersept request json " + ex.Message + ex.StackTrace); - } - - return builderRequest; - } - - public List GetDllInfoFromDirectory(string directorypath) - { - List dllInfos = new List(); - - Console.WriteLine($"finding dll in folder {directorypath}"); - DirectoryInfo d = new DirectoryInfo(directorypath);//Assuming packagepath is your Folder - var files = d.GetFiles("*.dll"); //Getting dll files - foreach(var file in files) - { - Console.WriteLine($"found dll {file.Name.ToLower()} at {Path.Combine(directorypath, file.Name)}"); - dllInfos.Add(new DllInfo() { - name = file.Name.ToLower(), - path = Path.Combine(directorypath, file.Name) - }); - } - - return dllInfos; - } - - public FunctionSpecification GetFunctionSpecs(string directorypath) - { - - string functionSpecsFilePath = Path.Combine(directorypath, this.environmentSettings.functionSpecFileName); - if (File.Exists(functionSpecsFilePath)) - { - string specsJson = File.ReadAllText(functionSpecsFilePath); - return ObjectConverter.Instance.GetFunctionSpecificationFromJson(specsJson); - } - else - throw new Exception($"Function Specification file not found at {functionSpecsFilePath}"); - - - } - } -} diff --git a/environments/dotnet20/Utility/ObjectConverter.cs b/environments/dotnet20/Utility/ObjectConverter.cs deleted file mode 100644 index 7d29c71f..00000000 --- a/environments/dotnet20/Utility/ObjectConverter.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Fission.DotNetCore.Model; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Text; - -namespace Fission.DotNetCore.Utilty -{ - public sealed class ObjectConverter - { - private static readonly Lazy lazy = - new Lazy(() => new ObjectConverter()); - - public static ObjectConverter Instance { get { return lazy.Value; } } - - private ObjectConverter() {} - - public EnvironmentSettings GetWatcherSettingsFromJson(string json) - { - return JsonConvert.DeserializeObject(json); - } - - public FunctionSpecification GetFunctionSpecificationFromJson(string json) - { - return JsonConvert.DeserializeObject(json); - } - } -} diff --git a/environments/dotnet20/builder/Builder.cs b/environments/dotnet20/builder/Builder.cs deleted file mode 100644 index bc34c453..00000000 --- a/environments/dotnet20/builder/Builder.cs +++ /dev/null @@ -1,55 +0,0 @@ -using Builder.Utility; -using NugetWorker; -using System; -using System.IO; -using Builder.Engine; - -namespace Builder -{ - class Builder - { - static void Main(string[] args) - { - Console.WriteLine("Builder Task Begins!"); - //create log file name for this session - var logFileName = $"{DateTime.Now.ToString("yyyy_MM_dd")}_{Guid.NewGuid().ToString()}.log"; - Console.WriteLine($"going to create logger!!"); - - try - { - string _logdirectory = BuilderHelper.Instance.builderSettings.BuildLogDirectory; - BuilderHelper.Instance._logFileName = Path.Combine(_logdirectory, logFileName); - BuilderHelper.Instance.logger = new Utility.Logger( - BuilderHelper.Instance._logFileName); - - //set the same for nuget engine dll - NugetHelper.Instance.logger = new NugetWorker.Logger(BuilderHelper.Instance._logFileName); - - Console.WriteLine($"detailed logs for this build will be at : {Path.Combine(_logdirectory, logFileName)}!!"); - - - BuilderEngine builderEngine = new BuilderEngine(); - builderEngine.BuildPackage().Wait(); - } - catch (Exception ex) - { - string detailedException = string.Empty; - try - { - detailedException= BuilderHelper.Instance.DeepException(ex); - Console.WriteLine($"Exception During Build : {Environment.NewLine} {ex.Message} | {ex.StackTrace} | {Environment.NewLine} {detailedException}"); - } - catch(Exception childEx) - { - //do nothing , just log original exception - Console.WriteLine($"{Environment.NewLine} Exception During Build :{ex.Message} |{Environment.NewLine} {ex.StackTrace} {Environment.NewLine} "); - } - - //now throw back exception so that build gets failed via builder - throw; - } - - Console.WriteLine("Builder Task Ends!"); - } - } -} diff --git a/environments/dotnet20/builder/Builder.csproj b/environments/dotnet20/builder/Builder.csproj deleted file mode 100644 index 1edf8dad..00000000 --- a/environments/dotnet20/builder/Builder.csproj +++ /dev/null @@ -1,40 +0,0 @@ - - - - Exe - netcoreapp2.0 - - - - - - - - - - - - - System - - - - - - Always - - - Always - - - Always - - - Always - - - Always - - - - diff --git a/environments/dotnet20/builder/Builder.sln b/environments/dotnet20/builder/Builder.sln deleted file mode 100644 index 14f4184d..00000000 --- a/environments/dotnet20/builder/Builder.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27906.1 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Builder", "Builder.csproj", "{D479FF57-44A0-483D-B5B0-B6C475D12292}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {D479FF57-44A0-483D-B5B0-B6C475D12292}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D479FF57-44A0-483D-B5B0-B6C475D12292}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D479FF57-44A0-483D-B5B0-B6C475D12292}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D479FF57-44A0-483D-B5B0-B6C475D12292}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {AA20D0B8-E5D5-4BA1-9E29-FC5132A4DD00} - EndGlobalSection -EndGlobal diff --git a/environments/dotnet20/builder/BuilderEngine/BuilderEngine.cs b/environments/dotnet20/builder/BuilderEngine/BuilderEngine.cs deleted file mode 100644 index 78dd07b0..00000000 --- a/environments/dotnet20/builder/BuilderEngine/BuilderEngine.cs +++ /dev/null @@ -1,306 +0,0 @@ -using Builder.Model; -using Builder.Utility; -using NugetWorker; -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; -using System.Linq; -using NuGet.Packaging; -using System.IO; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using System.Reflection; -using Microsoft.CodeAnalysis.Emit; -using System.Runtime.Loader; -using Newtonsoft.Json; - -namespace Builder.Engine -{ - public class BuilderEngine - { - public string SRC_PKG = string.Empty; - public string DEPLOY_PKG = string.Empty; - - List dllInfos = new List(); - List excludeDlls = new List(); - List includeNugets = new List(); - List compile_errors = new List(); - List compile_info = new List(); - - public BuilderEngine() - { - SRC_PKG = Environment.GetEnvironmentVariable("SRC_PKG"); - DEPLOY_PKG = Environment.GetEnvironmentVariable("DEPLOY_PKG"); - } - - - public async Task BuildPackage() - { - await BuildDllInfo(); - - Console.WriteLine("DLL Info Gathered!!"); - // try to compile the function and if compilation succeed ,then create func spec file - //this enables us to find compilation issues during package creation itself thus saving time - // however this feature impose that the function file name should be func.cs - //if we don't want it , we can comment the TryCompile() logic - Console.WriteLine("Trying to compile it during build itself !!"); - bool compiled =await TryCompile(); - Console.WriteLine($"Compilation result Gathered as : {compiled}!!"); - if (compiled) - { - - //nowwhatever has been done so far and all files which are generated are in /app folder where dll resides - //thus copy relevant thing in SRC_PKG as it is ,but lest skip it here , we shall do it in build.sh - CopyToSourceDir(); - Console.WriteLine($"Copy to Source Done!!"); - //build the function specs - await BuildSpecs(); - Console.WriteLine("BuildSpecs Done!!"); - } - else - { - Console.WriteLine("Compilation failed , throwing exception !!"); - foreach(var error in compile_errors) - { - Console.WriteLine($"COMPILATION ERROR : {error}"); - } - throw new Exception($"COMPILATION FAILED !! , See builder logs for details , total Errors : {compile_errors.Count}"); - - } - - } - - public void CopyToSourceDir() - { - //to create folder if it doesnt already exists - string destinationFile=Path.Combine(SRC_PKG, BuilderHelper.Instance.builderSettings.DllDirectory, "dummy.txt"); - new FileInfo(destinationFile).Directory.Create(); - - - //copy all dlls - foreach (var dllinfo in dllInfos) - { - string filename = Path.GetFileName(dllinfo.path); - destinationFile = Path.Combine(SRC_PKG, BuilderHelper.Instance.builderSettings.DllDirectory, filename); - File.Copy(dllinfo.path, destinationFile,true); - } - - - //copy logs , well there is not point as logs are still being generated - - //create dir if not exist - //new FileInfo(Path.Combine(SRC_PKG, BuilderHelper.Instance._logFileName)).Directory.Create(); - - //File.Copy(BuilderHelper.Instance._logFileName, Path.Combine(SRC_PKG, BuilderHelper.Instance._logFileName)); - //BuilderHelper.Instance.logger.Log($"All Required Files copied to {SRC_PKG}"); - } - - public async Task TryCompile() - { - bool isSuccess = false; - - string CODE_PATH = Path.Combine(SRC_PKG, BuilderHelper.Instance.builderSettings.functionBodyFileName); - if (!File.Exists(CODE_PATH)) - { - Console.WriteLine($"Source Code not found at : {CODE_PATH} !" + - $" to use TryCompile() in Builder, make sure , your main function file name is " + - $"{BuilderHelper.Instance.builderSettings.functionBodyFileName} and " + - $"it is located at root of zip!!" ); - return isSuccess; - } - - var code = File.ReadAllText(CODE_PATH); - isSuccess = await Compile(code); - - return isSuccess; - } - - public async Task Compile(string code) - { - bool isSuccess = false; - - #region assembly init and parent dll references - SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(code); - string assemblyName = Path.GetRandomFileName(); - - var coreDir = Directory.GetParent(typeof(Enumerable).GetTypeInfo().Assembly.Location); - - List references = new List - { - MetadataReference.CreateFromFile(coreDir.FullName + Path.DirectorySeparatorChar + "mscorlib.dll"), - MetadataReference.CreateFromFile(coreDir.FullName + Path.DirectorySeparatorChar + "netstandard.dll"), - MetadataReference.CreateFromFile(typeof(object).GetTypeInfo().Assembly.Location), - MetadataReference.CreateFromFile(Assembly.GetEntryAssembly().Location), - MetadataReference.CreateFromFile(typeof(System.Runtime.Serialization.Json.DataContractJsonSerializer).GetTypeInfo().Assembly.Location) - }; - - foreach (var referencedAssembly in Assembly.GetEntryAssembly().GetReferencedAssemblies()) - { - var assembly = Assembly.Load(referencedAssembly); - references.Add(MetadataReference.CreateFromFile(assembly.Location)); - BuilderHelper.Instance.logger.Log($"Refering assembly based dls : {assembly.Location}"); - } - - #endregion - - #region handler registration for runtime resolution - //now add handler for missing dlls for parent app domain as same assemblies should be needed - //for parent , thus refering from https://support.microsoft.com/en-in/help/837908/how-to-load-an-assembly-at-runtime-that-is-located-in-a-folder-that-is - AppDomain currentDomain = AppDomain.CurrentDomain; - currentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; - - #endregion - - BuilderHelper.Instance.logger.Log($"dynamic handlar registered!!"); - #region nuget dll reference add - //now add those dll reference - foreach (var dll in dllInfos) - { - BuilderHelper.Instance.logger.Log($"refering nuget based dll : {dll.path}"); - references.Add(MetadataReference.CreateFromFile(dll.path)); - } - - #endregion - - #region compilation - - CSharpCompilation compilation = CSharpCompilation.Create( - assemblyName, - syntaxTrees: new[] { syntaxTree }, - references: references, - options: new CSharpCompilationOptions( - OutputKind.DynamicallyLinkedLibrary, - optimizationLevel: OptimizationLevel.Release)); - - using (var ms = new MemoryStream()) - { - EmitResult result = compilation.Emit(ms); - - if (!result.Success) - { - BuilderHelper.Instance.logger.Log($"Compile Failed!!!!",true); - IEnumerable failures = result.Diagnostics.Where(diagnostic => - diagnostic.IsWarningAsError || - diagnostic.Severity == DiagnosticSeverity.Error).ToList(); - - foreach (Diagnostic diagnostic in failures) - { - compile_errors.Add($"{diagnostic.Id}: {diagnostic.GetMessage()}"); - BuilderHelper.Instance.logger.Log($"COMPILE ERROR :{diagnostic.Id}: {diagnostic.GetMessage()}"); - } - } - else - { - BuilderHelper.Instance.logger.Log("Compile Success!!",true); - isSuccess = true; - } - } - - #endregion - return isSuccess; - - } - - public async Task BuildSpecs() - { - //create function specs C# object - FunctionSpecification functionSpecification = new FunctionSpecification(); - - functionSpecification.functionName = BuilderHelper.Instance.builderSettings.functionBodyFileName; - - foreach (var dllinfo in dllInfos) - { - //here is the tweak , as this path is based on execution directoy , thus choose the relative path - string destinationFile = Path.Combine(BuilderHelper.Instance.builderSettings.DllDirectory, Path.GetFileName(dllinfo.path)).GetrelevantPathAsPerOS(); - - Library library = new Library() - { - name=dllinfo.name, - nugetPackage=dllinfo.rootPackage, - path = destinationFile - }; - functionSpecification.libraries.Add(library); - } - - //serialize that object to save it in json file - string funcMetaJson= JsonConvert.SerializeObject(functionSpecification); - - string funcMetaFile = Path.Combine(this.SRC_PKG, BuilderHelper.Instance.builderSettings.functionSpecFileName); - BuilderHelper.Instance.WriteTofile(funcMetaFile, funcMetaJson); - - } - - public async Task BuildDllInfo() - { - //read the nuget file and download nuget packages - includeNugets = BuilderHelper.Instance.GetNugettoInclude(SRC_PKG); - //set the nuget logger to same logger - - - foreach (var nuget in includeNugets) - { - NugetEngine nugetEngine = new NugetEngine(); - await nugetEngine.GetPackage(nuget.packageName, nuget.version); - - //add the list of dlls received via this package in master list - dllInfos.AddRange(nugetEngine.dllInfos); - } - - //now do a distinct of all dlls paths as multiple packaged might have added same dll - dllInfos = dllInfos.DistinctBy(x => x.path).ToList(); - -#if DEBUG - dllInfos.LogDllPathstoCSV("preFilter.CSV"); -#endif - - //exclude the dlls from exclude file - excludeDlls = BuilderHelper.Instance.GetDllstoExclude(SRC_PKG); - foreach (var excludedll in excludeDlls) - { - BuilderHelper.Instance.logger.Log($"trying to remove , if available : {excludedll.dllName} from package {excludedll.packageName}"); - dllInfos.RemoveAll(x => x.rootPackage.ToLower() == excludedll.packageName.ToLower() && x.name.ToLower() == excludedll.dllName.ToLower()); - } - -#if DEBUG - //log dlls in debug mode - dllInfos.LogDllPathstoCSV("PostFilter.CSV"); -#endif - - } - - private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) - { - //This handler is called only when the common language runtime tries to bind to the assembly and fails. - - BuilderHelper.Instance.logger.Log($"Dynamically trying to load dll {(args.Name.Substring(0, args.Name.IndexOf(",")).ToString() + ".dll").ToLower()} in parent assembaly"); - - //Retrieve the list of referenced assemblies in an array of AssemblyName. - Assembly MyAssembly = null, objExecutingAssemblies; - string strTempAssmbPath = ""; - - objExecutingAssemblies = Assembly.GetExecutingAssembly(); - AssemblyName[] arrReferencedAssmbNames = objExecutingAssemblies.GetReferencedAssemblies(); - - ////Loop through the array of referenced assembly names. - - if (dllInfos.Any(x => x.name.ToLower() == (args.Name.Substring(0, args.Name.IndexOf(",")).ToString() + ".dll").ToLower())) - { - strTempAssmbPath = dllInfos.Where(x => x.name.ToLower() == (args.Name.Substring(0, args.Name.IndexOf(",")).ToString() + ".dll").ToLower()).FirstOrDefault().path; - - BuilderHelper.Instance.logger.Log($"loading dll in parent :{strTempAssmbPath}"); - - //Load the assembly from the specified path. - MyAssembly = Assembly.LoadFile(strTempAssmbPath); - } - - if (MyAssembly == null) - { - BuilderHelper.Instance.logger.Log($"WARNING !!! unabel to locate dll :{(args.Name.Substring(0, args.Name.IndexOf(",")).ToString() + ".dll").ToLower()} ", true); - } - //Return the loaded assembly. - return MyAssembly; - } - - } -} diff --git a/environments/dotnet20/builder/Dockerfile b/environments/dotnet20/builder/Dockerfile deleted file mode 100644 index e187c460..00000000 --- a/environments/dotnet20/builder/Dockerfile +++ /dev/null @@ -1,37 +0,0 @@ -ARG BUILDER_IMAGE=fission/builder -FROM ${BUILDER_IMAGE} AS fission-builder - - -FROM microsoft/dotnet:2.0.0-sdk AS builderimage - - -WORKDIR /app - -# Copy csproj and restore as distinct layers -COPY *.csproj ./ -RUN dotnet restore - -# Copy everything else and build -COPY . ./ -RUN dotnet publish -c Release -o out - - -# Build runtime image -FROM microsoft/dotnet:aspnetcore-runtime -WORKDIR /app -COPY --from=builderimage /app/out . - -# this builder is actually compilation from : https://github.com/fission/fission/tree/master/builder/cmd and renamed cmd.exe to builder -# make sure to compile it in linux only else you will get exec execute error as binary was compiled in windows and running on linux - -COPY --from=fission-builder /builder /builder - -# ADD builder /builder - -ADD build.sh /usr/local/bin/build -RUN chmod +x /usr/local/bin/build - -ADD build.sh /bin/build -RUN chmod +x /bin/build - -EXPOSE 8001 diff --git a/environments/dotnet20/builder/Model/BuilderSettings.cs b/environments/dotnet20/builder/Model/BuilderSettings.cs deleted file mode 100644 index f5f13c05..00000000 --- a/environments/dotnet20/builder/Model/BuilderSettings.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Builder.Model -{ - public class BuilderSettings - { - public string NugetSpecsFile { get; set; } - public string DllExcludeFile { get; set; } - public string BuildLogDirectory { get; set; } - public string NugetPackageRegEx { get; set; } - public string ExcludeDllRegEx { get; set; } - public bool RunningOnwindows { get; set; } - public string functionBodyFileName { get; set; } - public string functionSpecFileName { get; set; } - public string DllDirectory { get; set; } - } -} diff --git a/environments/dotnet20/builder/Model/ExcludeDll.cs b/environments/dotnet20/builder/Model/ExcludeDll.cs deleted file mode 100644 index cb67c801..00000000 --- a/environments/dotnet20/builder/Model/ExcludeDll.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Builder.Model -{ - public class ExcludeDll - { - public string dllName { get; set; } - public string packageName { get; set; } - } -} diff --git a/environments/dotnet20/builder/Model/FissionContext.cs b/environments/dotnet20/builder/Model/FissionContext.cs deleted file mode 100644 index 0dfaceba..00000000 --- a/environments/dotnet20/builder/Model/FissionContext.cs +++ /dev/null @@ -1,137 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Security.Cryptography.X509Certificates; -using System.Text; -using Nancy; -using Newtonsoft.Json; - - -namespace Fission.DotNetCore.Api -{ - public class FissionContext - { - public FissionContext(Dictionary args, Logger logger, FissionHttpRequest request) - { - if (args == null) throw new ArgumentNullException(nameof(args)); - if (logger == null) throw new ArgumentNullException(nameof(logger)); - if (request == null) throw new ArgumentNullException(nameof(request)); - Arguments = args; - Logger = logger; - Request = request; - } - - public Dictionary Arguments { get; private set; } - - public FissionHttpRequest Request { get; private set; } - - public Logger Logger { get; private set; } - - public static FissionContext Build(Request request, Logger logger) - { - return new FissionContext(((DynamicDictionary)request.Query).ToDictionary(), - logger, - new FissionHttpRequest(request)); - } - - //this is a dummy, not being implemented, just to pass compilation - //actual execution is written in environment to use the app settings as there we need it - public T GetSettings(string relativePath) - { - //intentionally doing it as these are just dummy methods not being called - //but if tomorrow if we decide to give implementation for execution in build then we - //need to implement it - throw new NotImplementedException(); - } - - //this is a dummy, not being implemented, just to pass compilation - //actual execution is written in environment to use the app settings as there we need it - private string GetSettingsJson(string relativePath) - { - //intentionally doing it as these are just dummy methods not being called - //but tomorrow if we decide to give implementation for execution in build then we - //need to implement it - throw new NotImplementedException(); - } - - } - - public class Logger - { - public void Write(Severity severity, string format, params object[] args) - { - Console.WriteLine($"{DateTime.Now.ToString("MM/dd/yy H:mm:ss zzz")} {severity}: " + format, args); - } - - public void WriteInfo(string format, params object[] args) - { - Write(Severity.Info, format, args); - } - - public void WriteWarning(string format, params object[] args) - { - Write(Severity.Warning, format, args); - } - - public void WriteError(string format, params object[] args) - { - Write(Severity.Error, format, args); - } - - public void WriteCritical(string format, params object[] args) - { - Write(Severity.Critical, format, args); - } - - public void WriteVerbose(string format, params object[] args) - { - Write(Severity.Verbose, format, args); - } - } - - public enum Severity - { - Info, - Warning, - Error, - Critical, - Verbose - } - - public class FissionHttpRequest - { - private readonly Request _request; - internal FissionHttpRequest(Request request) - { - if (request == null) throw new ArgumentNullException(nameof(request)); - _request = request; - } - - public Stream Body { get { return _request.Body; } } - - public string BodyAsString() - { - int length = (int)_request.Body.Length; - byte[] data = new byte[length]; - _request.Body.Read(data, 0, length); - return Encoding.UTF8.GetString(data); - } - - public Dictionary> Headers - { - get - { - var headers = new Dictionary>(); - foreach (var kv in _request.Headers) - { - headers.Add(kv.Key, kv.Value); - } - return headers; - } - } - - public X509Certificate Certificate { get { return _request.ClientCertificate; } } - public string Url { get { return _request.Url.ToString(); } } - public string Method { get { return _request.Method; } } - } -} diff --git a/environments/dotnet20/builder/Model/FunctionSpecification.cs b/environments/dotnet20/builder/Model/FunctionSpecification.cs deleted file mode 100644 index 1ff29b73..00000000 --- a/environments/dotnet20/builder/Model/FunctionSpecification.cs +++ /dev/null @@ -1,40 +0,0 @@ -using NugetWorker; -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - -namespace Builder.Model -{ - public class FunctionSpecification - { - public FunctionSpecification() - { - this.libraries = new List(); - } - public string functionName { get; set; } - public List libraries { get; set; } - public string hash { get; set; } - public string certificatePath { get; set; } - } - - - public class Library - { - public Library() - { - - } - - public Library(DllInfo dllInfo) - { - this.name = dllInfo.name; - this.nugetPackage = dllInfo.rootPackage; - this.path = dllInfo.path; - } - public string name { get; set; } - //public string version { get; set; } - public string path { get; set; } - public string nugetPackage { get; set; } - } -} diff --git a/environments/dotnet20/builder/Model/IncludeNuget.cs b/environments/dotnet20/builder/Model/IncludeNuget.cs deleted file mode 100644 index 7fc960d6..00000000 --- a/environments/dotnet20/builder/Model/IncludeNuget.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Builder.Model -{ - public class IncludeNuget - { - public string packageName { get; set; } - public string version { get; set; } - } -} diff --git a/environments/dotnet20/builder/README.md b/environments/dotnet20/builder/README.md deleted file mode 100644 index 777c7c63..00000000 --- a/environments/dotnet20/builder/README.md +++ /dev/null @@ -1,175 +0,0 @@ -# Fission: dotnet 2.0 C# Environment Builder - -This is a simple dotnet core 2.0 C# environment builder for Fission. - -It's a docker image containing the dotnet 2.0.0 (core) run-time builder. This image read the source package and uses -*roslyn* to compile the source package code and creates deployment package out of it. -This enables using nuget packages as part of function and thus user can use extended functionality in fission functions via nuget. - -During build , builder also does a pre-compile to prevent any compilation issues during function environment pod specialization. -Thus we get the function compilation issues during builder phase in package info's build logs itself. - -**Note** : In future we can further enhance the compiled assembly to be saved as physical file in deployment package , -as this will save cold start time for function. - -Now , once after the build is finished, the output package (deploy archive) will be uploaded to storagesvc to store. -Then, during the specialization, the fetcher inside function pod will fetch the package from storagesvc for function loading - and will call on the **/v2/specialized** endpoint of fission environment with required parameters. - -There further environment will compile it and execute the function. - - -Example of simplest possible class to be executed: - -The source package structure in zip file : - -``` - Source Package zip : - --source.zip - |--func.cs - |--nuget.txt - |--exclude.txt - |--....MiscFiles(optional) - |--....MiscFiles(optional) -``` - -**func.cs** --> This contains original function body with Executing method name as : Execute - - -**nuget.txt**--> this file contains list of nuget packages required by your function , in this file put one line per nuget with nugetpackage name:version(optional) format, for example : - -``` -RestSharp -CsvHelper -Newtonsoft.json:10.2.1.0 -``` - - - this should match the following regex as mentioned in builderSetting.json -``` -"NugetPackageRegEx": "\\:?\\s*(?[^:\\n]*)(?:\\:)?(?.*)?" -``` - - - **exclude.txt**--> as nuget.txt will download original package and their dependent packages , thus sometime dependent packages might not be -that useful and can break compilation , thus this file contains list of dlls of specific nuget packages which doesn't need to be added during compilation if they break compilation .Put one line per nuget with dllname:nugetpackagename formate ,for example : - -``` -Newtonsoft.json:Newtonsoft.json.dll -``` -this should match the following regex as mentions in builderSetting.json - - -``` -"ExcludeDllRegEx": "\\:?\\s*(?[^:\\n]*)(?:\\:)?(?.*)?", -``` - From above , builder will create a deployment package with all dlls in a folder and one function specification file : - Deployment Package zip : - -``` - --Deploye.zip - |--func.cs - |--nuget.txt - |--exclude.txt - |--dll() - |--newtonsoft.json.dll - |--restsharp.dll - |--csvhelper.dll - |--logs() - |-->logFileName - |--func.meta.json // this is the function specific file - |--....MiscFiles(optional) - |--....MiscFiles(optional) -``` -Here are commands and detailed example for the same . - -lets say my source package zip name is *funccsv.zip* : - -**Content of func.cs:** -``` -using System; -using Fission.DotNetCore.Api; - -public class FissionFunction -{ - public string Execute(FissionContext context){ - string res="initial value"; - try - { - context.Logger.WriteInfo("Staring..... "); - res=$" sample object by getting Enum of CsvHelper nuget dll: { CsvHelper.Caches.NamedIndex.ToString()}"; - } - catch(Exception ex) - { - context.Logger.WriteError(ex.Message); - res = ex.Message; - } - context.Logger.WriteInfo("Done!"); - return res; - } -} -``` - -**Content of *nuget.txt*** -``` -CsvHelper -``` -**Content of exclude.txt** - -As we don't want to exclude any specific dll thus we shall leave it as empty. - -Now check name of existing environments & functions as we want to create a unique environment for this .Net Core if not already present - -``` -fission env list -fission fn list - ``` - Create Environment with builder (choose a unique which doesn't exist , here we have chosen : dotnetcorewithnuget ) - also suppose the builder image name is fissiondotnet20-builder and hosted on Docker Hub as fission/dotnet20-builder - ``` -fission environment create --name dotnetcorewithnuget --image fission/dotnet20-env --builder fission/dotnet20-builder - ``` - Verify fission-builder and fission-function namespace for new pods (pods name beginning with env name which we have given like *dotnetcorewithnuget-xxx-xxx*) - ``` -kubectl get pods -n fission-builder -kubectl get pods -n fission-function - ``` -Create Package from source zip using this environment name , this will output some package name created.. - ``` -fission package create --src funccsv.zip --env dotnetcorewithnuget - ``` - Note down output package name lets say it is *funccsv-zip-xyz* now check its status using package info command , this will give the status - on what happened with builder and test compilation in builder. - - ``` -fission package info --name funccsv-zip-xyz -``` - -#Status of package should be f*ailed / running / succeeded* . - Wait if the status is running , until it fails or succeeded. For detailed build logs, you can shell into builder pod in fission-builder namespace and verify log location mentioned in above command's result output. - -**Note** : Even If the result is succeeded , please have a look at detailed build logs to see compilation success and builder job done. - -Now If the result is succeeded , then go ahead and create function using this package. - -*--entrypoint* flag is optional if your function body file name is func.cs (which it should be as builder need that), else put the filename (without extension ) - ``` - fission fn create --name dotnetcsvtest --pkg funccsv-zip-xyz --env dotnetcorewithnuget --entrypoint "func" - ``` -Test the function execution : - -``` - fission fn test --name dotnetcsvtest -``` -above would execute the function and will output the enum value as written in dll. -rest of the feature are same as normal fission environment. - -**Benefit of using builder** : - -1. Ability to use various nuget packages. -2. Ability to use many additional files and functions as part of deployment package. -3. Ability to know the compilation issue in advance via package logs , instead of environment giving compilation issue. -4. Reusability of same deployment package. - - - diff --git a/environments/dotnet20/builder/Utility/BuilderExtensions.cs b/environments/dotnet20/builder/Utility/BuilderExtensions.cs deleted file mode 100644 index 18cff1ff..00000000 --- a/environments/dotnet20/builder/Utility/BuilderExtensions.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Builder.Utility -{ - public static class BuilderExtensions - { - public static string GetrelevantPathAsPerOS(this string curruntPath) - { - if (BuilderHelper.Instance.builderSettings.RunningOnwindows) - { - return curruntPath; - } - else - { - return curruntPath.Replace("\\","/"); - } - } - } -} diff --git a/environments/dotnet20/builder/Utility/BuilderHelper.cs b/environments/dotnet20/builder/Utility/BuilderHelper.cs deleted file mode 100644 index f91d0077..00000000 --- a/environments/dotnet20/builder/Utility/BuilderHelper.cs +++ /dev/null @@ -1,180 +0,0 @@ -using Builder.Model; -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; -using System.Text.RegularExpressions; - -namespace Builder.Utility -{ - - public sealed class BuilderHelper - { - - private static readonly Lazy lazy = - new Lazy(() => new BuilderHelper()); - - public string _logFileName = string.Empty; - public static BuilderHelper Instance { get { return lazy.Value; } } - - private static Logger _logger = new Logger("Initial.log"); - - private BuilderSettings _builderSettings = null; - - public BuilderSettings builderSettings - { - get - { - if (_builderSettings == null) - { - string builderSettingsjson = GetBuilderSettingsJson(); - _builderSettings = ObjectConverter.Instance.GetBuilderSettingsFromJson(builderSettingsjson); - } - return _builderSettings; - } - set - { - builderSettings = value; - } - } - - public Logger logger - { - get - { - return _logger; - } - set - { - _logger = value; - } - } - - static BuilderHelper() - { - } - private BuilderHelper() - { - } - - private string GetBuilderSettingsJson() - { - var baselocation = AppDomain.CurrentDomain.BaseDirectory; - var FileLocation = baselocation + "builderSettings.json"; - - return File.ReadAllText(FileLocation); - } - - - public List GetNugettoInclude(string directoryPath) - { - List includeNugets = new List(); - string includeNugetsFilePath = Path.Combine(directoryPath, this.builderSettings.NugetSpecsFile); - if (File.Exists(includeNugetsFilePath)) - { - Regex _pkgName = new Regex(this.builderSettings.NugetPackageRegEx, - RegexOptions.Compiled); - - string filetext = File.ReadAllText(includeNugetsFilePath); - var _pkgMatchCollection = _pkgName.Matches(filetext); - - foreach (Match match in _pkgMatchCollection) - { - if(!string.IsNullOrWhiteSpace(match.Value)) - { - string package = match.Groups["package"]?.Value?.Trim(); - string version = match.Groups["version"]?.Value?.Trim(); - this.logger.Log($"adding {package} | {version} to includeNugets collection"); - - includeNugets.Add( - new IncludeNuget() - { - packageName = package, - version = version - } - ); - } - - } - } - - return includeNugets; - } - public List GetDllstoExclude(string directoryPath) - { - List excludeDlls = new List(); - string excludeDllsFilePath = Path.Combine(directoryPath, this.builderSettings.DllExcludeFile); - if (File.Exists(excludeDllsFilePath)) - { - //xyzPackage:abc.dll - Regex _exclude = new Regex(this.builderSettings.ExcludeDllRegEx, - RegexOptions.Compiled); - - string filetext = File.ReadAllText(excludeDllsFilePath); - var _excludeMatchCollection = _exclude.Matches(filetext); - - foreach (Match match in _excludeMatchCollection) - { - if (!string.IsNullOrWhiteSpace(match.Value)) - { - string _package = match.Groups["package"]?.Value?.Trim(); - string _dllName = match.Groups["dll"]?.Value?.Trim(); - this.logger.Log($"adding {_package} | {_dllName} to excludeDlls collection"); - - excludeDlls.Add( - new ExcludeDll() - { - packageName = _package, - dllName = _dllName - } - ); - } - } - } - - return excludeDlls; - } - - public string DeepException(Exception ex) - { - string responce = string.Empty; - - responce = " Exception : LEVEL 1: " + Environment.NewLine + ex.Message; - if (ex.InnerException != null) - { - responce = responce + Environment.NewLine + "LEVEL 2:" + Environment.NewLine + ex.InnerException.Message; - if (ex.InnerException.InnerException != null) - { - responce =responce + Environment.NewLine + "LEVEL 3:" + Environment.NewLine + ex.InnerException.InnerException.Message; - - if (ex.InnerException.InnerException.InnerException != null) - { - responce = responce + Environment.NewLine + "LEVEL 4:" + Environment.NewLine + ex.InnerException.InnerException.InnerException.Message; - if (ex.InnerException.InnerException.InnerException.InnerException != null) - { - responce = responce + Environment.NewLine + "LEVEL 5:" + Environment.NewLine + ex.InnerException.InnerException.InnerException.InnerException.Message; - } - } - } - } - - if(ex.StackTrace!=null) - { - responce = responce + "|| STACK :"+ ex.StackTrace; - } - return responce; - - - } - - public void WriteTofile(string filenameWithPath , string content) - { - using (StreamWriter sw = new StreamWriter(filenameWithPath, false)) - { - sw.AutoFlush = true; - sw.Write(content); - } - - } - } -} diff --git a/environments/dotnet20/builder/Utility/Logger.cs b/environments/dotnet20/builder/Utility/Logger.cs deleted file mode 100644 index 19fddd1c..00000000 --- a/environments/dotnet20/builder/Utility/Logger.cs +++ /dev/null @@ -1,111 +0,0 @@ -using log4net; -using NuGet.Common; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; -using System.Xml; - -namespace Builder.Utility -{ - public class Logger : NuGet.Common.ILogger - { - private ILog _ILog { get; set; } - public Logger(string logpath) - { - - //read the log4net config and create logger instance form log4net - XmlDocument ConfigLoader = new XmlDocument(); - ConfigLoader.Load(File.OpenRead("log4net.config")); - var repo = LogManager.CreateRepository(Assembly.GetEntryAssembly(), - typeof(log4net.Repository.Hierarchy.Hierarchy)); - log4net.Config.XmlConfigurator.Configure(repo, ConfigLoader["log4net"]); - - var appender = ((log4net.Appender.FileAppender)repo.GetAppenders().Where(x => x.Name == "RollingLogFileAppender").FirstOrDefault()); - appender.File = logpath;// $"directoryPath/{DateTime.Now.ToString("yyyy_MM_dd")}_{Guid.NewGuid().ToString()}_.log"; - - appender.ActivateOptions(); - _ILog = LogManager.GetLogger(typeof(Logger)); - } - - public void Log(string message,bool logToConsoleAsWell=false) - { - if(logToConsoleAsWell) - Console.WriteLine(message); - - _ILog.Info(message); - } - - public void Log(LogLevel level, string data) - { - //Console.WriteLine(data); - _ILog.Info(data); - } - - public void Log(ILogMessage message) - { - //Console.WriteLine(message); - _ILog.Info(message.Message); - } - - public Task LogAsync(LogLevel level, string data) - { - //Console.WriteLine(data); - _ILog.Info(data); - return null; - } - - public Task LogAsync(ILogMessage message) - { - //Console.WriteLine(message); - _ILog.Info(message.Message); - return null; - } - - public void LogDebug(string data) - { - //Console.WriteLine(data); - _ILog.Debug(data); - - } - - public void LogError(string data) - { - //Console.WriteLine(data); - _ILog.Error(data); - } - - public void LogInformation(string data) - { - //Console.WriteLine(data); - _ILog.Info(data); - } - - public void LogInformationSummary(string data) - { - //Console.WriteLine(data); - _ILog.Info(data); - } - - public void LogMinimal(string data) - { - //Console.WriteLine(data); - _ILog.Info(data); - } - - public void LogVerbose(string data) - { - //Console.WriteLine(data); - _ILog.Debug(data); - } - - public void LogWarning(string data) - { - //Console.WriteLine(data); - _ILog.Warn(data); - } - } -} diff --git a/environments/dotnet20/builder/Utility/ObjectConverter.cs b/environments/dotnet20/builder/Utility/ObjectConverter.cs deleted file mode 100644 index 03ffb113..00000000 --- a/environments/dotnet20/builder/Utility/ObjectConverter.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Builder.Model; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Text; - -namespace Builder.Utility -{ - public sealed class ObjectConverter - { - - private static readonly Lazy lazy = - new Lazy(() => new ObjectConverter()); - - public static ObjectConverter Instance { get { return lazy.Value; } } - - private ObjectConverter() - { - - } - - - public BuilderSettings GetBuilderSettingsFromJson(string json) - { - return JsonConvert.DeserializeObject(json); - } - - - - } -} diff --git a/environments/dotnet20/builder/build.sh b/environments/dotnet20/builder/build.sh deleted file mode 100644 index 504f06b0..00000000 --- a/environments/dotnet20/builder/build.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -set -euxo pipefail -cd ${SRC_PKG} -#now start execution of custom logic dll in such a way that it should copy everything in ${SRC_PKG} -#first lets try putting sample file which will prove that this worked -echo src : ${SRC_PKG} ,dest: ${DEPLOY_PKG} >builderpaths.txt - -#now run actual dll for custom builder logic -# please note as this need to be executed from app folder so that all dependent files are avilable -# else you will end up getting File not found error -cd /app - -#now execute dll -dotnet Builder.dll - -#copy entire content to deployment package -cp -r ${SRC_PKG} ${DEPLOY_PKG} \ No newline at end of file diff --git a/environments/dotnet20/builder/builderSettings.json b/environments/dotnet20/builder/builderSettings.json deleted file mode 100644 index e54aaf64..00000000 --- a/environments/dotnet20/builder/builderSettings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "NugetSpecsFile": "nuget.txt", - "DllExcludeFile": "exclude.txt", - "BuildLogDirectory": "logs", - "DllDirectory": "Dlls", - "NugetPackageRegEx": "\\s*(?[^:\\n]*)(?:\\:)?(?.*)?", - "ExcludeDllRegEx": "\\:?\\s*(?[^:\\n]*)(?:\\:)?(?.*)?", - "RunningOnwindows": false, - "functionBodyFileName": "func.cs", - "functionSpecFileName": "func.meta.json" -} \ No newline at end of file diff --git a/environments/dotnet20/builder/log4net.config b/environments/dotnet20/builder/log4net.config deleted file mode 100644 index 7ae56e49..00000000 --- a/environments/dotnet20/builder/log4net.config +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/environments/dotnet20/builder/nugetSettings.json b/environments/dotnet20/builder/nugetSettings.json deleted file mode 100644 index b09a9c67..00000000 --- a/environments/dotnet20/builder/nugetSettings.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "NugetFolder": "Nugetdownload", - "DisableCache": false, - "CSVDirectory": "logs", - "RunningOnwindows": false, - "NugetRepositories": [ - { - "Order": 1, - "IsPrivate": false, - "Name": "local", - "Source": "Nugetdownload", //in case of local , relative path to folder - "IsPasswordClearText": false, - "Username": "", - "Password": "" - }, - { - "Order": 2, - "IsPrivate": false, - "Name": "NugetV3", - "Source": "https://api.nuget.org/v3/index.json", - "IsPasswordClearText": false, - "Username": "", - "Password": "" - } - //, - //{ - // "Order": 3, - // "IsPrivate": true, - // "Name": "myPrivateRepository", //in case of private repo , if not using, then just remove this section No 3 - // "Source": "https://URL-FOR-myPrivateRepository/api/nuget/nugetcore/COMPLETE-END-POINT", - // "IsPasswordClearText": true, - // "Username": "johndeo@myorg.com", - // "Password": "AlPH24GAMAc49fDELTA" - //} - - ] -} \ No newline at end of file diff --git a/environments/dotnet20/dotnet20.sln b/environments/dotnet20/dotnet20.sln deleted file mode 100644 index d3d831dd..00000000 --- a/environments/dotnet20/dotnet20.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26730.12 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "fission-dotnet20", "fission-dotnet20.csproj", "{3F044DE1-74E5-48F7-8D23-233C24AAA45C}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {3F044DE1-74E5-48F7-8D23-233C24AAA45C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3F044DE1-74E5-48F7-8D23-233C24AAA45C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3F044DE1-74E5-48F7-8D23-233C24AAA45C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3F044DE1-74E5-48F7-8D23-233C24AAA45C}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {272000F7-BBEC-4B61-8865-783EF7E5CEE9} - EndGlobalSection -EndGlobal diff --git a/environments/dotnet20/envsettings.json b/environments/dotnet20/envsettings.json deleted file mode 100644 index d151c9c7..00000000 --- a/environments/dotnet20/envsettings.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "LogDirectory": "logs", - "RunningOnwindows": false, - "DllDirectory": "Dlls", - "functionBodyFileName": "func.cs", - "functionSpecFileName": "func.meta.json" -} \ No newline at end of file diff --git a/environments/dotnet20/fission-dotnet20.csproj b/environments/dotnet20/fission-dotnet20.csproj deleted file mode 100644 index 60953ce3..00000000 --- a/environments/dotnet20/fission-dotnet20.csproj +++ /dev/null @@ -1,34 +0,0 @@ - - - - Exe - netcoreapp2.0 - false - - - - - - - - - - - - - - - - - - - - - - - - Always - - - - diff --git a/environments/dotnet20/project-build.sh b/environments/dotnet20/project-build.sh deleted file mode 100755 index 12298d1c..00000000 --- a/environments/dotnet20/project-build.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -dotnet restore fission-dotnet20.csproj -dotnet publish fission-dotnet20.csproj -c Release -o out diff --git a/environments/go/Dockerfile b/environments/go/Dockerfile deleted file mode 100644 index 1bb975a8..00000000 --- a/environments/go/Dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -ARG GO_VERSION=1.9.2 - -FROM ubuntu:18.04 AS base -WORKDIR / -RUN apt update && apt install -y ca-certificates && rm -rf /var/lib/apt/lists/* - -FROM golang:${GO_VERSION} AS builder - -ENV GOPATH /usr -ENV APP ${GOPATH}/src/github.com/fission/fission/environments/go - -WORKDIR ${APP} - -ADD context ${APP}/context -ADD server.go ${APP} - -RUN go get -RUN go build -a -o /server server.go - -FROM base -COPY --from=builder /server / - -ENTRYPOINT ["/server"] -EXPOSE 8888 diff --git a/environments/go/Dockerfile-1.11.4 b/environments/go/Dockerfile-1.11.4 deleted file mode 100644 index 226dbdfb..00000000 --- a/environments/go/Dockerfile-1.11.4 +++ /dev/null @@ -1,24 +0,0 @@ -ARG GO_VERSION=1.11.4 - -FROM ubuntu:18.04 AS base -WORKDIR / -RUN apt update && apt install -y ca-certificates && rm -rf /var/lib/apt/lists/* - -FROM golang:${GO_VERSION} AS builder - -ENV GOPATH /usr -ENV APP ${GOPATH}/src/github.com/fission/fission/environments/go - -WORKDIR ${APP} - -ADD context ${APP}/context -ADD server.go ${APP} - -RUN go get -RUN go build -a -o /server server.go - -FROM base -COPY --from=builder /server / - -ENTRYPOINT ["/server"] -EXPOSE 8888 diff --git a/environments/go/Dockerfile-1.12 b/environments/go/Dockerfile-1.12 deleted file mode 100644 index c5c934d5..00000000 --- a/environments/go/Dockerfile-1.12 +++ /dev/null @@ -1,24 +0,0 @@ -ARG GO_VERSION=1.12 - -FROM ubuntu:18.04 AS base -WORKDIR / -RUN apt update && apt install -y ca-certificates && rm -rf /var/lib/apt/lists/* - -FROM golang:${GO_VERSION} AS builder - -ENV GOPATH /usr -ENV APP ${GOPATH}/src/github.com/fission/fission/environments/go - -WORKDIR ${APP} - -ADD context ${APP}/context -ADD server.go ${APP} - -RUN go get -RUN go build -a -o /server server.go - -FROM base -COPY --from=builder /server / - -ENTRYPOINT ["/server"] -EXPOSE 8888 diff --git a/environments/go/Dockerfile-1.13 b/environments/go/Dockerfile-1.13 deleted file mode 100644 index 5542bdc5..00000000 --- a/environments/go/Dockerfile-1.13 +++ /dev/null @@ -1,24 +0,0 @@ -ARG GO_VERSION=1.13 - -FROM ubuntu:18.04 AS base -WORKDIR / -RUN apt update && apt install -y ca-certificates && rm -rf /var/lib/apt/lists/* - -FROM golang:${GO_VERSION} AS builder - -ENV GOPATH /usr -ENV APP ${GOPATH}/src/github.com/fission/fission/environments/go - -WORKDIR ${APP} - -ADD context ${APP}/context -ADD server.go ${APP} - -RUN go get -RUN go build -a -o /server server.go - -FROM base -COPY --from=builder /server / - -ENTRYPOINT ["/server"] -EXPOSE 8888 diff --git a/environments/go/Dockerfile-1.14 b/environments/go/Dockerfile-1.14 deleted file mode 100644 index 4fab4759..00000000 --- a/environments/go/Dockerfile-1.14 +++ /dev/null @@ -1,24 +0,0 @@ -ARG GO_VERSION=1.14 - -FROM ubuntu:18.04 AS base -WORKDIR / -RUN apt update && apt install -y ca-certificates && rm -rf /var/lib/apt/lists/* - -FROM golang:${GO_VERSION} AS builder - -ENV GOPATH /usr -ENV APP ${GOPATH}/src/github.com/fission/fission/environments/go - -WORKDIR ${APP} - -ADD context ${APP}/context -ADD server.go ${APP} - -RUN go get -RUN go build -a -o /server server.go - -FROM base -COPY --from=builder /server / - -ENTRYPOINT ["/server"] -EXPOSE 8888 diff --git a/environments/go/README.md b/environments/go/README.md deleted file mode 100644 index 1ab0d7d6..00000000 --- a/environments/go/README.md +++ /dev/null @@ -1,38 +0,0 @@ -# Fission: Go Environment - -This is the Go environment for Fission. - -It's a Docker image containing a Go runtime, along with a dynamic loader. - -Looking for ready-to-run examples? See the [Go examples directory](../../examples/go). - -## Build this image - -``` -docker build -t USER/go-runtime . && docker push USER/go-runtime -``` - -Note that if you build the runtime, you must also build the go-builder -image, to ensure that it's at the same version of go: - -``` -cd builder && docker build -t USER/go-builder . && docker push USER/go-builder -``` - -## Using the image in fission - -You can add this customized image to fission with "fission env -create": - -``` -fission env create --name go --image USER/go-runtime --builder USER/go-builder --version 2 -``` - -Or, if you already have an environment, you can update its image: - -``` -fission env update --name go --image USER/go-runtime --builder USER/go-builder -``` - -After this, fission functions that have the env parameter set to the -same environment name as this command will use this environment. diff --git a/environments/go/builder/Dockerfile b/environments/go/builder/Dockerfile deleted file mode 100644 index 178ae671..00000000 --- a/environments/go/builder/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -ARG BUILDER_IMAGE=fission/builder -ARG GO_VERSION=1.9.2 - -FROM ${BUILDER_IMAGE} - -FROM golang:${GO_VERSION} - -ENV GOPATH /usr -WORKDIR ${GOPATH} - -COPY --from=0 /builder /builder -ADD build.sh /usr/local/bin/build - diff --git a/environments/go/builder/Dockerfile-1.11.4 b/environments/go/builder/Dockerfile-1.11.4 deleted file mode 100644 index 0f6b6ebe..00000000 --- a/environments/go/builder/Dockerfile-1.11.4 +++ /dev/null @@ -1,13 +0,0 @@ -ARG BUILDER_IMAGE=fission/builder -ARG GO_VERSION=1.11.4 - -FROM ${BUILDER_IMAGE} - -FROM golang:${GO_VERSION} - -ENV GOPATH /usr -WORKDIR ${GOPATH} - -COPY --from=0 /builder /builder -ADD build.sh /usr/local/bin/build - diff --git a/environments/go/builder/Dockerfile-1.12 b/environments/go/builder/Dockerfile-1.12 deleted file mode 100644 index e30415c7..00000000 --- a/environments/go/builder/Dockerfile-1.12 +++ /dev/null @@ -1,14 +0,0 @@ -ARG BUILDER_IMAGE=fission/builder -ARG GO_VERSION=1.12 - -FROM ${BUILDER_IMAGE} - -FROM golang:${GO_VERSION} - -ENV GOPATH /usr -ENV GO111MODULE on -WORKDIR ${GOPATH} - -COPY --from=0 /builder /builder -ADD build.sh /usr/local/bin/build - diff --git a/environments/go/builder/Dockerfile-1.13 b/environments/go/builder/Dockerfile-1.13 deleted file mode 100644 index 144f5a7d..00000000 --- a/environments/go/builder/Dockerfile-1.13 +++ /dev/null @@ -1,14 +0,0 @@ -ARG BUILDER_IMAGE=fission/builder -ARG GO_VERSION=1.13 - -FROM ${BUILDER_IMAGE} - -FROM golang:${GO_VERSION} - -ENV GOPATH /usr -ENV GO111MODULE on -WORKDIR ${GOPATH} - -COPY --from=0 /builder /builder -ADD build.sh /usr/local/bin/build - diff --git a/environments/go/builder/Dockerfile-1.14 b/environments/go/builder/Dockerfile-1.14 deleted file mode 100644 index 476b0bce..00000000 --- a/environments/go/builder/Dockerfile-1.14 +++ /dev/null @@ -1,14 +0,0 @@ -ARG BUILDER_IMAGE=fission/builder -ARG GO_VERSION=1.14 - -FROM ${BUILDER_IMAGE} - -FROM golang:${GO_VERSION} - -ENV GOPATH /usr -ENV GO111MODULE on -WORKDIR ${GOPATH} - -COPY --from=0 /builder /builder -ADD build.sh /usr/local/bin/build - diff --git a/environments/go/builder/build.sh b/environments/go/builder/build.sh deleted file mode 100755 index 17310980..00000000 --- a/environments/go/builder/build.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -set -eux - -srcDir=${GOPATH}/src/$(basename ${SRC_PKG}) - -trap "rm -rf ${srcDir}" EXIT - -# http://ask.xmodulo.com/compare-two-version-numbers.html -version_ge() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"; } - -if [ -d ${SRC_PKG} ] -then - echo "Building in directory ${srcDir}" - ln -sf ${SRC_PKG} ${srcDir} -elif [ -f ${SRC_PKG} ] -then - echo "Building file ${SRC_PKG} in ${srcDir}" - mkdir -p ${srcDir} - cp ${SRC_PKG} ${srcDir}/function.go -fi - -cd ${srcDir} - -if [ ! -z ${GOLANG_VERSION} ] && version_ge ${GOLANG_VERSION} "1.12"; then - if [ -f "go.mod" ]; then - go mod download - else - # still need to do this; otherwise, go will complain "cannot find main module". - go mod init - fi -else # go version lower than go 1.12 - if [ -f "go.mod" ]; then - echo "Please update fission/go-builder and fission/go-env image to the latest version to support go module" - exit 1 - fi -fi - -# use vendor mode if the vendor dir exists when go version is greater -# than 1.12 (the version that fission started to support go module). -if [ -d "vendor" ] && [ ! -z ${GOLANG_VERSION} ] && version_ge ${GOLANG_VERSION} "1.12"; then - go build -mod=vendor -buildmode=plugin -i -o ${DEPLOY_PKG} . -else - go build -buildmode=plugin -i -o ${DEPLOY_PKG} . -fi diff --git a/environments/go/context/context.go b/environments/go/context/context.go deleted file mode 100644 index 37c601a8..00000000 --- a/environments/go/context/context.go +++ /dev/null @@ -1,10 +0,0 @@ -package context - -type ( - Context map[string]interface{} -) - -func New() Context { - ctx := make(map[string]interface{}) - return ctx -} diff --git a/environments/go/server.go b/environments/go/server.go deleted file mode 100644 index 6250ff72..00000000 --- a/environments/go/server.go +++ /dev/null @@ -1,203 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "log" - "net/http" - "os" - "path/filepath" - "plugin" - - // DO NOT IMPORT THIRD PARTY PACKAGES - // The 3rd party package version used by go server may be - // different from the one in user's source code and will - // cause plugin version mismatched. Hence, we should never - // import any external packages except the Fission or built-in - // packages. - - "github.com/fission/fission/environments/go/context" -) - -const ( - CODE_PATH = "/userfunc/user" -) - -type ( - FunctionLoadRequest struct { - // FilePath is an absolute filesystem path to the - // function. What exactly is stored here is - // env-specific. Optional. - FilePath string `json:"filepath"` - - // FunctionName has an environment-specific meaning; - // usually, it defines a function within a module - // containing multiple functions. Optional; default is - // environment-specific. - FunctionName string `json:"functionName"` - - // URL to expose this function at. Optional; defaults - // to "/". - URL string `json:"url"` - } -) - -var userFunc http.HandlerFunc - -func loadPlugin(codePath, entrypoint string) (http.HandlerFunc, error) { - - // if codepath's a directory, load the file inside it - info, err := os.Stat(codePath) - if err != nil { - return nil, fmt.Errorf("error checking plugin path: %v", err) - } - if info.IsDir() { - files, err := ioutil.ReadDir(codePath) - if err != nil { - return nil, fmt.Errorf("error reading directory: %v", err) - } - if len(files) == 0 { - return nil, fmt.Errorf("no files to load: %v", codePath) - } - fi := files[0] - codePath = filepath.Join(codePath, fi.Name()) - } - - log.Printf("loading plugin from %v", codePath) - p, err := plugin.Open(codePath) - if err != nil { - return nil, fmt.Errorf("error loading plugin: %v", err) - } - sym, err := p.Lookup(entrypoint) - if err != nil { - return nil, fmt.Errorf("entry point not found: %v", err) - } - - switch h := sym.(type) { - case *http.Handler: - return (*h).ServeHTTP, nil - case *http.HandlerFunc: - return *h, nil - case func(http.ResponseWriter, *http.Request): - return h, nil - case func(context.Context, http.ResponseWriter, *http.Request): - return func(w http.ResponseWriter, r *http.Request) { - c := context.New() - h(c, w, r) - }, nil - default: - panic("Entry point not found: bad type") - } -} - -func specializeHandler() func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - if userFunc != nil { - w.WriteHeader(http.StatusBadRequest) - w.Write([]byte("Not a generic container")) - return - } - - _, err := os.Stat(CODE_PATH) - if err != nil { - if os.IsNotExist(err) { - log.Printf("code path (%v) does not exist: %v", CODE_PATH, err) - w.WriteHeader(http.StatusNotFound) - w.Write([]byte(CODE_PATH + ": not found")) - return - } else { - log.Printf("unknown error looking for code path(%v): %v", CODE_PATH, err) - err = fmt.Errorf("unknown error: %v", err) - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte(err.Error())) - return - } - } - - log.Println("specializing ...") - userFunc, err = loadPlugin(CODE_PATH, "Handler") - if err != nil { - err = fmt.Errorf("error specializing function: %v", err) - log.Println(err.Error()) - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte(err.Error())) - return - } - log.Println("done") - } -} - -func specializeHandlerV2() func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - if userFunc != nil { - w.WriteHeader(http.StatusBadRequest) - w.Write([]byte("Not a generic container")) - return - } - - body, err := ioutil.ReadAll(r.Body) - if err != nil { - log.Printf("error reading request body: %v", err) - w.WriteHeader(http.StatusInternalServerError) - return - } - var loadreq FunctionLoadRequest - err = json.Unmarshal(body, &loadreq) - if err != nil { - w.WriteHeader(http.StatusBadRequest) - return - } - - _, err = os.Stat(loadreq.FilePath) - if err != nil { - if os.IsNotExist(err) { - log.Printf("code path (%v) does not exist: %v", loadreq.FilePath, err) - w.WriteHeader(http.StatusNotFound) - w.Write([]byte(loadreq.FilePath + ": not found")) - return - } else { - log.Printf("unknown error looking for code path(%v): %v", loadreq.FilePath, err) - err = fmt.Errorf("unknown error: %v", err) - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte(err.Error())) - return - } - } - - log.Println("specializing ...") - userFunc, err = loadPlugin(loadreq.FilePath, loadreq.FunctionName) - if err != nil { - err = fmt.Errorf("error specializing function: %v", err) - log.Println(err.Error()) - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte(err.Error())) - return - } - log.Println("done") - } -} - -func readinessProbeHandler(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(http.StatusOK) -} - -func main() { - - http.HandleFunc("/healthz", readinessProbeHandler) - http.HandleFunc("/specialize", specializeHandler()) - http.HandleFunc("/v2/specialize", specializeHandlerV2()) - - // Generic route -- all http requests go to the user function. - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - if userFunc == nil { - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte("Generic container: no requests supported")) - return - } - userFunc(w, r) - }) - - log.Println("listening on 8888 ...") - http.ListenAndServe(":8888", nil) -} diff --git a/environments/jvm-jersey/.gitignore b/environments/jvm-jersey/.gitignore deleted file mode 100644 index 809cc8f2..00000000 --- a/environments/jvm-jersey/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -target/ -bin/ diff --git a/environments/jvm-jersey/Dockerfile b/environments/jvm-jersey/Dockerfile deleted file mode 100644 index a4b04096..00000000 --- a/environments/jvm-jersey/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM maven:3.5-jdk-8 as BUILD -WORKDIR /usr/src/myapp/ - -# To reuse the build cache, here we split maven dependency -# download and package into two RUN commands to avoid cache invalidation. -COPY pom.xml . -RUN mvn dependency:go-offline - -COPY src /usr/src/myapp/src/ -RUN mvn package - -FROM openjdk:8-jre-alpine -COPY --from=BUILD /usr/src/myapp/target/env-jvm-jersey-0.0.1.jar /app.jar -ENTRYPOINT java ${JVM_OPTS} -Djava.security.egd=file:/dev/./urandom -jar app.jar 8888 -EXPOSE 8888 diff --git a/environments/jvm-jersey/Dockerfile-11 b/environments/jvm-jersey/Dockerfile-11 deleted file mode 100644 index 37353798..00000000 --- a/environments/jvm-jersey/Dockerfile-11 +++ /dev/null @@ -1,15 +0,0 @@ -FROM maven:3.6-jdk-11 as BUILD -WORKDIR /usr/src/myapp/ - -# To reuse the build cache, here we split maven dependency -# download and package into two RUN commands to avoid cache invalidation. -COPY pom.xml . -RUN mvn dependency:go-offline - -COPY src /usr/src/myapp/src/ -RUN mvn package - -FROM openjdk:11-jre -COPY --from=BUILD /usr/src/myapp/target/env-jvm-jersey-0.0.1.jar /app.jar -ENTRYPOINT java ${JVM_OPTS} -Djava.security.egd=file:/dev/./urandom -jar /app.jar --server.port=8888 -EXPOSE 8888 diff --git a/environments/jvm-jersey/README.md b/environments/jvm-jersey/README.md deleted file mode 100644 index 2a6278d9..00000000 --- a/environments/jvm-jersey/README.md +++ /dev/null @@ -1,68 +0,0 @@ -# Fission: Java and JVM-Jersey Environment - -This is the JVM (Jersey based) environment for Fission. - -It's a Docker image containing a OpenJDK8 runtime, along with a -dynamic loader. A few dependencies are included in the -pom.xml file. - -Unlike the other [JVM environment](../jvm) which is based on the Spring framework, this environment uses Jersey. - -Looking for ready-to-run examples? See the [JVM examples directory](../../examples/jvm-jersey). - -## Customizing this image - -To add package dependencies, edit pom.xml to add what you -need, and rebuild this image (instructions below). - -## Rebuilding and pushing the image - -You'll need access to a Docker registry to push the image: you can -sign up for Docker hub at hub.docker.com, or use registries from -gcr.io, quay.io, etc. Let's assume you're using a docker hub account -called USER. Build and push the image to the the registry: - -``` - docker build -t USER/jvm-jersey-env . && docker push USER/jvm-jersey-env -``` - -You can also create environment image based on JVM 11 using Dockerfile-11 in this directory. - -## Using the image in fission - -You can add this customized image to fission with "fission env -create": - -``` - fission env create --name jvm --image USER/jvm-jersey-env -``` - -Or, if you already have an environment, you can update its image: - -``` - fission env update --name jvm --image USER/jvm-jersey-env -``` - -After this, fission functions that have the env parameter set to the -same environment name as this command will use this environment. - -## Web Server Framework - -JVM Jersey environment uses an embedded Jetty HTTP server by default, as can be seen in the pom.xml file. - -``` - - org.eclipse.jetty - jetty-server - 9.0.4.v20130625 - - - org.eclipse.jetty - jetty-servlet - 9.0.4.v20130625 - -``` - -## Java and JVM builder - -There are two JVM environment builder based on OpenJDK8 and OpenJDK 11 and using Maven 3.5.4. The default build command runs `mvn clean package` and uses the target/*with-dependencies.jar file for function. The default build command can be overridden as long as the uber jar file is copied to ${DEPLOY_PKG}. diff --git a/environments/jvm-jersey/builder/Dockerfile b/environments/jvm-jersey/builder/Dockerfile deleted file mode 100644 index 24db019a..00000000 --- a/environments/jvm-jersey/builder/Dockerfile +++ /dev/null @@ -1,48 +0,0 @@ -## Fission builder base image -ARG BUILDER_IMAGE=fission/builder:latest -FROM ${BUILDER_IMAGE} - -## Section copied from the openjdk:8-jdk-alpine Dockerfile - (https://github.com/docker-library/openjdk/blob/47a6539cd18023dafb45db9013455136cc0bca07/8/jdk/alpine/Dockerfile) - -ENV LANG C.UTF-8 -RUN { \ - echo '#!/bin/sh'; \ - echo 'set -e'; \ - echo; \ - echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \ - } > /usr/local/bin/docker-java-home \ - && chmod +x /usr/local/bin/docker-java-home -ENV JAVA_HOME /usr/lib/jvm/java-1.8-openjdk -ENV PATH $PATH:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin - -ENV JAVA_VERSION 8u181 -## Use "fuzzy" version matching to pin the version to a major/minor release -ENV JAVA_ALPINE_VERSION "~8" - -RUN set -x \ - && apk add --no-cache \ - openjdk8="$JAVA_ALPINE_VERSION" \ - && [ "$JAVA_HOME" = "$(docker-java-home)" ] - -## Section copied from the Maven Dockerfile - -RUN apk add --no-cache curl tar bash procps - -ARG MAVEN_VERSION=3.5.4 -ARG USER_HOME_DIR="/root" -ARG SHA=ce50b1c91364cb77efe3776f756a6d92b76d9038b0a0782f7d53acf1e997a14d -ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries - -RUN mkdir -p /usr/share/maven /usr/share/maven/ref \ - && curl -fsSL -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \ - && echo "${SHA} /tmp/apache-maven.tar.gz" | sha256sum -c - \ - && tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \ - && rm -f /tmp/apache-maven.tar.gz \ - && ln -s /usr/share/maven/bin/mvn /usr/bin/mvn - -ENV MAVEN_HOME /usr/share/maven -ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2" - -## Fission builder specific section -ADD build.sh /usr/local/bin/build -EXPOSE 8001 diff --git a/environments/jvm-jersey/builder/Dockerfile-11 b/environments/jvm-jersey/builder/Dockerfile-11 deleted file mode 100644 index 8849d9af..00000000 --- a/environments/jvm-jersey/builder/Dockerfile-11 +++ /dev/null @@ -1,43 +0,0 @@ -## Fission builder base image -ARG BUILDER_IMAGE=fission/builder:latest -FROM ${BUILDER_IMAGE} - -## Section referred from the openjdk:8-jdk-alpine Dockerfile - (https://github.com/docker-library/openjdk/blob/47a6539cd18023dafb45db9013455136cc0bca07/8/jdk/alpine/Dockerfile) - -ENV LANG C.UTF-8 -RUN { \ - echo '#!/bin/sh'; \ - echo 'set -e'; \ - echo; \ - echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \ - } > /usr/local/bin/docker-java-home \ - && chmod +x /usr/local/bin/docker-java-home -ENV JAVA_HOME /usr/lib/jvm/java-11-openjdk -ENV PATH $PATH:/usr/lib/jvm/java-11-openjdk/jre/bin:/usr/lib/jvm/java-11-openjdk/bin - -RUN set -x \ - && apk add --no-cache openjdk11 \ - && [ "$JAVA_HOME" = "$(docker-java-home)" ] - -## Section copied from the Maven Dockerfile - -RUN apk add --no-cache curl tar bash procps - -ARG MAVEN_VERSION=3.5.4 -ARG USER_HOME_DIR="/root" -ARG SHA=ce50b1c91364cb77efe3776f756a6d92b76d9038b0a0782f7d53acf1e997a14d -ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries - -RUN mkdir -p /usr/share/maven /usr/share/maven/ref \ - && curl -fsSL -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \ - && echo "${SHA} /tmp/apache-maven.tar.gz" | sha256sum -c - \ - && tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \ - && rm -f /tmp/apache-maven.tar.gz \ - && ln -s /usr/share/maven/bin/mvn /usr/bin/mvn - -ENV MAVEN_HOME /usr/share/maven -ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2" - -## Fission builder specific section -ADD build.sh /usr/local/bin/build -EXPOSE 8001 diff --git a/environments/jvm-jersey/builder/build.sh b/environments/jvm-jersey/builder/build.sh deleted file mode 100755 index bf167d59..00000000 --- a/environments/jvm-jersey/builder/build.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -set -eou pipefail -mvn clean package -cp ${SRC_PKG}/target/*with-dependencies.jar ${DEPLOY_PKG} \ No newline at end of file diff --git a/environments/jvm-jersey/pom.xml b/environments/jvm-jersey/pom.xml deleted file mode 100644 index 01cfb786..00000000 --- a/environments/jvm-jersey/pom.xml +++ /dev/null @@ -1,86 +0,0 @@ - - - 4.0.0 - - io.fission - env-jvm-jersey - 0.0.1 - - - 1.6 - 1.6 - - - - - io.fission - fission-jvm-jersey - 0.0.1 - - - org.eclipse.jetty - jetty-server - 9.4.17.v20190418 - - - org.eclipse.jetty - jetty-servlet - 9.4.17.v20190418 - - - org.glassfish.jersey.containers - jersey-container-servlet-core - 2.0 - - - org.glassfish.jersey.media - jersey-media-json-jackson - 2.0 - - - javax.xml - jaxb-api - 2.1 - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - ${java.source.level} - ${java.target.level} - UTF-8 - true - true - - - - maven-assembly-plugin - - - - io.fission.Main - - - - jar-with-dependencies - - false - - - - package - - single - - - - - - - diff --git a/environments/jvm-jersey/src/main/java/io/fission/FunctionLoadRequest.java b/environments/jvm-jersey/src/main/java/io/fission/FunctionLoadRequest.java deleted file mode 100644 index 02d3e65a..00000000 --- a/environments/jvm-jersey/src/main/java/io/fission/FunctionLoadRequest.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.fission; - -import org.codehaus.jackson.annotate.JsonIgnoreProperties; - -@JsonIgnoreProperties(ignoreUnknown = true) -public class FunctionLoadRequest { - - private String filepath; - private String functionName; - private String url; - - String getFilepath() { - return filepath; - } - - void setFilepath(String filepath) { - this.filepath = filepath; - } - - String getUrl() { - return url; - } - - void setUrl(String url) { - this.url = url; - } - - public String getFunctionName() { - return functionName; - } - - public void setFunctionName(String functionName) { - this.functionName = functionName; - } -} diff --git a/environments/jvm-jersey/src/main/java/io/fission/JerseyServer.java b/environments/jvm-jersey/src/main/java/io/fission/JerseyServer.java deleted file mode 100644 index b33927cc..00000000 --- a/environments/jvm-jersey/src/main/java/io/fission/JerseyServer.java +++ /dev/null @@ -1,146 +0,0 @@ -package io.fission; - -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Enumeration; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.DELETE; -import javax.ws.rs.Path; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Context; -import javax.ws.rs.container.ContainerRequestContext; - -import io.fission.Function; - -@Path("/") -public class JerseyServer { - - private static Function fn; - - private static final int CLASS_LENGTH = 6; - - private static Logger logger = Logger.getGlobal(); - - @GET - public Response home(@Context ContainerRequestContext request) { - return callUserFunction(request); - } - - @POST - public Response homePost(@Context ContainerRequestContext request) { - return callUserFunction(request); - } - - @PUT - public Response homePut(@Context ContainerRequestContext request) { - return callUserFunction(request); - } - - @DELETE - public Response homeDelete(@Context ContainerRequestContext request) { - return callUserFunction(request); - } - - @Path("v2/specialize") - @POST - public Response specialize(FunctionLoadRequest req) { - - long startTime = System.nanoTime(); - File file = new File(req.getFilepath()); - - if (!file.exists()) { - return Response.status(Response.Status.BAD_REQUEST).entity("/userfunc/usernot found").build(); - } - - String entryPoint = req.getFunctionName(); - logger.log(Level.INFO, "Entrypoint class:" + entryPoint); - if (entryPoint == null) { - return Response.status(Response.Status.BAD_REQUEST).entity("Entrypoint class is missing in the JAR or the name is incorrect") - .build(); - } - - JarFile jarFile = null; - ClassLoader cl = null; - try { - - jarFile = new JarFile(file); - Enumeration e = jarFile.entries(); - URL[] urls = { new URL("jar:file:" + file + "!/") }; - - // TODO Check if the class loading can be improved for ex. use something like: - // Thread.currentThread().setContextClassLoader(cl); - if (this.getClass().getClassLoader() == null) { - cl = URLClassLoader.newInstance(urls); - } else { - cl = URLClassLoader.newInstance(urls, this.getClass().getClassLoader()); - } - - if (cl == null) { - return Response.status(Response.Status.BAD_REQUEST).entity("Failed to initialize the class loader") - .build(); - } - - // Load all dependent classes from libraries etc. - while (e.hasMoreElements()) { - JarEntry je = e.nextElement(); - if (je.isDirectory() || !je.getName().endsWith(".class")) { - continue; - } - String className = je.getName().substring(0, je.getName().length() - CLASS_LENGTH); - className = className.replace('/', '.'); - cl.loadClass(className); - } - - // Instantiate the function class - fn = (Function) cl.loadClass(entryPoint).newInstance(); - } catch (MalformedURLException e) { - e.printStackTrace(); - return Response.status(Response.Status.BAD_REQUEST).entity("Entrypoint class is missing in the function") - .build(); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - return Response.status(Response.Status.BAD_REQUEST).entity("Error loading Function or dependent class") - .build(); - } catch (InstantiationException e) { - e.printStackTrace(); - return Response.status(Response.Status.BAD_REQUEST) - .entity("Error creating a new instance of function class").build(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - return Response.status(Response.Status.BAD_REQUEST) - .entity("Error creating a new instance of function class").build(); - } catch (IOException e) { - e.printStackTrace(); - return Response.status(Response.Status.BAD_REQUEST).entity("Error reading the JAR file").build(); - } finally { - try { - jarFile.close(); - } catch (IOException e) { - e.printStackTrace(); - return Response.status(Response.Status.BAD_REQUEST) - .entity("Error closing the file while loading the class").build(); - } - } - long elapsedTime = System.nanoTime() - startTime; - logger.log(Level.INFO, "Specialize call done in: " + elapsedTime / 1000000 + " ms"); - return Response.status(Response.Status.OK).entity("Done").build(); - } - - private Response callUserFunction(ContainerRequestContext httpRequest) { - if (fn == null) { - return Response.status(Response.Status.BAD_REQUEST).entity("Container not specialized").build(); - } else { - return fn.call(httpRequest, null); - } - } -} diff --git a/environments/jvm-jersey/src/main/java/io/fission/Main.java b/environments/jvm-jersey/src/main/java/io/fission/Main.java deleted file mode 100644 index a3148f1c..00000000 --- a/environments/jvm-jersey/src/main/java/io/fission/Main.java +++ /dev/null @@ -1,50 +0,0 @@ -package io.fission; - -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.servlet.ServletContextHandler; -import org.eclipse.jetty.servlet.ServletHolder; -import org.glassfish.jersey.jackson.JacksonFeature; -import org.glassfish.jersey.server.ResourceConfig; -import org.glassfish.jersey.servlet.ServletContainer; - -public class Main { - - private static final int DEFAULT_PORT = 8888; - - private int serverPort; - - public Main(int serverPort) throws Exception { - this.serverPort = serverPort; - Server server = configureServer(); - server.start(); - server.join(); - } - - private Server configureServer() { - ResourceConfig resourceConfig = new ResourceConfig(); - resourceConfig.packages(JerseyServer.class.getPackage().getName()); - resourceConfig.register(JacksonFeature.class); - ServletContainer servletContainer = new ServletContainer(resourceConfig); - ServletHolder sh = new ServletHolder(servletContainer); - Server server = new Server(serverPort); - ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); - context.setContextPath("/"); - context.addServlet(sh, "/*"); - server.setHandler(context); - return server; - } - - public static void main(String[] args) throws Exception { - - int serverPort = DEFAULT_PORT; - - if(args.length >= 1) { - try { - serverPort = Integer.parseInt(args[0]); - } catch (NumberFormatException e) { - e.printStackTrace(); - } - } - new Main(serverPort); - } -} diff --git a/environments/jvm/.gitignore b/environments/jvm/.gitignore deleted file mode 100644 index e0a3199d..00000000 --- a/environments/jvm/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -.springBeans -.project -.mvn -.settings -.classpath -target/ -bin/ diff --git a/environments/jvm/Dockerfile b/environments/jvm/Dockerfile deleted file mode 100644 index 02f0f609..00000000 --- a/environments/jvm/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -FROM maven:3.5-jdk-8 as BUILD -WORKDIR /usr/src/myapp/ - -# To reuse the build cache, here we split maven dependency -# download and package into two RUN commands to avoid cache invalidation. -COPY pom.xml . -RUN mvn dependency:go-offline - -COPY src /usr/src/myapp/src/ -RUN mvn package - -FROM openjdk:8-jdk-alpine -VOLUME /tmp -COPY --from=BUILD /usr/src/myapp/target/env-java-0.0.1-SNAPSHOT.jar /app.jar -ENTRYPOINT java ${JVM_OPTS} -Djava.security.egd=file:/dev/./urandom -jar /app.jar --server.port=8888 -EXPOSE 8888 \ No newline at end of file diff --git a/environments/jvm/README.md b/environments/jvm/README.md deleted file mode 100644 index 96b0cdea..00000000 --- a/environments/jvm/README.md +++ /dev/null @@ -1,70 +0,0 @@ -# Fission: Java and JVM Environment - -This is the JVM environment for Fission. - -It's a Docker image containing a OpenJDK8 runtime, along with a -dynamic loader. A few dependencies are included in the -pom.xml file. - -Looking for ready-to-run examples? See the [JVM examples directory](../../examples/jvm). - -## Customizing this image - -To add package dependencies, edit pom.xml to add what you -need, and rebuild this image (instructions below). - -## Rebuilding and pushing the image - -You'll need access to a Docker registry to push the image: you can -sign up for Docker hub at hub.docker.com, or use registries from -gcr.io, quay.io, etc. Let's assume you're using a docker hub account -called USER. Build and push the image to the the registry: - -``` - docker build -t USER/jvm-env . && docker push USER/jvm-env -``` - -## Using the image in fission - -You can add this customized image to fission with "fission env -create": - -``` - fission env create --name jvm --image USER/jvm-env -``` - -Or, if you already have an environment, you can update its image: - -``` - fission env update --name jvm --image USER/jvm-env -``` - -After this, fission functions that have the env parameter set to the -same environment name as this command will use this environment. - -## Web Server Framework - -JVM environment uses Tomcat HTTP server by default as it is included in spring web. You can choose to use jetty or undertow by changing the dependency in pom.xml file as shown below. - -``` - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-tomcat - - - - - - org.springframework.boot - spring-boot-starter-jetty - -``` - -## Java and JVM builder - -JVM environment builder is based on OpenJDK8 and Maven 3.5.4 version. The default build command runs `mvn clean package` and uses the target/*with-dependencies.jar file for function. The default build command can be overridden as long as the uber jar file is copied to ${DEPLOY_PKG}. diff --git a/environments/jvm/builder/Dockerfile b/environments/jvm/builder/Dockerfile deleted file mode 100644 index 24db019a..00000000 --- a/environments/jvm/builder/Dockerfile +++ /dev/null @@ -1,48 +0,0 @@ -## Fission builder base image -ARG BUILDER_IMAGE=fission/builder:latest -FROM ${BUILDER_IMAGE} - -## Section copied from the openjdk:8-jdk-alpine Dockerfile - (https://github.com/docker-library/openjdk/blob/47a6539cd18023dafb45db9013455136cc0bca07/8/jdk/alpine/Dockerfile) - -ENV LANG C.UTF-8 -RUN { \ - echo '#!/bin/sh'; \ - echo 'set -e'; \ - echo; \ - echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \ - } > /usr/local/bin/docker-java-home \ - && chmod +x /usr/local/bin/docker-java-home -ENV JAVA_HOME /usr/lib/jvm/java-1.8-openjdk -ENV PATH $PATH:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin - -ENV JAVA_VERSION 8u181 -## Use "fuzzy" version matching to pin the version to a major/minor release -ENV JAVA_ALPINE_VERSION "~8" - -RUN set -x \ - && apk add --no-cache \ - openjdk8="$JAVA_ALPINE_VERSION" \ - && [ "$JAVA_HOME" = "$(docker-java-home)" ] - -## Section copied from the Maven Dockerfile - -RUN apk add --no-cache curl tar bash procps - -ARG MAVEN_VERSION=3.5.4 -ARG USER_HOME_DIR="/root" -ARG SHA=ce50b1c91364cb77efe3776f756a6d92b76d9038b0a0782f7d53acf1e997a14d -ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries - -RUN mkdir -p /usr/share/maven /usr/share/maven/ref \ - && curl -fsSL -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \ - && echo "${SHA} /tmp/apache-maven.tar.gz" | sha256sum -c - \ - && tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \ - && rm -f /tmp/apache-maven.tar.gz \ - && ln -s /usr/share/maven/bin/mvn /usr/bin/mvn - -ENV MAVEN_HOME /usr/share/maven -ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2" - -## Fission builder specific section -ADD build.sh /usr/local/bin/build -EXPOSE 8001 diff --git a/environments/jvm/builder/build.sh b/environments/jvm/builder/build.sh deleted file mode 100755 index bf167d59..00000000 --- a/environments/jvm/builder/build.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -set -eou pipefail -mvn clean package -cp ${SRC_PKG}/target/*with-dependencies.jar ${DEPLOY_PKG} \ No newline at end of file diff --git a/environments/jvm/pom.xml b/environments/jvm/pom.xml deleted file mode 100644 index 458404fc..00000000 --- a/environments/jvm/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - 4.0.0 - - io.fission - env-java - 0.0.1-SNAPSHOT - - - org.springframework.boot - spring-boot-starter-parent - 2.0.1.RELEASE - - - - - org.springframework.boot - spring-boot-starter-web - - - io.fission - fission-java-core - 0.0.2-SNAPSHOT - - - com.fasterxml.jackson.dataformat - jackson-dataformat-xml - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - - - - fission-java-core - fission-java-core-snapshot - https://oss.sonatype.org/content/repositories/snapshots/ - - - \ No newline at end of file diff --git a/environments/jvm/src/main/java/io/fission/FunctionLoadRequest.java b/environments/jvm/src/main/java/io/fission/FunctionLoadRequest.java deleted file mode 100644 index f5276840..00000000 --- a/environments/jvm/src/main/java/io/fission/FunctionLoadRequest.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.fission; - -public class FunctionLoadRequest { - - private String filepath; - private String functionName; - private String url; - - String getFilepath() { - return filepath; - } - - void setFilepath(String filepath) { - this.filepath = filepath; - } - - String getUrl() { - return url; - } - - void setUrl(String url) { - this.url = url; - } - - public String getFunctionName() { - return functionName; - } - - public void setFunctionName(String functionName) { - this.functionName = functionName; - } -} diff --git a/environments/jvm/src/main/java/io/fission/Server.java b/environments/jvm/src/main/java/io/fission/Server.java deleted file mode 100644 index 7c48da93..00000000 --- a/environments/jvm/src/main/java/io/fission/Server.java +++ /dev/null @@ -1,122 +0,0 @@ -package io.fission; - -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Enumeration; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.springframework.boot.*; -import org.springframework.boot.autoconfigure.*; -import org.springframework.http.RequestEntity; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import io.fission.Function; - -@RestController -@EnableAutoConfiguration -public class Server { - - private Function fn; - - private static final int CLASS_LENGTH = 6; - - private static Logger logger = Logger.getGlobal(); - - @RequestMapping(value = "/", method = { RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE, - RequestMethod.PUT }) - ResponseEntity home(RequestEntity req) { - if (fn == null) { - return ResponseEntity.badRequest().body("Container not specialized"); - } else { - return ((ResponseEntity) ((Function) fn).call(req, null)); - } - } - - @PostMapping(path = "/v2/specialize", consumes = "application/json") - ResponseEntity specialize(@RequestBody FunctionLoadRequest req) { - long startTime = System.nanoTime(); - File file = new File(req.getFilepath()); - if (!file.exists()) { - return ResponseEntity.badRequest().body("/userfunc/user not found"); - } - - String entryPoint = req.getFunctionName(); - logger.log(Level.INFO, "Entrypoint class:" + entryPoint); - if (entryPoint == null) { - return ResponseEntity.badRequest().body("Entrypoint class is missing in the function"); - } - - JarFile jarFile = null; - ClassLoader cl = null; - try { - - jarFile = new JarFile(file); - Enumeration e = jarFile.entries(); - URL[] urls = { new URL("jar:file:" + file + "!/") }; - - // TODO Check if the class loading can be improved for ex. use something like: - // Thread.currentThread().setContextClassLoader(cl); - if (this.getClass().getClassLoader() == null) { - cl = URLClassLoader.newInstance(urls); - } else { - cl = URLClassLoader.newInstance(urls, this.getClass().getClassLoader()); - } - - if (cl == null) { - return ResponseEntity.status(500).body("Failed to initialize the class loader"); - } - - // Load all dependent classes from libraries etc. - while (e.hasMoreElements()) { - JarEntry je = e.nextElement(); - if (je.isDirectory() || !je.getName().endsWith(".class")) { - continue; - } - String className = je.getName().substring(0, je.getName().length() - CLASS_LENGTH); - className = className.replace('/', '.'); - cl.loadClass(className); - } - - // Instantiate the function class - fn = (Function) cl.loadClass(entryPoint).newInstance(); - - } catch (MalformedURLException e) { - e.printStackTrace(); - return ResponseEntity.badRequest().body("Error loading the Function class file"); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - return ResponseEntity.badRequest().body("Error loading Function or dependent class"); - } catch (InstantiationException e) { - e.printStackTrace(); - return ResponseEntity.badRequest().body("Error creating a new instance of function class"); - } catch (IllegalAccessException e) { - e.printStackTrace(); - return ResponseEntity.badRequest().body("Error creating a new instance of function class"); - } catch (IOException e) { - e.printStackTrace(); - return ResponseEntity.badRequest().body("Error reading the JAR file"); - } finally { - try { - // cl.close(); - jarFile.close(); - } catch (IOException e) { - e.printStackTrace(); - return ResponseEntity.badRequest().body("Error closing the file while loading the class"); - } - } - long elapsedTime = System.nanoTime() - startTime; - logger.log(Level.INFO, "Specialize call done in: " + elapsedTime / 1000000 + " ms"); - return ResponseEntity.ok("Done"); - } - - public static void main(String[] args) throws Exception { - SpringApplication.run(Server.class, args); - } -} diff --git a/environments/nodejs/.gitignore b/environments/nodejs/.gitignore deleted file mode 100644 index c2658d7d..00000000 --- a/environments/nodejs/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules/ diff --git a/environments/nodejs/Dockerfile b/environments/nodejs/Dockerfile deleted file mode 100644 index f21526cb..00000000 --- a/environments/nodejs/Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -# A docker image for the func container. - -# default variant is the official alpine node image (much smaller than the standard image) -FROM node:8-alpine - -ARG NODE_ENV -ENV NODE_ENV $NODE_ENV - -RUN mkdir -p /usr/src/app -WORKDIR /usr/src/app - -COPY package.json /usr/src/app/ -RUN npm install && npm cache clean --force -COPY server.js /usr/src/app/server.js - -CMD [ "npm", "start" ] - -EXPOSE 8888 \ No newline at end of file diff --git a/environments/nodejs/Dockerfile-12.16 b/environments/nodejs/Dockerfile-12.16 deleted file mode 100644 index 9b32e18e..00000000 --- a/environments/nodejs/Dockerfile-12.16 +++ /dev/null @@ -1,15 +0,0 @@ -FROM node:12.16-alpine3.11 - -ARG NODE_ENV -ENV NODE_ENV $NODE_ENV - -RUN mkdir -p /usr/src/app -WORKDIR /usr/src/app - -COPY package.json /usr/src/app/ -RUN npm install && npm cache clean --force -COPY server.js /usr/src/app/server.js - -CMD [ "npm", "start" ] - -EXPOSE 8888 \ No newline at end of file diff --git a/environments/nodejs/Dockerfile-debian b/environments/nodejs/Dockerfile-debian deleted file mode 100644 index 76d5db33..00000000 --- a/environments/nodejs/Dockerfile-debian +++ /dev/null @@ -1,18 +0,0 @@ -# A docker image for the func container. - -# debian variant is the official standard node image (larger than the alpine image) -FROM node:8 - -ARG NODE_ENV -ENV NODE_ENV $NODE_ENV - -RUN mkdir -p /usr/src/app -WORKDIR /usr/src/app - -COPY package.json /usr/src/app/ -RUN npm install && npm cache clean --force -COPY server.js /usr/src/app/server.js - -CMD [ "npm", "start" ] - -EXPOSE 8888 \ No newline at end of file diff --git a/environments/nodejs/README.md b/environments/nodejs/README.md deleted file mode 100644 index e0ea6840..00000000 --- a/environments/nodejs/README.md +++ /dev/null @@ -1,47 +0,0 @@ -# Fission: NodeJS Environment - -This is the NodeJS environment for Fission. - -It's a Docker image containing a NodeJS runtime, along with a dynamic -loader. A few common dependencies are included in the package.json -file. - -Looking for ready-to-run examples? See the [NodeJS examples directory](../../examples/nodejs). - -## Customizing this image - -To add package dependencies, edit package.json to add what you need, -and rebuild this image (instructions below). - -You also may want to customize what's available to the function in its -request context. You can do this by editing `server.js` (see the -comment in that file about customizing request context). - -## Rebuilding and pushing the image - -You'll need access to a Docker registry to push the image: you can -sign up for Docker hub at hub.docker.com, or use registries from -gcr.io, quay.io, etc. Let's assume you're using a docker hub account -called USER. Build and push the image to the the registry: - -``` - docker build -t USER/nodejs-env . && docker push USER/nodejs-env -``` - -## Using the image in fission - -You can add this customized image to fission with "fission env -create": - -``` - fission env create --name nodejs --image USER/nodejs-env -``` - -Or, if you already have an environment, you can update its image: - -``` - fission env update --name nodejs --image USER/nodejs-env -``` - -After this, fission functions that have the env parameter set to the -same environment name as this command will use this environment. diff --git a/environments/nodejs/builder/Dockerfile b/environments/nodejs/builder/Dockerfile deleted file mode 100644 index e99cc6d4..00000000 --- a/environments/nodejs/builder/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -ARG BUILDER_IMAGE=fission/builder -FROM ${BUILDER_IMAGE} -# default variant is the official alpine node image (much smaller than the standard image) -FROM node:8-alpine - -ARG NODE_ENV -ENV NODE_ENV $NODE_ENV - -COPY --from=0 /builder /builder -ADD build.sh /usr/local/bin/build -RUN chmod +x /usr/local/bin/build diff --git a/environments/nodejs/builder/Dockerfile-12.16 b/environments/nodejs/builder/Dockerfile-12.16 deleted file mode 100644 index 26584814..00000000 --- a/environments/nodejs/builder/Dockerfile-12.16 +++ /dev/null @@ -1,11 +0,0 @@ -ARG BUILDER_IMAGE=fission/builder -FROM ${BUILDER_IMAGE} -# default variant is the official alpine node image (much smaller than the standard image) -FROM node:12.16-alpine3.11 - -ARG NODE_ENV -ENV NODE_ENV $NODE_ENV - -COPY --from=0 /builder /builder -ADD build.sh /usr/local/bin/build -RUN chmod +x /usr/local/bin/build diff --git a/environments/nodejs/builder/build.sh b/environments/nodejs/builder/build.sh deleted file mode 100755 index af57903a..00000000 --- a/environments/nodejs/builder/build.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -cd ${SRC_PKG} -npm install && cp -r ${SRC_PKG} ${DEPLOY_PKG} diff --git a/environments/nodejs/package.json b/environments/nodejs/package.json deleted file mode 100644 index 22c45d77..00000000 --- a/environments/nodejs/package.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "fission-nodejs-runtime", - "version": "0.1.0", - "author": "Soam Vasani", - "contributors": [ - { - "name": "Soam Vasani", - "email": "soamvasani+1@gmail.com" - }, - { - "name": "Gary Yeap", - "email": "contact@garyyeap.com" - } - ], - "description": "NodeJS run container for the fission framework", - "engines": { - "node": ">=7.6.0" - }, - "dependencies": { - "body-parser": "*", - "co": "~4.6.0", - "express": "*", - "minimist": "*", - "morgan": "*", - "mz": "~2.7.0", - "request": "^2.81.0", - "underscore": ">=1.8.3", - "request-promise-native": "^1.0.3" - } -} diff --git a/environments/nodejs/server.js b/environments/nodejs/server.js deleted file mode 100644 index e864aa3d..00000000 --- a/environments/nodejs/server.js +++ /dev/null @@ -1,168 +0,0 @@ -'use strict'; - -const fs = require('fs'); -const path = require('path'); -const process = require('process'); -const express = require('express'); -const app = express(); -const bodyParser = require('body-parser'); -const morgan = require('morgan'); -const argv = require('minimist')(process.argv.slice(1));// Command line opts - -if (!argv.port) { - argv.port = 8888; -} - -// To catch unhandled exceptions thrown by user code async callbacks, -// these exceptions cannot be catched by try-catch in user function invocation code below -process.on('uncaughtException', (err) => { - console.error(`Caught exception: ${err}`); -}); - -// User function. Starts out undefined. -let userFunction; - -function loadFunction(modulepath, funcname) { - // Read and load the code. It's placed there securely by the fission runtime. - try { - let startTime = process.hrtime(); - // support v1 codepath and v2 entrypoint like 'foo', '', 'index.hello' - let userFunction = funcname ? require(modulepath)[funcname] : require(modulepath); - let elapsed = process.hrtime(startTime); - console.log(`user code loaded in ${elapsed[0]}sec ${elapsed[1]/1000000}ms`); - return userFunction; - } catch(e) { - console.error(`user code load error: ${e}`); - return e; - } -} - -function withEnsureGeneric(func) { - return function(req, res) { - // Make sure we're a generic container. (No reuse of containers. - // Once specialized, the container remains specialized.) - if (userFunction) { - res.status(400).send("Not a generic container"); - return; - } - - func(req, res); - } -} - -function isFunction(func) { - return func && func.constructor && func.call && func.apply; -} - -function specializeV2(req, res) { - // for V2 entrypoint, 'filename.funcname' => ['filename', 'funcname'] - const entrypoint = req.body.functionName ? req.body.functionName.split('.') : []; - // for V2, filepath is dynamic path - const modulepath = path.join(req.body.filepath, entrypoint[0] || ''); - const result = loadFunction(modulepath, entrypoint[1]); - - if(isFunction(result)){ - userFunction = result; - res.status(202).send(); - } else { - res.status(500).send(JSON.stringify(result)); - } -} - -function specialize(req, res) { - // Specialize this server to a given user function. The user function - // is read from argv.codepath; it's expected to be placed there by the - // fission runtime. - // - const modulepath = argv.codepath || '/userfunc/user'; - - // Node resolves module paths according to a file's location. We load - // the file from argv.codepath, but tell users to put dependencies in - // the server's package.json; this means the function's dependencies - // are in /usr/src/app/node_modules. We could be smarter and have the - // function deps in the right place in argv.codepath; b ut for now we - // just symlink the function's node_modules to the server's - // node_modules. - fs.symlinkSync('/usr/src/app/node_modules', `${path.dirname(modulepath)}/node_modules`); - - const result = loadFunction(modulepath); - - if(isFunction(result)){ - userFunction = result; - res.status(202).send(); - } else { - res.status(500).send(JSON.stringify(result)); - } -} - - -// Request logger -app.use(morgan('combined')); - -let bodyParserLimit = process.env.BODY_PARSER_LIMIT || '1mb'; - -app.use(bodyParser.urlencoded({ extended: false, limit: bodyParserLimit})); -app.use(bodyParser.json({limit: bodyParserLimit})); -app.use(bodyParser.raw({limit: bodyParserLimit})); -app.use(bodyParser.text({ type : "text/*", limit: bodyParserLimit })); - -app.post('/specialize', withEnsureGeneric(specialize)); -app.post('/v2/specialize', withEnsureGeneric(specializeV2)); - -// Generic route -- all http requests go to the user function. -app.all('/', function (req, res) { - if (!userFunction) { - res.status(500).send("Generic container: no requests supported"); - return; - } - - const context = { - request: req, - response: res - // TODO: context should also have: URL template params, query string - }; - - function callback(status, body, headers) { - if (!status) - return; - if (headers) { - for (let name of Object.keys(headers)) { - res.set(name, headers[name]); - } - } - res.status(status).send(body); - } - - // - // Customizing the request context - // - // If you want to modify the context to add anything to it, - // you can do that here by adding properties to the context. - // - - if (userFunction.length <= 1) { // One or zero argument (context) - let result; - // Make sure their function returns a promise - if (userFunction.length === 0) { - result = Promise.resolve(userFunction()) - } else { - result = Promise.resolve(userFunction(context)) - } - result.then(function({status, body, headers}) { - callback(status, body, headers); - }).catch(function(err) { - console.log(`Function error: ${err}`); - callback(500, "Internal server error"); - }); - } else { // 2 arguments (context, callback) - try { - userFunction(context, callback); - } catch (err) { - console.log(`Function error: ${err}`); - callback(500, "Internal server error"); - } - } - -}); - -app.listen(argv.port); diff --git a/environments/nodejs/test/test.js b/environments/nodejs/test/test.js deleted file mode 100644 index 4d0791d4..00000000 --- a/environments/nodejs/test/test.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = async function (context) { - console.log("headers=", JSON.stringify(context.request.headers)); - console.log("body=", JSON.stringify(context.request.body)); - - return { - status: 200, - body: "Hello, world !\n" - }; -} diff --git a/environments/nodejs/test/test.sh b/environments/nodejs/test/test.sh deleted file mode 100755 index 49907e64..00000000 --- a/environments/nodejs/test/test.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh - -# TODO placeholder until we have better tests :) - -set +x -set -e - -DIR=$(dirname $0) - -echo "-- Starting server" -node $DIR/../server.js --codepath $DIR/test.js --port 8888 & -function cleanup() { - echo "-- Cleanup" - kill %1 -} -trap cleanup EXIT -sleep 2 - -echo "-- Specializing" -curl -f -X POST http://localhost:8888/specialize - -echo "-- Running user function" -curl -f -X GET http://localhost:8888 -curl -f -X POST http://localhost:8888 -curl -f -X PUT http://localhost:8888 -curl -f -X DELETE http://localhost:8888 -curl -f -X TRACE http://localhost:8888 -curl -f -X OPTIONS http://localhost:8888 - -# -I causes curl to make a HEAD request. -curl -f -I http://localhost:8888 diff --git a/environments/perl/Dockerfile b/environments/perl/Dockerfile deleted file mode 100644 index 12e67ce6..00000000 --- a/environments/perl/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM perl:latest - -RUN cpanm -n Twiggy Getopt::Args Dancer2 - -COPY server.pl /server.pl -WORKDIR / - -EXPOSE 8888 -ENTRYPOINT ["/server.pl"] diff --git a/environments/perl/README.md b/environments/perl/README.md deleted file mode 100644 index 6c6c2768..00000000 --- a/environments/perl/README.md +++ /dev/null @@ -1,38 +0,0 @@ -# Fission Perl environment - -This is an environment to execute perl code. - -It is implemented using the lightweight web application framework -[Dancer2](https://metacpan.org/pod/Dancer2) and the async I/O webserver -[Twiggy](https://metacpan.org/pod/Twiggy). - -Since Twiggy is implemented with [AnyEvent](https://metacpan.org/pod/AnyEvent), -you can write async code using AnyEvent in your function. - -Looking for ready-to-run examples? See the [Perl examples directory](../../examples/perl). - -## Build this image - -``` -docker build -t USER/perl . && docker push USER/perl -``` - -## Usage - -The function you upload is actually a perl package returning a coderef (see the -example). - -You can use other packages and add more subs, but only the coderef you returned -from the package is executed directly. - -Your main-function gets exactly one argument: the Dancer2 request object. You -may want to `use Dancer2` to get functions like `send_error`. - -## Example - -```perl -# hello.pm -return sub { - return 'Hello, Perl!'; -} -``` diff --git a/environments/perl/server.pl b/environments/perl/server.pl deleted file mode 100755 index 1145f998..00000000 --- a/environments/perl/server.pl +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env perl - -use utf8; -use strict; -use warnings; - -use Getopt::Args; -use Plack::Handler::Twiggy; - -opt codepath => ( - isa => 'Str', - default => '/userfunc/user', - comment => 'Path to the user code', -); - -opt port => ( - isa => 'Int', - default => 8888, - comment => 'Port to listen on', -); - -my $options = optargs(); - -{ - package App::Fission::Perl; - - use Dancer2; - - our $userfunc; - - post '/specialize' => sub { - if($userfunc) { - send_error('Not a generic container', 400); - } - - $userfunc = require($options->{codepath}); - return ''; - }; - - any '/' => sub { - return $userfunc ? $userfunc->(request) : send_error('Not yet specialized', 500); - }; -} - -my $handler = Plack::Handler::Twiggy->new(port => $options->{port}); -$handler->run(App::Fission::Perl->to_app); diff --git a/environments/php7/Dockerfile b/environments/php7/Dockerfile deleted file mode 100644 index 253bf65b..00000000 --- a/environments/php7/Dockerfile +++ /dev/null @@ -1,75 +0,0 @@ -FROM php:7.3-alpine - -ENV PATH="/root/.composer/vendor/bin:${PATH}" \ - COMPOSER_ALLOW_SUPERUSER=1 - -RUN echo 'http://dl-4.alpinelinux.org/alpine/edge/testing' >> /etc/apk/repositories \ - && apk --no-cache add \ - git \ - curl \ - curl-dev \ - libcurl \ - zlib-dev \ - freetype-dev \ - jpeg-dev \ - libjpeg-turbo-dev \ - postgresql-dev \ - libmcrypt-dev \ - libpng-dev \ - icu-dev \ - gettext-dev \ - vim \ - libxml2-dev \ - freetype-dev \ - libzip-dev \ - unzip \ - libc6-compat \ - openssl \ - gcc \ - autoconf \ - make \ - libc-dev - -RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ - -# Install useful extensions -RUN docker-php-ext-install \ - opcache \ - bcmath \ - ctype \ - curl \ - dom \ - iconv \ - fileinfo \ - gd \ - gettext \ - intl \ - json \ - mysqli \ - pgsql \ - pcntl \ - pdo \ - ftp \ - pdo_mysql \ - pdo_pgsql \ - phar \ - simplexml \ - xmlrpc \ - zip - -RUN pecl install \ - mcrypt-1.0.2 -RUN docker-php-ext-enable \ - mcrypt - -RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer - -COPY . /app -WORKDIR /app - -RUN composer install - -EXPOSE 8888 - -ENTRYPOINT ["php"] -CMD ["server.php"] diff --git a/environments/php7/README.md b/environments/php7/README.md deleted file mode 100644 index c4de10a4..00000000 --- a/environments/php7/README.md +++ /dev/null @@ -1,58 +0,0 @@ -# Fission: PHP Environment - -This is the PHP environment for Fission. - -It's a Docker image containing a PHP 7.3 runtime. This image use php:7.3-cli base image with the built-in PHP server - -This environment does not force you to use a specific class or create a main function. - -A few common extensions are included : -- curl -- gd -- json -- mcrypt -- PDO (pdo_mysql, pdo_pgsql, pdo_sqlite) -- OPcache -- ftp -- iconv -- phar -- mysqli -- pgsql -- SimpleXML -- xmlrpc -- zip - -Looking for ready-to-run examples? See the [PHP examples directory](../../examples/php). - -## Customizing this image - -To add other extensions or packages(composer.json) you need to edit the Dockerfile and rebuild this image (instructions below). - -## Rebuilding and pushing the image - -You'll need access to a Docker registry to push the image: you can -sign up for Docker hub at hub.docker.com, or use registries from -gcr.io, quay.io, etc. Let's assume you're using a docker hub account -called USER. Build and push the image to the the registry: - -``` - docker build -t USER/php7-env . && docker push USER/php7-env -``` - -## Using the image in fission - -You can add this customized image to fission with "fission env -create": - -``` - fission env create --name php7 --image USER/php7-env -``` - -Or, if you already have an environment, you can update its image: - -``` - fission env update --name php7 --image USER/php7-env -``` - -After this, fission functions that have the env parameter set to the -same environment name as this command will use this environment. diff --git a/environments/php7/builder/Dockerfile b/environments/php7/builder/Dockerfile deleted file mode 100644 index 49b31be6..00000000 --- a/environments/php7/builder/Dockerfile +++ /dev/null @@ -1,71 +0,0 @@ -ARG BUILDER_IMAGE=fission/builder -FROM ${BUILDER_IMAGE} - -FROM php:7.3-alpine - -ENV PATH="/root/.composer/vendor/bin:${PATH}" \ - COMPOSER_ALLOW_SUPERUSER=1 - -RUN echo 'http://dl-4.alpinelinux.org/alpine/edge/testing' >> /etc/apk/repositories \ - && apk --no-cache add \ - git \ - curl \ - curl-dev \ - libcurl \ - zlib-dev \ - freetype-dev \ - jpeg-dev \ - libjpeg-turbo-dev \ - postgresql-dev \ - libmcrypt-dev \ - libpng-dev \ - icu-dev \ - gettext-dev \ - vim \ - libxml2-dev \ - freetype-dev \ - libzip-dev \ - unzip \ - libc6-compat \ - openssl \ - gcc \ - autoconf \ - make \ - libc-dev - -RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ - -# Install useful extensions -RUN docker-php-ext-install \ - opcache \ - bcmath \ - ctype \ - curl \ - dom \ - iconv \ - fileinfo \ - gd \ - gettext \ - intl \ - json \ - mysqli \ - pgsql \ - pcntl \ - pdo \ - ftp \ - pdo_mysql \ - pdo_pgsql \ - phar \ - simplexml \ - xmlrpc \ - zip - -RUN pecl install \ - mcrypt-1.0.2 -RUN docker-php-ext-enable \ - mcrypt - -RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer - -COPY --from=0 /builder /builder -COPY defaultBuildCmd /usr/local/bin/build diff --git a/environments/php7/builder/defaultBuildCmd b/environments/php7/builder/defaultBuildCmd deleted file mode 100755 index 2fa2d4a1..00000000 --- a/environments/php7/builder/defaultBuildCmd +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -set -euxo pipefail - -if [ -f ${SRC_PKG}/composer.json ] -then - cd ${SRC_PKG} - composer install --no-interaction -fi -cp -r ${SRC_PKG} ${DEPLOY_PKG} diff --git a/environments/php7/composer.json b/environments/php7/composer.json deleted file mode 100644 index ebbcef45..00000000 --- a/environments/php7/composer.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "autoload": { - "psr-4": { - "PHPEnv\\": "src/" - } - }, - "require": { - "monolog/monolog": "^1.22", - "react/http": "^0.8.4", - "nikic/php-parser": "^4.2" - } -} diff --git a/environments/php7/composer.lock b/environments/php7/composer.lock deleted file mode 100644 index 71691fe3..00000000 --- a/environments/php7/composer.lock +++ /dev/null @@ -1,769 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", - "This file is @generated automatically" - ], - "hash": "5a681a6e3133f56dde5a45b087dbfa6f", - "content-hash": "d48759c44a5d6d8f97f3f2f26c8a5de5", - "packages": [ - { - "name": "evenement/evenement", - "version": "v3.0.1", - "source": { - "type": "git", - "url": "https://github.com/igorw/evenement.git", - "reference": "531bfb9d15f8aa57454f5f0285b18bec903b8fb7" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/igorw/evenement/zipball/531bfb9d15f8aa57454f5f0285b18bec903b8fb7", - "reference": "531bfb9d15f8aa57454f5f0285b18bec903b8fb7", - "shasum": "" - }, - "require": { - "php": ">=7.0" - }, - "require-dev": { - "phpunit/phpunit": "^6.0" - }, - "type": "library", - "autoload": { - "psr-0": { - "Evenement": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Igor Wiedler", - "email": "igor@wiedler.ch" - } - ], - "description": "Événement is a very simple event dispatching library for PHP", - "keywords": [ - "event-dispatcher", - "event-emitter" - ], - "time": "2017-07-23 21:35:13" - }, - { - "name": "monolog/monolog", - "version": "1.24.0", - "source": { - "type": "git", - "url": "https://github.com/Seldaek/monolog.git", - "reference": "bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266", - "reference": "bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266", - "shasum": "" - }, - "require": { - "php": ">=5.3.0", - "psr/log": "~1.0" - }, - "provide": { - "psr/log-implementation": "1.0.0" - }, - "require-dev": { - "aws/aws-sdk-php": "^2.4.9 || ^3.0", - "doctrine/couchdb": "~1.0@dev", - "graylog2/gelf-php": "~1.0", - "jakub-onderka/php-parallel-lint": "0.9", - "php-amqplib/php-amqplib": "~2.4", - "php-console/php-console": "^3.1.3", - "phpunit/phpunit": "~4.5", - "phpunit/phpunit-mock-objects": "2.3.0", - "ruflin/elastica": ">=0.90 <3.0", - "sentry/sentry": "^0.13", - "swiftmailer/swiftmailer": "^5.3|^6.0" - }, - "suggest": { - "aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB", - "doctrine/couchdb": "Allow sending log messages to a CouchDB server", - "ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)", - "ext-mongo": "Allow sending log messages to a MongoDB server", - "graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server", - "mongodb/mongodb": "Allow sending log messages to a MongoDB server via PHP Driver", - "php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib", - "php-console/php-console": "Allow sending log messages to Google Chrome", - "rollbar/rollbar": "Allow sending log messages to Rollbar", - "ruflin/elastica": "Allow sending log messages to an Elastic Search server", - "sentry/sentry": "Allow sending log messages to a Sentry server" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Monolog\\": "src/Monolog" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jordi Boggiano", - "email": "j.boggiano@seld.be", - "homepage": "http://seld.be" - } - ], - "description": "Sends your logs to files, sockets, inboxes, databases and various web services", - "homepage": "http://github.com/Seldaek/monolog", - "keywords": [ - "log", - "logging", - "psr-3" - ], - "time": "2018-11-05 09:00:11" - }, - { - "name": "nikic/php-parser", - "version": "v4.2.1", - "source": { - "type": "git", - "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "5221f49a608808c1e4d436df32884cbc1b821ac0" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/5221f49a608808c1e4d436df32884cbc1b821ac0", - "reference": "5221f49a608808c1e4d436df32884cbc1b821ac0", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "php": ">=7.0" - }, - "require-dev": { - "phpunit/phpunit": "^6.5 || ^7.0" - }, - "bin": [ - "bin/php-parse" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.2-dev" - } - }, - "autoload": { - "psr-4": { - "PhpParser\\": "lib/PhpParser" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Nikita Popov" - } - ], - "description": "A PHP parser written in PHP", - "keywords": [ - "parser", - "php" - ], - "time": "2019-02-16 20:54:15" - }, - { - "name": "psr/http-message", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/php-fig/http-message.git", - "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", - "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Http\\Message\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for HTTP messages", - "homepage": "https://github.com/php-fig/http-message", - "keywords": [ - "http", - "http-message", - "psr", - "psr-7", - "request", - "response" - ], - "time": "2016-08-06 14:39:51" - }, - { - "name": "psr/log", - "version": "1.1.0", - "source": { - "type": "git", - "url": "https://github.com/php-fig/log.git", - "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", - "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Log\\": "Psr/Log/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for logging libraries", - "homepage": "https://github.com/php-fig/log", - "keywords": [ - "log", - "psr", - "psr-3" - ], - "time": "2018-11-20 15:27:04" - }, - { - "name": "react/cache", - "version": "v0.5.0", - "source": { - "type": "git", - "url": "https://github.com/reactphp/cache.git", - "reference": "7d7da7fb7574d471904ba357b39bbf110ccdbf66" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/cache/zipball/7d7da7fb7574d471904ba357b39bbf110ccdbf66", - "reference": "7d7da7fb7574d471904ba357b39bbf110ccdbf66", - "shasum": "" - }, - "require": { - "php": ">=5.3.0", - "react/promise": "~2.0|~1.1" - }, - "require-dev": { - "phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35" - }, - "type": "library", - "autoload": { - "psr-4": { - "React\\Cache\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Async, Promise-based cache interface for ReactPHP", - "keywords": [ - "cache", - "caching", - "promise", - "reactphp" - ], - "time": "2018-06-25 12:52:40" - }, - { - "name": "react/dns", - "version": "v0.4.16", - "source": { - "type": "git", - "url": "https://github.com/reactphp/dns.git", - "reference": "0a0bedfec72b38406413c6ea01e1c015bd0bf72b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/dns/zipball/0a0bedfec72b38406413c6ea01e1c015bd0bf72b", - "reference": "0a0bedfec72b38406413c6ea01e1c015bd0bf72b", - "shasum": "" - }, - "require": { - "php": ">=5.3.0", - "react/cache": "^0.5 || ^0.4 || ^0.3", - "react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3.5", - "react/promise": "^2.1 || ^1.2.1", - "react/promise-timer": "^1.2", - "react/stream": "^1.0 || ^0.7 || ^0.6 || ^0.5 || ^0.4.5" - }, - "require-dev": { - "clue/block-react": "^1.2", - "phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35" - }, - "type": "library", - "autoload": { - "psr-4": { - "React\\Dns\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Async DNS resolver for ReactPHP", - "keywords": [ - "async", - "dns", - "dns-resolver", - "reactphp" - ], - "time": "2018-11-11 11:21:13" - }, - { - "name": "react/event-loop", - "version": "v1.1.0", - "source": { - "type": "git", - "url": "https://github.com/reactphp/event-loop.git", - "reference": "a0ecac955c67b57c40fe4a1b88a7cca1b58c982d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/event-loop/zipball/a0ecac955c67b57c40fe4a1b88a7cca1b58c982d", - "reference": "a0ecac955c67b57c40fe4a1b88a7cca1b58c982d", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "require-dev": { - "phpunit/phpunit": "^7.0 || ^6.4 || ^5.7 || ^4.8.35" - }, - "suggest": { - "ext-event": "~1.0 for ExtEventLoop", - "ext-pcntl": "For signal handling support when using the StreamSelectLoop", - "ext-uv": "* for ExtUvLoop" - }, - "type": "library", - "autoload": { - "psr-4": { - "React\\EventLoop\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "ReactPHP's core reactor event loop that libraries can use for evented I/O.", - "keywords": [ - "asynchronous", - "event-loop" - ], - "time": "2019-02-07 16:19:49" - }, - { - "name": "react/http", - "version": "v0.8.4", - "source": { - "type": "git", - "url": "https://github.com/reactphp/http.git", - "reference": "b29ab96557ac5c53e738fcb26f73f631a3f81f1a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/http/zipball/b29ab96557ac5c53e738fcb26f73f631a3f81f1a", - "reference": "b29ab96557ac5c53e738fcb26f73f631a3f81f1a", - "shasum": "" - }, - "require": { - "evenement/evenement": "^3.0 || ^2.0 || ^1.0", - "php": ">=5.3.0", - "react/promise": "^2.3 || ^1.2.1", - "react/promise-stream": "^1.1", - "react/socket": "^1.0 || ^0.8.3", - "react/stream": "^1.0 || ^0.7.1", - "ringcentral/psr7": "^1.2" - }, - "require-dev": { - "clue/block-react": "^1.1", - "phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35" - }, - "type": "library", - "autoload": { - "psr-4": { - "React\\Http\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Event-driven, streaming plaintext HTTP and secure HTTPS server for ReactPHP", - "keywords": [ - "event-driven", - "http", - "https", - "reactphp", - "server", - "streaming" - ], - "time": "2019-01-16 07:26:32" - }, - { - "name": "react/promise", - "version": "v2.7.1", - "source": { - "type": "git", - "url": "https://github.com/reactphp/promise.git", - "reference": "31ffa96f8d2ed0341a57848cbb84d88b89dd664d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/promise/zipball/31ffa96f8d2ed0341a57848cbb84d88b89dd664d", - "reference": "31ffa96f8d2ed0341a57848cbb84d88b89dd664d", - "shasum": "" - }, - "require": { - "php": ">=5.4.0" - }, - "require-dev": { - "phpunit/phpunit": "~4.8" - }, - "type": "library", - "autoload": { - "psr-4": { - "React\\Promise\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jan Sorgalla", - "email": "jsorgalla@gmail.com" - } - ], - "description": "A lightweight implementation of CommonJS Promises/A for PHP", - "keywords": [ - "promise", - "promises" - ], - "time": "2019-01-07 21:25:54" - }, - { - "name": "react/promise-stream", - "version": "v1.1.1", - "source": { - "type": "git", - "url": "https://github.com/reactphp/promise-stream.git", - "reference": "00e269d611e9c9a29356aef64c07f7e513e73dc9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/promise-stream/zipball/00e269d611e9c9a29356aef64c07f7e513e73dc9", - "reference": "00e269d611e9c9a29356aef64c07f7e513e73dc9", - "shasum": "" - }, - "require": { - "php": ">=5.3", - "react/promise": "^2.1 || ^1.2", - "react/stream": "^1.0 || ^0.7 || ^0.6 || ^0.5 || ^0.4 || ^0.3" - }, - "require-dev": { - "clue/block-react": "^1.0", - "phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35", - "react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3", - "react/promise-timer": "^1.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "React\\Promise\\Stream\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christian Lück", - "email": "christian@lueck.tv" - } - ], - "description": "The missing link between Promise-land and Stream-land for ReactPHP", - "homepage": "https://github.com/reactphp/promise-stream", - "keywords": [ - "Buffer", - "async", - "promise", - "reactphp", - "stream", - "unwrap" - ], - "time": "2017-12-22 12:02:05" - }, - { - "name": "react/promise-timer", - "version": "v1.5.0", - "source": { - "type": "git", - "url": "https://github.com/reactphp/promise-timer.git", - "reference": "a11206938ca2394dc7bb368f5da25cd4533fa603" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/promise-timer/zipball/a11206938ca2394dc7bb368f5da25cd4533fa603", - "reference": "a11206938ca2394dc7bb368f5da25cd4533fa603", - "shasum": "" - }, - "require": { - "php": ">=5.3", - "react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3.5", - "react/promise": "^2.7.0 || ^1.2.1" - }, - "require-dev": { - "phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35" - }, - "type": "library", - "autoload": { - "psr-4": { - "React\\Promise\\Timer\\": "src/" - }, - "files": [ - "src/functions.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christian Lück", - "email": "christian@lueck.tv" - } - ], - "description": "A trivial implementation of timeouts for Promises, built on top of ReactPHP.", - "homepage": "https://github.com/reactphp/promise-timer", - "keywords": [ - "async", - "event-loop", - "promise", - "reactphp", - "timeout", - "timer" - ], - "time": "2018-06-13 16:45:37" - }, - { - "name": "react/socket", - "version": "v1.2.0", - "source": { - "type": "git", - "url": "https://github.com/reactphp/socket.git", - "reference": "23b7372bb25cea934f6124f5bdac34e30161959e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/socket/zipball/23b7372bb25cea934f6124f5bdac34e30161959e", - "reference": "23b7372bb25cea934f6124f5bdac34e30161959e", - "shasum": "" - }, - "require": { - "evenement/evenement": "^3.0 || ^2.0 || ^1.0", - "php": ">=5.3.0", - "react/dns": "^0.4.13", - "react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3.5", - "react/promise": "^2.6.0 || ^1.2.1", - "react/promise-timer": "^1.4.0", - "react/stream": "^1.1" - }, - "require-dev": { - "clue/block-react": "^1.2", - "phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35" - }, - "type": "library", - "autoload": { - "psr-4": { - "React\\Socket\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Async, streaming plaintext TCP/IP and secure TLS socket server and client connections for ReactPHP", - "keywords": [ - "Connection", - "Socket", - "async", - "reactphp", - "stream" - ], - "time": "2019-01-07 14:10:13" - }, - { - "name": "react/stream", - "version": "v1.1.0", - "source": { - "type": "git", - "url": "https://github.com/reactphp/stream.git", - "reference": "50426855f7a77ddf43b9266c22320df5bf6c6ce6" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/stream/zipball/50426855f7a77ddf43b9266c22320df5bf6c6ce6", - "reference": "50426855f7a77ddf43b9266c22320df5bf6c6ce6", - "shasum": "" - }, - "require": { - "evenement/evenement": "^3.0 || ^2.0 || ^1.0", - "php": ">=5.3.8", - "react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3.5" - }, - "require-dev": { - "clue/stream-filter": "~1.2", - "phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35" - }, - "type": "library", - "autoload": { - "psr-4": { - "React\\Stream\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Event-driven readable and writable streams for non-blocking I/O in ReactPHP", - "keywords": [ - "event-driven", - "io", - "non-blocking", - "pipe", - "reactphp", - "readable", - "stream", - "writable" - ], - "time": "2019-01-01 16:15:09" - }, - { - "name": "ringcentral/psr7", - "version": "1.2.2", - "source": { - "type": "git", - "url": "https://github.com/ringcentral/psr7.git", - "reference": "dcd84bbb49b96c616d1dcc8bfb9bef3f2cd53d1c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/ringcentral/psr7/zipball/dcd84bbb49b96c616d1dcc8bfb9bef3f2cd53d1c", - "reference": "dcd84bbb49b96c616d1dcc8bfb9bef3f2cd53d1c", - "shasum": "" - }, - "require": { - "php": ">=5.3", - "psr/http-message": "~1.0" - }, - "provide": { - "psr/http-message-implementation": "1.0" - }, - "require-dev": { - "phpunit/phpunit": "~4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "psr-4": { - "RingCentral\\Psr7\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - } - ], - "description": "PSR-7 message implementation", - "keywords": [ - "http", - "message", - "stream", - "uri" - ], - "time": "2018-01-15 21:00:49" - } - ], - "packages-dev": [], - "aliases": [], - "minimum-stability": "stable", - "stability-flags": [], - "prefer-stable": false, - "prefer-lowest": false, - "platform": [], - "platform-dev": [] -} diff --git a/environments/php7/server.php b/environments/php7/server.php deleted file mode 100644 index 48c17bc0..00000000 --- a/environments/php7/server.php +++ /dev/null @@ -1,91 +0,0 @@ -pushHandler(new StreamHandler('php://stdout', Logger::DEBUG)); - - -$loop = React\EventLoop\Factory::create(); - -$server = new Server(function (ServerRequestInterface $request) use (&$codePath, &$userFunction, $logger) { - $path = $request->getUri()->getPath(); - $method = $request->getMethod(); - - if ('/specialize' === $path && 'POST' === $method) { - $codePath = V1_CODEPATH; - $userFunction = V1_USER_FUNCTION; - - return new Response(201); - } - - if ('/v2/specialize' === $path && 'POST' === $method) { - $body = json_decode($request->getBody()->getContents(), true); - $filepath = $body['filepath']; - list ($moduleName, $userFunction) = explode(HANDLER_DIVIDER, $body['functionName']); - if (true === is_dir($filepath)) { - $codePath = $filepath . DIRECTORY_SEPARATOR . $moduleName; - - } else { - $codePath = $filepath; - } - - return new Response(201); - } - if ('/' === $path) { - if (null === $codePath) { - $logger->error("$codePath not found"); - return new Response(500, [], 'Generic container: no requests supported'); - } - - ob_start(); - - if (!file_exists($codePath)) { - $logger->error("$codePath not found"); - return new Response(500, [], "$codePath not found"); - } - - $parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); - try { - $parser->parse(file_get_contents($codePath)); - } catch (Throwable $throwable) { - $logger->error($codePath . ' - ' . $throwable->getMessage()); - return new Response(500, [], $codePath . ' - ' . $throwable->getMessage()); - } - - require_once $codePath; - - //If the function as an handler class it will be called with request, response and logger - if (function_exists($userFunction)) { - $response = new Response(); - ob_end_clean(); - $userFunction(['request' =>$request, 'response' => $response, 'logger' => $logger]); - return $response; - } - //backwards compatibility: php code didn't have userFunction, i will return the content - $bodyRowContent = ob_get_contents(); - ob_end_clean(); - - return new Response(200, [], $bodyRowContent); - } - - return new Response(404, ['Content-Type' => 'text/plain'], 'Not found'); -}); - -$socket = new React\Socket\Server('0.0.0.0:8888', $loop); -$server->listen($socket); - -$loop->run(); diff --git a/environments/python/Dockerfile b/environments/python/Dockerfile deleted file mode 100644 index c7b6d4e2..00000000 --- a/environments/python/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM alpine - -WORKDIR /app - -RUN apk add --update gcc && \ - apk upgrade --no-cache && \ - apk add --no-cache python3 python3-dev build-base libev-dev libffi-dev bash py-pip && \ - pip3 install --upgrade pip && \ - rm -r /root/.cache - -COPY requirements.txt /app -RUN pip3 install -r requirements.txt - -COPY . /app - -ENTRYPOINT ["python3"] -CMD ["server.py"] diff --git a/environments/python/Dockerfile-2.7 b/environments/python/Dockerfile-2.7 deleted file mode 100644 index 0eab8d3e..00000000 --- a/environments/python/Dockerfile-2.7 +++ /dev/null @@ -1,15 +0,0 @@ -FROM alpine:3.5 - -WORKDIR /app - -RUN apk add --no-cache python python-dev build-base py-pip libev-dev libffi-dev && \ - pip install --upgrade pip && \ - rm -r /root/.cache - -COPY requirements.txt /app -RUN pip install -r requirements.txt - -COPY . /app - -ENTRYPOINT ["python"] -CMD ["server.py"] diff --git a/environments/python/README.md b/environments/python/README.md deleted file mode 100644 index 708b728c..00000000 --- a/environments/python/README.md +++ /dev/null @@ -1,67 +0,0 @@ -# Fission: Python Environment - -This is the Python environment for Fission. - -It's a Docker image containing a Python 3.5 runtime, along with a -dynamic loader. A few common dependencies are included in the -requirements.txt file. - -Looking for ready-to-run examples? See the [Python examples directory](../../examples/python). - -## Customizing this image - -To add package dependencies, edit requirements.txt to add what you -need, and rebuild this image (instructions below). - -You also may want to customize what's available to the function in its -request context. You can do this by editing server.py (see the -comment in that file about customizing request context). - -## Rebuilding and pushing the image - -You'll need access to a Docker registry to push the image: you can -sign up for Docker hub at hub.docker.com, or use registries from -gcr.io, quay.io, etc. Let's assume you're using a docker hub account -called USER. Build and push the image to the the registry: - -``` - docker build -t USER/python-env . && docker push USER/python-env -``` - -## Using the image in fission - -You can add this customized image to fission with "fission env -create": - -``` - fission env create --name python --image USER/python-env -``` - -Or, if you already have an environment, you can update its image: - -``` - fission env update --name python --image USER/python-env -``` - -After this, fission functions that have the env parameter set to the -same environment name as this command will use this environment. - -## Web Server Framework - -Python environment build and start a WSGI server, to support high HTTP -traffic. As it is applied in different use cases, this provides two server -frameworks: `bjoern` and `gevent`. They all support high concurrency request. - -`bjoern` has good performance on RPS, to be ideal for most light resource -utilization cases. - -`gevent` is a good supplement because of its internal multi-threads. It -supports heavy resource load functions, with well distribution of response -time. - -Python environment pod remains `bjoern` framework by default. And it runs `gevent` -framework by setting the container environment `WSGI_FRAMEWORK` value to `GEVENT`. - -The environment value is configured normally in two ways. One way is to set in Dockerfile -and build it into image. The other way is to set in Kubernetes deployment spec during -pod running and restart it. diff --git a/environments/python/builder/Dockerfile b/environments/python/builder/Dockerfile deleted file mode 100644 index baa7d842..00000000 --- a/environments/python/builder/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -ARG BUILDER_IMAGE=fission/builder:latest -FROM ${BUILDER_IMAGE} - -RUN apk update -RUN apk add --no-cache python3 python3-dev build-base gcc bash py-pip -RUN pip3 install --upgrade pip -RUN rm -r /root/.cache - -ADD defaultBuildCmd /usr/local/bin/build - -EXPOSE 8001 diff --git a/environments/python/builder/defaultBuildCmd b/environments/python/builder/defaultBuildCmd deleted file mode 100755 index 1e40ed6c..00000000 --- a/environments/python/builder/defaultBuildCmd +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -set -euxo pipefail - -if [ -f ${SRC_PKG}/requirements.txt ] -then - pip3 install -r ${SRC_PKG}/requirements.txt -t ${SRC_PKG} -fi -cp -r ${SRC_PKG} ${DEPLOY_PKG} \ No newline at end of file diff --git a/environments/python/requirements.txt b/environments/python/requirements.txt deleted file mode 100644 index ea364a8f..00000000 --- a/environments/python/requirements.txt +++ /dev/null @@ -1,9 +0,0 @@ -flask ~= 1.0.4 -bjoern -httplib2 -python-dateutil -requests==2.20.0 -redis -hiredis -gevent -sentry-sdk[flask] diff --git a/environments/python/server.py b/environments/python/server.py deleted file mode 100644 index 92cb420d..00000000 --- a/environments/python/server.py +++ /dev/null @@ -1,143 +0,0 @@ -#!/usr/bin/env python -import importlib -import logging -import os -import sys - -from flask import Flask, request, abort, g -from gevent.pywsgi import WSGIServer -import bjoern -import sentry_sdk -from sentry_sdk.integrations.flask import FlaskIntegration - - -IS_PY2 = (sys.version_info.major == 2) -SENTRY_DSN = os.environ.get('SENTRY_DSN', None) -SENTRY_RELEASE = os.environ.get('SENTRY_RELEASE', None) - -if SENTRY_DSN: - params = { - 'dsn': SENTRY_DSN, - 'integrations': [FlaskIntegration()] - } - if SENTRY_RELEASE: - params['release'] = SENTRY_RELEASE - sentry_sdk.init(**params) - - -def import_src(path): - if IS_PY2: - import imp - return imp.load_source('mod', path) - else: - # the imp module is deprecated in Python3. use importlib instead. - return importlib.machinery.SourceFileLoader('mod', path).load_module() - - -class FuncApp(Flask): - def __init__(self, name, loglevel=logging.DEBUG): - super(FuncApp, self).__init__(name) - - # init the class members - self.userfunc = None - self.root = logging.getLogger() - self.ch = logging.StreamHandler(sys.stdout) - - # - # Logging setup. TODO: Loglevel hard-coded for now. We could allow - # functions/routes to override this somehow; or we could create - # separate dev vs. prod environments. - # - self.root.setLevel(loglevel) - self.ch.setLevel(loglevel) - self.ch.setFormatter(logging.Formatter( - '%(asctime)s - %(levelname)s - %(message)s')) - self.logger.addHandler(self.ch) - - # - # Register the routers - # - @self.route('/specialize', methods=['POST']) - def load(): - self.logger.info('/specialize called') - # load user function from codepath - self.userfunc = import_src('/userfunc/user').main - return "" - - @self.route('/v2/specialize', methods=['POST']) - def loadv2(): - body = request.get_json() - filepath = body['filepath'] - handler = body['functionName'] - self.logger.info('/v2/specialize called with filepath = "{}" handler = "{}"'.format(filepath, handler)) - - # handler looks like `path.to.module.function` - parts = handler.rsplit(".", 1) - if len(handler) == 0: - # default to main.main if entrypoint wasn't provided - moduleName = 'main' - funcName = 'main' - elif len(parts) == 1: - moduleName = 'main' - funcName = parts[0] - else: - moduleName = parts[0] - funcName = parts[1] - self.logger.debug('moduleName = "{}" funcName = "{}"'.format(moduleName, funcName)) - - # check whether the destination is a directory or a file - if os.path.isdir(filepath): - # add package directory path into module search path - sys.path.append(filepath) - - self.logger.debug('__package__ = "{}"'.format(__package__)) - if __package__: - mod = importlib.import_module(moduleName, __package__) - else: - mod = importlib.import_module(moduleName) - - else: - # load source from destination python file - mod = import_src(filepath) - - # load user function from module - self.userfunc = getattr(mod, funcName) - - return "" - - @self.route('/healthz', methods=['GET']) - def healthz(): - return "", 200 - - @self.route('/', methods=['GET', 'POST', 'PUT', 'HEAD', 'OPTIONS', - 'DELETE']) - def f(): - if self.userfunc is None: - print("Generic container: no requests supported") - abort(500) - # - # Customizing the request context - # - # If you want to pass something to the function, you can - # add it to 'g': - # g.myKey = myValue - # - # And the user func can then access that - # (after doing a"from flask import g"). - - return self.userfunc() - - -app = FuncApp(__name__, logging.DEBUG) - -# -# TODO: this starts the built-in server, which isn't the most -# efficient. We should use something better. -# -if os.environ.get("WSGI_FRAMEWORK") == "GEVENT": - app.logger.info("Starting gevent based server") - svc = WSGIServer(('0.0.0.0', 8888), app) - svc.serve_forever() -else: - app.logger.info("Starting bjoern based server") - bjoern.run(app, '0.0.0.0', 8888, reuse_port=True) diff --git a/environments/ruby/Dockerfile b/environments/ruby/Dockerfile deleted file mode 100644 index 28bf0dce..00000000 --- a/environments/ruby/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM ruby:2.6.1-alpine3.9 - -RUN apk update -RUN apk add --no-cache build-base - -COPY . /app -WORKDIR /app -RUN bundle install - -ENTRYPOINT ["ruby"] -CMD ["server.rb"] diff --git a/environments/ruby/Gemfile b/environments/ruby/Gemfile deleted file mode 100644 index 068569a8..00000000 --- a/environments/ruby/Gemfile +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true -source "https://rubygems.org" - -gem "rack" -gem "thin" diff --git a/environments/ruby/Gemfile.lock b/environments/ruby/Gemfile.lock deleted file mode 100644 index 36b2444e..00000000 --- a/environments/ruby/Gemfile.lock +++ /dev/null @@ -1,20 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - daemons (1.3.1) - eventmachine (1.2.7) - rack (2.1.4) - thin (1.7.2) - daemons (~> 1.0, >= 1.0.9) - eventmachine (~> 1.0, >= 1.0.4) - rack (>= 1, < 3) - -PLATFORMS - ruby - -DEPENDENCIES - rack - thin - -BUNDLED WITH - 1.15.1 diff --git a/environments/ruby/README.md b/environments/ruby/README.md deleted file mode 100644 index 9a605bae..00000000 --- a/environments/ruby/README.md +++ /dev/null @@ -1,54 +0,0 @@ -# Fission: Ruby Environment - -This is the Ruby environment for Fission. - -It's a Docker image containing a Ruby 2.6.1 runtime. The image uses -Rack with WEBrick to host the internal web server. - -The environment works via convention where you create a Ruby method -called `handler` with a single optional argument, a `Fission::Context` -object. - -The `Fission::Context` object gives access to the Rack env, a -request object, and a logger. Please see `fission/context.rb` for the -public api. - -The `Fission::Request` object is a subclass of `Rack::Request` and -provides access to parameters and headers. See `fission/request.rb` -for the public api. - -Looking for ready-to-run examples? See the [Ruby examples directory](../../examples/ruby). - -## Customizing this image - -To add package dependencies, edit Gemfile to add what you -need, and rebuild this image (instructions below). - -## Rebuilding and pushing the image - -You'll need access to a Docker registry to push the image: you can -sign up for Docker hub at hub.docker.com, or use registries from -gcr.io, quay.io, etc. Let's assume you're using a docker hub account -called USER. Build and push the image to the the registry: - -``` - docker build -t USER/ruby-env . && docker push USER/ruby-env -``` - -## Using the image in fission - -You can add this customized image to fission with "fission env -create": - -``` - fission env create --name ruby --image USER/ruby-env -``` - -Or, if you already have an environment, you can update its image: - -``` - fission env update --name ruby --image USER/ruby-env -``` - -After this, fission functions that have the env parameter set to the -same environment name as this command will use this environment. diff --git a/environments/ruby/builder/Dockerfile b/environments/ruby/builder/Dockerfile deleted file mode 100644 index 9f73afa7..00000000 --- a/environments/ruby/builder/Dockerfile +++ /dev/null @@ -1,12 +0,0 @@ -ARG BUILDER_IMAGE=fission/builder:latest -FROM ${BUILDER_IMAGE} - -FROM ruby:2.6.1-alpine3.9 -COPY --from=0 /builder /builder - -RUN apk update -RUN apk add --no-cache ruby ruby-dev ruby-bundler build-base - -ADD defaultBuildCmd /usr/local/bin/build - -EXPOSE 8001 diff --git a/environments/ruby/builder/defaultBuildCmd b/environments/ruby/builder/defaultBuildCmd deleted file mode 100755 index e6a2637a..00000000 --- a/environments/ruby/builder/defaultBuildCmd +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -set -euxo pipefail - -if [ -f ${SRC_PKG}/Gemfile.lock ] -then - cd $SRC_PKG - bundle install --deployment -fi -cp -r ${SRC_PKG} ${DEPLOY_PKG} \ No newline at end of file diff --git a/environments/ruby/fission/context.rb b/environments/ruby/fission/context.rb deleted file mode 100644 index 9e893833..00000000 --- a/environments/ruby/fission/context.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -require_relative 'request' -require 'forwardable' - -module Fission - class Context - extend Forwardable - - def_instance_delegator :request, :logger - - attr_reader :env - - def initialize(env) - @env = env - end - - def request - @request ||= Request.new(env) - end - end -end diff --git a/environments/ruby/fission/handler.rb b/environments/ruby/fission/handler.rb deleted file mode 100644 index a594f5e2..00000000 --- a/environments/ruby/fission/handler.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -require_relative 'context' - -module Fission - module Handler - def self.call(env) - context = Context.new(env) - - response = if $handler.arity > 0 - $handler.call(context) - else - $handler.call - end - - response.is_a?(Array) ? response : Rack::Response.new([response]).finish - - rescue => e - context.logger.error(%(Function failed - #{e}\n#{e.backtrace.join("\n")})) - Rack::Response.new(['500 Internal Server Error'], 500, {}).finish - end - end -end diff --git a/environments/ruby/fission/request.rb b/environments/ruby/fission/request.rb deleted file mode 100644 index 7a3d37fc..00000000 --- a/environments/ruby/fission/request.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -module Fission - HEADER_PREFIX = 'HTTP_' - PARAM_HEADER_PREFIX = 'HTTP_X_FISSION_PARAMS_' - PARAMETERS_KEY = 'fission.request.parameters' - - class Request < Rack::Request - def headers - Hash[ - *env.select { |k,v| k.start_with?(HEADER_PREFIX) } - .map { |k,v| [k.sub(/\A#{HEADER_PREFIX}/, '').split('_').map(&:capitalize).join('-'), v] } - .sort - .flatten - ] - end - - def params - env[PARAMETERS_KEY] ||= super.merge(path_parameters) - end - - def path_parameters - Hash[ - *env.select { |k,v| k.start_with?(PARAM_HEADER_PREFIX) } - .map { |k,v| [k.sub(/\A#{PARAM_HEADER_PREFIX}/, '').downcase, v] } - .sort - .flatten - ] - end - end -end diff --git a/environments/ruby/fission/specializer.rb b/environments/ruby/fission/specializer.rb deleted file mode 100644 index 1b85e532..00000000 --- a/environments/ruby/fission/specializer.rb +++ /dev/null @@ -1,84 +0,0 @@ -# frozen_string_literal: true - -require 'benchmark' -require 'json' - -module Fission - module Specializer - - CODE_PATH = '/userfunc/user' - - def self.call(env) - request = Request.new(env) - - request.logger.info("Codepath defaulting to #{CODE_PATH}") - time = Benchmark.measure { load CODE_PATH } - request.logger.info("User code loaded in #{(time.real * 1000).round(3)}ms") - - # set to "handler" for v1 specialization - $handler = method(:handler) - - Rack::Response.new([], 201).finish - rescue => e - request.logger.error(%(Specialization failed - #{e}\n#{e.backtrace.join("\n")})) - Rack::Response.new(['500 Internal Server Error'], 500, {}).finish - end - end - - module V2 - module Specializer - - def self.load_vendor(path) - gems = Dir[File.join(path, 'vendor/bundle/ruby/*/gems/*/lib')] - exts = Dir[File.join(path, 'vendor/bundle/ruby/*/extensions/x86_64-linux/*/*')] - - $LOAD_PATH.unshift(*gems) - $LOAD_PATH.unshift(*exts) - end - - def self.call(env) - request = Request.new(env) - - body = JSON.parse(request.body.read) - path = body['filepath'] - func = body['functionName'] - - time = Benchmark.measure do - if File.file?(path) - # If pointing to just a single file, all we need to do is load it - request.logger.debug("Loading file #{path}") - - load path - elsif File.directory?(path) - # First we want to load all the vendor files - load_vendor(path) - - # We then want to get all the .rb files in this src - rb_files = File.join(path, "**/*.rb") - - # But we don't want to include the vendor files that we loaded above - vendor_dir = File.join(path, 'vendor') - src_files = Dir[rb_files].reject {|d| d.start_with?(vendor_dir) } - - request.logger.debug("Loading sources #{src_files}") - - src_files.each do |file| - load file - end - else - request.logger.error(%(Specialization failed - could not find src at #{path}})) - Rack::Response.new(['500 Internal Server Error'], 500, {}).finish - - return - end - end - request.logger.info("User code loaded in #{(time.real * 1000).round(3)}ms") - - # set global handler for this specialization - $handler = method(func) - - Rack::Response.new([], 201).finish - end - end - end -end diff --git a/environments/ruby/server.rb b/environments/ruby/server.rb deleted file mode 100644 index 5b087ab8..00000000 --- a/environments/ruby/server.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -require 'rack' -require 'thin' -require 'logger' - -require_relative 'fission/specializer' -require_relative 'fission/handler' - -$handler = nil - -app = Rack::Builder.new do - use Rack::Logger, Logger::DEBUG - use Rack::CommonLogger - - map "/specialize" do - run Fission::Specializer - end - - map '/v2/specialize' do - run Fission::V2::Specializer - end - - map "/healthz" do - run ->(env) { [ 200, {}, [] ] } - end - - map '/' do - run Fission::Handler - end -end - -Rack::Handler::Thin.run app, Host: '0.0.0.0', Port: 8888 diff --git a/environments/tensorflow-serving/Dockerfile b/environments/tensorflow-serving/Dockerfile deleted file mode 100644 index e51abf6f..00000000 --- a/environments/tensorflow-serving/Dockerfile +++ /dev/null @@ -1,23 +0,0 @@ -ARG GO_VERSION=1.13 - -FROM tensorflow/serving as serving -RUN apt update && apt install -y ca-certificates && rm -rf /var/lib/apt/lists/* - -FROM golang:${GO_VERSION} AS builder - -ENV GOPATH /usr -ENV APP ${GOPATH}/src/github.com/fission/fission/environments/tensorflow-serving - -WORKDIR ${APP} - -ADD server.go ${APP} - -RUN go get -RUN go build -a -o /server server.go - -FROM serving -WORKDIR / -COPY --from=builder /server / - -ENTRYPOINT ["/server"] -EXPOSE 8888 diff --git a/environments/tensorflow-serving/README.md b/environments/tensorflow-serving/README.md deleted file mode 100644 index a1c4ea1c..00000000 --- a/environments/tensorflow-serving/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# Fission: Tensorflow Serving Environment - -This is the Tensorflow Serving environment for Fission. - -It's a Docker image containing a Go runtime, along with a tensorflow serving service. - -## How it works - -Tensorflow Serving is an serving service that supports both RESTful API and gRPC endpoints. In current implementation, -Go server launches `tensorflow_model_server` to load in model during specialization. As long as the Go server receives -requests from router it creates a reverse proxy that connects to RESTful API endpoint exposed by tensorflow_model_server -and get response from the upstream server for user. - -## Build this image - -``` -docker build -t USER/tensorflow-serving . && docker push USER/tensorflow-serving -``` - -## Using the image in fission - -You can add this customized image to fission with "fission env create": - -``` -fission env create --name tensorflow --image USER/tensorflow-serving --version 2 -``` - -After this, fission functions that have the env parameter set to the -same environment name as this command will use this environment. diff --git a/environments/tensorflow-serving/server.go b/environments/tensorflow-serving/server.go deleted file mode 100644 index d45c2c17..00000000 --- a/environments/tensorflow-serving/server.go +++ /dev/null @@ -1,231 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "log" - "net" - "net/http" - "net/http/httputil" - "os" - "os/exec" - "path/filepath" - "strings" - "time" - - "github.com/pkg/errors" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" -) - -const ( - PortgRPC = 8500 - PortRestAPI = 8501 -) - -var ( - specialized = false - - // for tensorflow serving to use - MODEL_NAME = "" - API_TYPE = "" -) - -type ( - FunctionLoadRequest struct { - // FilePath is an absolute filesystem path to the - // function. What exactly is stored here is - // env-specific. Optional. - FilePath string `json:"filepath"` - - // FunctionName has an environment-specific meaning; - // usually, it defines a function within a module - // containing multiple functions. Optional; default is - // environment-specific. - FunctionName string `json:"functionName"` - - // URL to expose this function at. Optional; defaults - // to "/". - URL string `json:"url"` - } -) - -func specializeHandler(logger *zap.Logger) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - logger.Error("v1 interface is not implemented") - w.WriteHeader(http.StatusNotImplemented) - } -} - -func specializeHandlerV2(logger *zap.Logger) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - if specialized { - w.WriteHeader(http.StatusBadRequest) - w.Write([]byte("Not a generic container")) - return - } - - body, err := ioutil.ReadAll(r.Body) - if err != nil { - logger.Error("error reading request body", zap.Error(err)) - w.WriteHeader(http.StatusInternalServerError) - return - } - var loadreq FunctionLoadRequest - err = json.Unmarshal(body, &loadreq) - if err != nil { - w.WriteHeader(http.StatusBadRequest) - return - } - - // Tensorflow-serving supports three types of API: classify, regress, predict - // To get the API type, we need to split the entry point with separator ":" - // POST http://host:port/v1/models/${MODEL_NAME}:(classify|regress:predict) - entrypoint := strings.Split(loadreq.FunctionName, ":") - modelDir, apiType := "", "" - - if len(entrypoint) == 0 { - logger.Error("unable to load model due to empty entrypoint") - w.WriteHeader(http.StatusBadRequest) - return - } else if len(entrypoint) == 1 { - modelDir = entrypoint[0] - apiType = "predict" // assign default API type - } else { - modelDir = entrypoint[0] - apiType = entrypoint[1] - } - - // To ensure we load model from the expected path - basePath := fmt.Sprintf("%v/%v", loadreq.FilePath, modelDir) - basePath, err = filepath.Abs(basePath) - if err != nil { - msg := "error getting absolute path of model" - logger.Error(msg, zap.Error(err)) - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte(err.Error())) - return - } else if !strings.HasPrefix(basePath, loadreq.FilePath) { - msg := "incorrect model base path" - logger.Error(msg, zap.String("model_base_path", basePath)) - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte(msg)) - return - } - - _, err = os.Stat(basePath) - if err != nil { - msg := "error checking model status" - logger.Error(msg, zap.Error(err)) - w.WriteHeader(http.StatusInternalServerError) - return - } - - // get directory name that holds model - MODEL_NAME = filepath.Base(basePath) - API_TYPE = apiType - - argModelBasePath := fmt.Sprintf("--model_base_path=%v", basePath) - argModelName := fmt.Sprintf("--model_name=%v", MODEL_NAME) - argPortgRPC := fmt.Sprintf("--port=%v", PortgRPC) - argPortREST := fmt.Sprintf("--rest_api_port=%v", PortRestAPI) - - logger.Info(fmt.Sprintf("specializing: %v %v", loadreq.FunctionName, loadreq.FilePath)) - - // Future: could be improved by keeping subprocess open while environment is specialized - cmd := exec.Command("tensorflow_model_server", - argPortgRPC, argPortREST, argModelName, argModelBasePath) - - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - - err = cmd.Start() - if err != nil { - msg := "error starting tensorflow serving" - logger.Error(msg, zap.Error(err)) - err = errors.Wrap(err, msg) - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte(err.Error())) - return - } - - go func() { - err = cmd.Wait() - if err != nil { - logger.Fatal("error running tensorflow serving", zap.Error(err)) - } - }() - - t := time.Now() - retryInterval := 50 * time.Millisecond - - // tensorflow serving takes some time to load model - // into memory, keep retrying until it starts REST api server. - for { - if time.Since(t) > 30*time.Second { - w.WriteHeader(http.StatusGatewayTimeout) - return - } - conn, err := net.Dial("tcp", "localhost:8501") - if err == nil { - conn.Close() - break - } else { - logger.Info(fmt.Sprintf("waiting for tensorflow serving to be ready: %v", err.Error())) - time.Sleep(retryInterval) - retryInterval = retryInterval * 2 - } - } - - specialized = true - - logger.Info("done") - } -} - -func readinessProbeHandler(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(http.StatusOK) -} - -func main() { - - config := zap.NewProductionConfig() - config.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder - logger, err := config.Build() - - if err != nil { - log.Fatalf("can't initialize zap logger: %v", err) - } - defer logger.Sync() - - http.HandleFunc("/healthz", readinessProbeHandler) - http.HandleFunc("/specialize", specializeHandler(logger.Named("specialize_handler"))) - http.HandleFunc("/v2/specialize", specializeHandlerV2(logger.Named("specialize_v2_handler"))) - - // Generic route -- all http requests go to the user function. - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - if !specialized { - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte("Generic container: no requests supported")) - return - } - - // TODO: replace it with gRPC (https://gist.github.com/mauri870/1f953a183ee6c186e70a0a72e78b088c) - // set up proxy server director - director := func(req *http.Request) { - req.URL.Scheme = "http" - req.URL.Host = "localhost:8501" - req.URL.Path = fmt.Sprintf("/v1/models/%v:%v", MODEL_NAME, API_TYPE) - req.Host = "localhost:8501" - } - - proxy := &httputil.ReverseProxy{ - Director: director, - } - proxy.ServeHTTP(w, r) - }) - - logger.Info("listening on 8888 ...") - http.ListenAndServe(":8888", nil) -} diff --git a/examples/binary/README.md b/examples/binary/README.md deleted file mode 100644 index b6aca034..00000000 --- a/examples/binary/README.md +++ /dev/null @@ -1,80 +0,0 @@ -# Binary Environment Examples - -The `binary` runtime is a go server that uses a subprocess to invoke executables or execute shell scripts. - -For more info read the [environment README](../../environments/binary/README.md). - -## Requirements - -First, set up your fission deployment with the binary environment. - -```bash -fission env create --name binary-env --image fission/binary-env -``` - -## Example Usage - -### hello.sh -`hello.sh` is an very basic shell script that returns `"Hello, World!"`. - -```bash -# Upload the function to fission -fission function create --name hello --env binary-env --code hello.sh - -# Map /hello to the hello function -fission route create --method GET --url /hello --function hello - -# Run the function -curl http://$FISSION_ROUTER/hello -``` - -This should return a HTTP response with the body `Hello World!` - -### echo.sh -`echo.sh` shows the the use of STDIN to read the request body, echoing the input back in the response. - -```bash -# Upload the function to fission -fission function create --name echo --env binary-env --code echo.sh - -# Map /hello to the hello function -fission route create --method POST --url /echo --function echo - -# Run the function -curl -XPOST -d 'Echoooooo!' http://$FISSION_ROUTER/echo -``` -This should return a HTTP response with the body `... Echoooooo!`. - - -### headers.sh -`headers.sh` shows the access to the environment variables that hold the HTTP headers, returning the set HTTP headers. - -```bash -# Upload the function to fission -fission function create --name headers --env binary-env --code headers.sh - -# Map /hello to the hello function -fission route create --url /headers --function headers - -# Run the function -curl -H 'X-FOO: BAR' http://$FISSION_ROUTER/headers -``` -This should return a HTTP response with the body `... Echoooooo!`. - -### hello..go -This example shows the differences between using shell scripts and binaries. `hello.go` returns `Hello World!` + the -environment variables it received from the server. - -```bash -# Build the function targeted at the right architecture -GOOS=linux GOARCH=386 go build -o hello-go-func hello.go - -# Upload the function to fission -fission function create --name hello-go --env binary-env --code hello-go-func - -# Map /hello to the hello function -fission route create --url /hello-go --function hello-go - -# Run the function -curl -H 'X-GO: AWESOME!' http://$FISSION_ROUTER/hello-go -``` \ No newline at end of file diff --git a/examples/binary/echo.sh b/examples/binary/echo.sh deleted file mode 100644 index 0fe93579..00000000 --- a/examples/binary/echo.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -printf "... " -cat - \ No newline at end of file diff --git a/examples/binary/headers.sh b/examples/binary/headers.sh deleted file mode 100644 index b0790b21..00000000 --- a/examples/binary/headers.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -env | grep "^HTTP_" \ No newline at end of file diff --git a/examples/binary/hello.go b/examples/binary/hello.go deleted file mode 100644 index 60bd1a0a..00000000 --- a/examples/binary/hello.go +++ /dev/null @@ -1,12 +0,0 @@ -package main - -import ( - "fmt" - "os" -) - -// See README.md in the examples/binary directory for instructions -func main() { - fmt.Println("Hello World!") - fmt.Printf("Environment: %v", os.Environ()) -} diff --git a/examples/binary/hello.sh b/examples/binary/hello.sh deleted file mode 100644 index 5dc761df..00000000 --- a/examples/binary/hello.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -echo "Hello World!" \ No newline at end of file diff --git a/examples/dotnet/arguments.cs b/examples/dotnet/arguments.cs deleted file mode 100644 index c3e2a48e..00000000 --- a/examples/dotnet/arguments.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using Fission.DotNetCore.Api; - -public class FissionFunction -{ - public string Execute(FissionContext context){ - var x = Convert.ToInt32(context.Arguments["x"]); - var y = Convert.ToInt32(context.Arguments["y"]); - return (x+y).ToString(); - } -} diff --git a/examples/dotnet/helloworld.cs b/examples/dotnet/helloworld.cs deleted file mode 100644 index cae5a7e9..00000000 --- a/examples/dotnet/helloworld.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Fission.DotNetCore.Api; - -public class FissionFunction -{ - public string Execute(FissionContext context) - { - return "Hello World!"; - } -} diff --git a/examples/dotnet/requestbody.cs b/examples/dotnet/requestbody.cs deleted file mode 100644 index c4be5f44..00000000 --- a/examples/dotnet/requestbody.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.IO; -using System.Runtime.Serialization.Json; -using Fission.DotNetCore.Api; - -public class FissionFunction -{ - public string Execute(FissionContext context) - { - var person = Person.Deserialize(context.Request.Body); - return $"Hello, my name is {person.Name} and I am {person.Age} years old."; - } -} - -public class Person -{ - public string Name { get; set; } - public int Age { get; set; } - - public static Person Deserialize(Stream json) - { - var serializer = new DataContractJsonSerializer(typeof(Person)); - return (Person)serializer.ReadObject(json); - } -} diff --git a/examples/dotnet/requestheaders.cs b/examples/dotnet/requestheaders.cs deleted file mode 100644 index 8e44f2f7..00000000 --- a/examples/dotnet/requestheaders.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using Fission.DotNetCore.Api; - -public class FissionFunction -{ - public string Execute(FissionContext context){ - var buffer = new System.Text.StringBuilder(); - foreach(var header in context.Request.Headers){ - buffer.AppendLine(header.Key); - foreach(var item in header.Value){ - buffer.AppendLine($"\t{item}"); - } - } - buffer.AppendLine($"Url: {context.Request.Url}, method: {context.Request.Method}"); - return buffer.ToString(); - } -} diff --git a/examples/dotnet20/arguments.cs b/examples/dotnet20/arguments.cs deleted file mode 100644 index c3e2a48e..00000000 --- a/examples/dotnet20/arguments.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using Fission.DotNetCore.Api; - -public class FissionFunction -{ - public string Execute(FissionContext context){ - var x = Convert.ToInt32(context.Arguments["x"]); - var y = Convert.ToInt32(context.Arguments["y"]); - return (x+y).ToString(); - } -} diff --git a/examples/dotnet20/echo.cs b/examples/dotnet20/echo.cs deleted file mode 100644 index 9e399583..00000000 --- a/examples/dotnet20/echo.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using Fission.DotNetCore.Api; - -public class FissionFunction -{ - public string Execute(FissionContext context){ - context.Logger.WriteInfo("executing.. {0}", context.Arguments["text"]); - return (string)context.Arguments["text"]; - } -} \ No newline at end of file diff --git a/examples/dotnet20/helloworld.cs b/examples/dotnet20/helloworld.cs deleted file mode 100644 index cae5a7e9..00000000 --- a/examples/dotnet20/helloworld.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Fission.DotNetCore.Api; - -public class FissionFunction -{ - public string Execute(FissionContext context) - { - return "Hello World!"; - } -} diff --git a/examples/dotnet20/requestbody.cs b/examples/dotnet20/requestbody.cs deleted file mode 100644 index c4be5f44..00000000 --- a/examples/dotnet20/requestbody.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.IO; -using System.Runtime.Serialization.Json; -using Fission.DotNetCore.Api; - -public class FissionFunction -{ - public string Execute(FissionContext context) - { - var person = Person.Deserialize(context.Request.Body); - return $"Hello, my name is {person.Name} and I am {person.Age} years old."; - } -} - -public class Person -{ - public string Name { get; set; } - public int Age { get; set; } - - public static Person Deserialize(Stream json) - { - var serializer = new DataContractJsonSerializer(typeof(Person)); - return (Person)serializer.ReadObject(json); - } -} diff --git a/examples/dotnet20/requestheaders.cs b/examples/dotnet20/requestheaders.cs deleted file mode 100644 index 8e44f2f7..00000000 --- a/examples/dotnet20/requestheaders.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using Fission.DotNetCore.Api; - -public class FissionFunction -{ - public string Execute(FissionContext context){ - var buffer = new System.Text.StringBuilder(); - foreach(var header in context.Request.Headers){ - buffer.AppendLine(header.Key); - foreach(var item in header.Value){ - buffer.AppendLine($"\t{item}"); - } - } - buffer.AppendLine($"Url: {context.Request.Url}, method: {context.Request.Method}"); - return buffer.ToString(); - } -} diff --git a/examples/go/README.md b/examples/go/README.md deleted file mode 100644 index adcd3a51..00000000 --- a/examples/go/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# Hello World in Go on Fission - -`hello.go` contains a very simple fission function that says "Hello, World!". - -## Deploying this function on your cluster - -```bash - -# Create the Fission Go environment and function, and wait for the -# function to build. (Take a look at the YAML files in the specs -# directory for details about how the environment and function are -# specified.) - -$ fission spec apply --wait -1 environment created -1 package created -1 function created - -# Now, run the function with the "fission function test" command: - -$ fission function test --name hello-go -Hello, World! -``` diff --git a/examples/go/hello.go b/examples/go/hello.go deleted file mode 100644 index 88c004fe..00000000 --- a/examples/go/hello.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -import ( - "net/http" -) - -// Handler is the entry point for this fission function -func Handler(w http.ResponseWriter, r *http.Request) { - msg := "Hello, world!\n" - w.Write([]byte(msg)) -} diff --git a/examples/go/module-example/README.md b/examples/go/module-example/README.md deleted file mode 100644 index e813bd11..00000000 --- a/examples/go/module-example/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# Go module usage - -1. Initialize your project - -```bash -$ go mod init "" -``` - -For example, - -```bash -$ go mod init "github.com/fission/fission/examples/go/go-module-example" -``` - -2. Add dependencies - - * See [here](https://github.com/golang/go/wiki/Modules#daily-workflow) - -3. Verify - -```bash -$ go mod verify -``` - -4. Archive and create package as usual - -```bash -$ zip -r go.zip . - adding: go.mod (deflated 26%) - adding: go.sum (deflated 1%) - adding: README.md (deflated 37%) - adding: main.go (deflated 30%) - -$ fission pkg create --env go --src go.zip -``` diff --git a/examples/go/module-example/go.mod b/examples/go/module-example/go.mod deleted file mode 100644 index cdc628a4..00000000 --- a/examples/go/module-example/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/fission/fission/examples/go/go-module-example - -require github.com/golang/example v0.0.0-20170904185048-46695d81d1fa diff --git a/examples/go/module-example/go.sum b/examples/go/module-example/go.sum deleted file mode 100644 index 868c5abf..00000000 --- a/examples/go/module-example/go.sum +++ /dev/null @@ -1 +0,0 @@ -github.com/golang/example v0.0.0-20170904185048-46695d81d1fa/go.mod h1:tO/5UvQ/uKigUjQBPqzstj6uxd3fUIjddi19DxGJeWg= diff --git a/examples/go/module-example/main.go b/examples/go/module-example/main.go deleted file mode 100644 index 91b5c21d..00000000 --- a/examples/go/module-example/main.go +++ /dev/null @@ -1,13 +0,0 @@ -package main - -import ( - "net/http" - - "github.com/golang/example/stringutil" -) - -// Handler is the entry point for this fission function -func Handler(w http.ResponseWriter, r *http.Request) { - msg := stringutil.Reverse(stringutil.Reverse("Vendor Example Test")) - w.Write([]byte(msg)) -} diff --git a/examples/go/specs/env.yaml b/examples/go/specs/env.yaml deleted file mode 100644 index c5c9b140..00000000 --- a/examples/go/specs/env.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: fission.io/v1 -kind: Environment -metadata: - name: go - namespace: default -spec: - version: 2 - builder: - command: build - image: fission/go-builder-1.12:1.5.0 - runtime: - image: fission/go-env-1.12:1.5.0 diff --git a/examples/go/specs/fission-deployment-config.yaml b/examples/go/specs/fission-deployment-config.yaml deleted file mode 100644 index 0967a979..00000000 --- a/examples/go/specs/fission-deployment-config.yaml +++ /dev/null @@ -1,6 +0,0 @@ -# This file is generated by the 'fission spec init' command. -# See the README in this directory for background and usage information. -# Do not edit the UID below: that will break 'fission spec apply' -kind: DeploymentConfig -name: hello-go -uid: a8cdb63c-9be8-4a59-9427-89051afecd7b diff --git a/examples/go/specs/function-hello.yaml b/examples/go/specs/function-hello.yaml deleted file mode 100644 index f53e92dd..00000000 --- a/examples/go/specs/function-hello.yaml +++ /dev/null @@ -1,39 +0,0 @@ -kind: ArchiveUploadSpec -name: hello-go -include: -- hello.go - ---- -apiVersion: fission.io/v1 -kind: Package -metadata: - creationTimestamp: null - name: hello-go-pkg - namespace: default -spec: - environment: - name: go - namespace: default - source: - type: url - url: archive://hello-go -status: - buildstatus: pending - ---- -apiVersion: fission.io/v1 -kind: Function -metadata: - creationTimestamp: null - name: hello-go - namespace: default -spec: - environment: - name: go - namespace: default - functionTimeout: 60 - package: - functionName: Handler - packageref: - name: hello-go-pkg - namespace: default diff --git a/examples/jvm-jersey/java/.gitignore b/examples/jvm-jersey/java/.gitignore deleted file mode 100644 index 4c3f8757..00000000 --- a/examples/jvm-jersey/java/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.project -.settings -.classpath -target/ diff --git a/examples/jvm-jersey/java/README.md b/examples/jvm-jersey/java/README.md deleted file mode 100644 index 1c9bf76e..00000000 --- a/examples/jvm-jersey/java/README.md +++ /dev/null @@ -1,60 +0,0 @@ -# Hello World in JVM/Java on Fission - -The `io.fission.HelloWorld.java` class is a very simple fission function that implements `io.fission.Function` and says "Hello, World!" . - -## Building and deploying using Fission - -Fission's builder can be used to create the binary artifact from source code. Create an environment with builder image and then create a package. - -``` -$ zip -r java-src-pkg.zip * -$ fission env create --name java --image fission/jvm-env --version 2 --keeparchive --builder fission/jvm-builder -$ fission package create --sourcearchive java-src-pkg.zip --env java -java-src-pkg-zip-tvd0 -$ fission package info --name java-src-pkg-zip-tvd0 -Name: java-src-pkg-zip-tvd0 -Environment: java -Status: succeeded -Build Logs: -[INFO] Scanning for projects... -[INFO] -[INFO] -----------------------< io.fission:hello-world >----------------------- -[INFO] Building hello-world 1.0-SNAPSHOT -[INFO] --------------------------------[ jar ]--------------------------------- -``` - -Once package's status is `succeeded` then that package can be used to create and execute a function. - -``` -$ fission fn create --name hello --pkg java-src-pkg-zip-tvd0 --env java --entrypoint io.fission.HelloWorld -$ fission fn test --name hello -Hello World! -``` - -## Building locally and deploying with Fission - -You can build the jar file in one of the two ways below based on your setup: - -- You can use docker without the need to install JDK and Maven to build the jar file from source code: - -```bash -$ bash -x ./build.sh - -``` -- If you have JDK and Maven installed, you can directly build the JAR file using command: - -``` -$ mvn clean package -``` - -Both of above steps will generate a target subdirectory which has the archive `target/hello-world-1.0-SNAPSHOT-jar-with-dependencies.jar` which will be used for creating function. - -- The archive created above will be used as a deploy package when creating the function. - -``` -$ fission env create --name jvm --image fission/jvm-env --version 2 --keeparchive=true -$ fission fn create --name hello --deploy target/hello-world-1.0-SNAPSHOT-jar-with-dependencies.jar --env jvm --entrypoint io.fission.HelloWorld -$ fission route create --function hello --url /hellop --method GET -$ fission fn test --name hello -Hello World! -``` diff --git a/examples/jvm-jersey/java/build.sh b/examples/jvm-jersey/java/build.sh deleted file mode 100755 index abac4200..00000000 --- a/examples/jvm-jersey/java/build.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -# This script allows you to build the jar without needing Maven & JDK installed locally. -# You need docker, as it uses a Docker image to build source code -set -eou pipefail -docker run -it --rm -v "$(pwd)":/usr/src/mymaven -w /usr/src/mymaven maven:3.5-jdk-8 mvn clean package diff --git a/examples/jvm-jersey/java/pom.xml b/examples/jvm-jersey/java/pom.xml deleted file mode 100644 index efc5fdf0..00000000 --- a/examples/jvm-jersey/java/pom.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - 4.0.0 - io.fission - jersey-hello-world - 0.0.1 - jar - - hello-world - http://maven.apache.org - - - UTF-8 - 1.6 - 1.6 - - - - - io.fission - fission-jvm-jersey - 0.0.1 - provided - - - javax.ws.rs - javax.ws.rs-api - 2.0 - provided - - - org.glassfish.jersey.containers - jersey-container-servlet-core - 2.0 - test - - - junit - junit - 4.13 - test - - - - - - - maven-assembly-plugin - - - jar-with-dependencies - - - - - make-assembly - package - - single - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.22.1 - - false - - - - - - diff --git a/examples/jvm-jersey/java/specs/README b/examples/jvm-jersey/java/specs/README deleted file mode 100644 index 1db3f9a5..00000000 --- a/examples/jvm-jersey/java/specs/README +++ /dev/null @@ -1,42 +0,0 @@ - -Fission Specs -============= - -This is a set of specifications for a Fission app. This includes functions, -environments, and triggers; we collectively call these things "resources". - -How to use these specs ----------------------- - -These specs are handled with the 'fission spec' command. See 'fission spec --help'. - -'fission spec apply' will "apply" all resources specified in this directory to your -cluster. That means it checks what resources exist on your cluster, what resources are -specified in the specs directory, and reconciles the difference by creating, updating or -deleting resources on the cluster. - -'fission spec apply' will also package up your source code (or compiled binaries) and -upload the archives to the cluster if needed. It uses 'ArchiveUploadSpec' resources in -this directory to figure out which files to archive. - -You can use 'fission spec apply --watch' to watch for file changes and continuously keep -the cluster updated. - -You can add YAMLs to this directory by writing them manually, but it's easier to generate -them. Use 'fission function create --spec' to generate a function spec, -'fission environment create --spec' to generate an environment spec, and so on. - -You can edit any of the files in this directory, except 'fission-deployment-config.yaml', -which contains a UID that you should never change. To apply your changes simply use -'fission spec apply'. - -fission-deployment-config.yaml ------------------------------- - -fission-deployment-config.yaml contains a UID. This UID is what fission uses to correlate -resources on the cluster to resources in this directory. - -All resources created by 'fission spec apply' are annotated with this UID. Resources on -the cluster that are _not_ annotated with this UID are never modified or deleted by -fission. - diff --git a/examples/jvm-jersey/java/specs/env-java.yaml b/examples/jvm-jersey/java/specs/env-java.yaml deleted file mode 100644 index 78b2db7b..00000000 --- a/examples/jvm-jersey/java/specs/env-java.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: fission.io/v1 -kind: Environment -metadata: - creationTimestamp: null - name: java-jersey - namespace: default -spec: - builder: - command: build - image: fission/jvm-jersey-builder - imagepullsecret: "" - keeparchive: true - poolsize: 3 - resources: {} - runtime: - image: fission/jvm-jersey-env - version: 2 diff --git a/examples/jvm-jersey/java/specs/fission-deployment-config.yaml b/examples/jvm-jersey/java/specs/fission-deployment-config.yaml deleted file mode 100644 index 24e5e094..00000000 --- a/examples/jvm-jersey/java/specs/fission-deployment-config.yaml +++ /dev/null @@ -1,7 +0,0 @@ -# This file is generated by the 'fission spec init' command. -# See the README in this directory for background and usage information. -# Do not edit the UID below: that will break 'fission spec apply' -apiVersion: fission.io/v1 -kind: DeploymentConfig -name: java-jersey -uid: 908a303a-bf23-4bae-a22c-b1db9a1f71a9 diff --git a/examples/jvm-jersey/java/specs/function-hello.yaml b/examples/jvm-jersey/java/specs/function-hello.yaml deleted file mode 100644 index 9dd85f65..00000000 --- a/examples/jvm-jersey/java/specs/function-hello.yaml +++ /dev/null @@ -1,27 +0,0 @@ -apiVersion: fission.io/v1 -kind: Function -metadata: - creationTimestamp: null - name: hello - namespace: default -spec: - InvokeStrategy: - ExecutionStrategy: - ExecutorType: poolmgr - MaxScale: 0 - MinScale: 0 - SpecializationTimeout: 120 - TargetCPUPercent: 0 - StrategyType: execution - configmaps: null - environment: - name: java-jersey - namespace: default - functionTimeout: 60 - package: - functionName: io.fission.HelloWorld - packageref: - name: hellojava - namespace: default - resources: {} - secrets: null diff --git a/examples/jvm-jersey/java/specs/package-hellojava.yaml b/examples/jvm-jersey/java/specs/package-hellojava.yaml deleted file mode 100644 index f606e112..00000000 --- a/examples/jvm-jersey/java/specs/package-hellojava.yaml +++ /dev/null @@ -1,26 +0,0 @@ -include: -- src -- pom.xml -kind: ArchiveUploadSpec -name: src-URlE - ---- -apiVersion: fission.io/v1 -kind: Package -metadata: - creationTimestamp: null - name: hellojavajersey - namespace: default -spec: - deployment: - checksum: {} - environment: - name: java-jersey - namespace: default - source: - checksum: {} - type: url - url: archive://src-URlE -status: - buildstatus: pending - lastUpdateTimestamp: "2020-01-29T09:43:56Z" diff --git a/examples/jvm-jersey/java/src/main/java/io/fission/HelloWorld.java b/examples/jvm-jersey/java/src/main/java/io/fission/HelloWorld.java deleted file mode 100644 index 29039300..00000000 --- a/examples/jvm-jersey/java/src/main/java/io/fission/HelloWorld.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.fission; - -import javax.ws.rs.core.Response; -import javax.ws.rs.container.ContainerRequestContext; -import io.fission.Function; -import java.io.BufferedReader; -import java.util.stream.Collectors; -import java.io.InputStreamReader; - -public class HelloWorld implements Function { - - public static final String RETURN_STRING = "Hello World!"; - - @Override - public Response call(ContainerRequestContext request, Context arg1) { - if(request.getMethod().equals("GET")) { - return Response.ok(RETURN_STRING).build(); - } - else { - String body = new BufferedReader(new InputStreamReader(request.getEntityStream())).lines() - .parallel().collect(Collectors.joining("\n")); - return Response.ok("Echo: " + body).build(); - } - } -} diff --git a/examples/jvm-jersey/java/src/test/java/io/fission/HelloWorldTest.java b/examples/jvm-jersey/java/src/test/java/io/fission/HelloWorldTest.java deleted file mode 100644 index 907946d8..00000000 --- a/examples/jvm-jersey/java/src/test/java/io/fission/HelloWorldTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.fission; - -import java.net.URI; -import java.net.URISyntaxException; -import org.glassfish.jersey.server.ContainerRequest; -import javax.ws.rs.core.Response; -import org.junit.Assert; -import org.junit.Test; - - -public class HelloWorldTest { - - @Test - public void testResponse() { - HelloWorld hw = new HelloWorld(); - ContainerRequest request = null; - try { - request = new ContainerRequest(new URI("http://example.com/"),new URI("/hello"),"GET",null,null); - } catch (URISyntaxException e) { - e.printStackTrace(); - } - Response response = hw.call(request, null); - Assert.assertTrue(response.getEntity().toString().equals(HelloWorld.RETURN_STRING)); - } -} diff --git a/examples/jvm/java/.gitignore b/examples/jvm/java/.gitignore deleted file mode 100644 index 4c3f8757..00000000 --- a/examples/jvm/java/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.project -.settings -.classpath -target/ diff --git a/examples/jvm/java/README.md b/examples/jvm/java/README.md deleted file mode 100644 index 1c9bf76e..00000000 --- a/examples/jvm/java/README.md +++ /dev/null @@ -1,60 +0,0 @@ -# Hello World in JVM/Java on Fission - -The `io.fission.HelloWorld.java` class is a very simple fission function that implements `io.fission.Function` and says "Hello, World!" . - -## Building and deploying using Fission - -Fission's builder can be used to create the binary artifact from source code. Create an environment with builder image and then create a package. - -``` -$ zip -r java-src-pkg.zip * -$ fission env create --name java --image fission/jvm-env --version 2 --keeparchive --builder fission/jvm-builder -$ fission package create --sourcearchive java-src-pkg.zip --env java -java-src-pkg-zip-tvd0 -$ fission package info --name java-src-pkg-zip-tvd0 -Name: java-src-pkg-zip-tvd0 -Environment: java -Status: succeeded -Build Logs: -[INFO] Scanning for projects... -[INFO] -[INFO] -----------------------< io.fission:hello-world >----------------------- -[INFO] Building hello-world 1.0-SNAPSHOT -[INFO] --------------------------------[ jar ]--------------------------------- -``` - -Once package's status is `succeeded` then that package can be used to create and execute a function. - -``` -$ fission fn create --name hello --pkg java-src-pkg-zip-tvd0 --env java --entrypoint io.fission.HelloWorld -$ fission fn test --name hello -Hello World! -``` - -## Building locally and deploying with Fission - -You can build the jar file in one of the two ways below based on your setup: - -- You can use docker without the need to install JDK and Maven to build the jar file from source code: - -```bash -$ bash -x ./build.sh - -``` -- If you have JDK and Maven installed, you can directly build the JAR file using command: - -``` -$ mvn clean package -``` - -Both of above steps will generate a target subdirectory which has the archive `target/hello-world-1.0-SNAPSHOT-jar-with-dependencies.jar` which will be used for creating function. - -- The archive created above will be used as a deploy package when creating the function. - -``` -$ fission env create --name jvm --image fission/jvm-env --version 2 --keeparchive=true -$ fission fn create --name hello --deploy target/hello-world-1.0-SNAPSHOT-jar-with-dependencies.jar --env jvm --entrypoint io.fission.HelloWorld -$ fission route create --function hello --url /hellop --method GET -$ fission fn test --name hello -Hello World! -``` diff --git a/examples/jvm/java/build.sh b/examples/jvm/java/build.sh deleted file mode 100755 index abac4200..00000000 --- a/examples/jvm/java/build.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -# This script allows you to build the jar without needing Maven & JDK installed locally. -# You need docker, as it uses a Docker image to build source code -set -eou pipefail -docker run -it --rm -v "$(pwd)":/usr/src/mymaven -w /usr/src/mymaven maven:3.5-jdk-8 mvn clean package diff --git a/examples/jvm/java/pom.xml b/examples/jvm/java/pom.xml deleted file mode 100644 index 3026ee47..00000000 --- a/examples/jvm/java/pom.xml +++ /dev/null @@ -1,72 +0,0 @@ - - - 4.0.0 - io.fission - hello-world - 1.0-SNAPSHOT - jar - - hello-world - http://maven.apache.org - - - UTF-8 - - - - - org.springframework.boot - spring-boot-starter-web - 2.0.1.RELEASE - provided - - - io.fission - fission-java-core - 0.0.2-SNAPSHOT - provided - - - - - - - maven-assembly-plugin - - - jar-with-dependencies - - - - - make-assembly - package - - single - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.22.1 - - false - - - - - - - - - fission-java-core - fission-java-core-snapshot - https://oss.sonatype.org/content/repositories/snapshots/ - - - - diff --git a/examples/jvm/java/specs/README b/examples/jvm/java/specs/README deleted file mode 100644 index 1db3f9a5..00000000 --- a/examples/jvm/java/specs/README +++ /dev/null @@ -1,42 +0,0 @@ - -Fission Specs -============= - -This is a set of specifications for a Fission app. This includes functions, -environments, and triggers; we collectively call these things "resources". - -How to use these specs ----------------------- - -These specs are handled with the 'fission spec' command. See 'fission spec --help'. - -'fission spec apply' will "apply" all resources specified in this directory to your -cluster. That means it checks what resources exist on your cluster, what resources are -specified in the specs directory, and reconciles the difference by creating, updating or -deleting resources on the cluster. - -'fission spec apply' will also package up your source code (or compiled binaries) and -upload the archives to the cluster if needed. It uses 'ArchiveUploadSpec' resources in -this directory to figure out which files to archive. - -You can use 'fission spec apply --watch' to watch for file changes and continuously keep -the cluster updated. - -You can add YAMLs to this directory by writing them manually, but it's easier to generate -them. Use 'fission function create --spec' to generate a function spec, -'fission environment create --spec' to generate an environment spec, and so on. - -You can edit any of the files in this directory, except 'fission-deployment-config.yaml', -which contains a UID that you should never change. To apply your changes simply use -'fission spec apply'. - -fission-deployment-config.yaml ------------------------------- - -fission-deployment-config.yaml contains a UID. This UID is what fission uses to correlate -resources on the cluster to resources in this directory. - -All resources created by 'fission spec apply' are annotated with this UID. Resources on -the cluster that are _not_ annotated with this UID are never modified or deleted by -fission. - diff --git a/examples/jvm/java/specs/env-java.yaml b/examples/jvm/java/specs/env-java.yaml deleted file mode 100644 index f3bbb582..00000000 --- a/examples/jvm/java/specs/env-java.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: fission.io/v1 -kind: Environment -metadata: - creationTimestamp: null - name: java - namespace: default -spec: - builder: - command: build - image: fission/jvm-builder:1.7.1 - imagepullsecret: "" - keeparchive: true - poolsize: 3 - resources: {} - runtime: - image: fission/jvm-env:1.7.1 - version: 2 diff --git a/examples/jvm/java/specs/fission-deployment-config.yaml b/examples/jvm/java/specs/fission-deployment-config.yaml deleted file mode 100644 index 753e349d..00000000 --- a/examples/jvm/java/specs/fission-deployment-config.yaml +++ /dev/null @@ -1,7 +0,0 @@ -# This file is generated by the 'fission spec init' command. -# See the README in this directory for background and usage information. -# Do not edit the UID below: that will break 'fission spec apply' -apiVersion: fission.io/v1 -kind: DeploymentConfig -name: java -uid: 908a303a-bf23-4bae-a22c-b1db9a1f71a9 diff --git a/examples/jvm/java/specs/function-hello.yaml b/examples/jvm/java/specs/function-hello.yaml deleted file mode 100644 index 8188e5db..00000000 --- a/examples/jvm/java/specs/function-hello.yaml +++ /dev/null @@ -1,27 +0,0 @@ -apiVersion: fission.io/v1 -kind: Function -metadata: - creationTimestamp: null - name: hello - namespace: default -spec: - InvokeStrategy: - ExecutionStrategy: - ExecutorType: poolmgr - MaxScale: 0 - MinScale: 0 - SpecializationTimeout: 120 - TargetCPUPercent: 0 - StrategyType: execution - configmaps: null - environment: - name: java - namespace: default - functionTimeout: 60 - package: - functionName: io.fission.HelloWorld - packageref: - name: hellojava - namespace: default - resources: {} - secrets: null diff --git a/examples/jvm/java/specs/package-hellojava.yaml b/examples/jvm/java/specs/package-hellojava.yaml deleted file mode 100644 index 0da0366c..00000000 --- a/examples/jvm/java/specs/package-hellojava.yaml +++ /dev/null @@ -1,26 +0,0 @@ -include: -- src -- pom.xml -kind: ArchiveUploadSpec -name: src-URlE - ---- -apiVersion: fission.io/v1 -kind: Package -metadata: - creationTimestamp: null - name: hellojava - namespace: default -spec: - deployment: - checksum: {} - environment: - name: java - namespace: default - source: - checksum: {} - type: url - url: archive://src-URlE -status: - buildstatus: pending - lastUpdateTimestamp: "2020-01-29T09:43:56Z" diff --git a/examples/jvm/java/src/main/java/io/fission/HelloWorld.java b/examples/jvm/java/src/main/java/io/fission/HelloWorld.java deleted file mode 100644 index 89e3d067..00000000 --- a/examples/jvm/java/src/main/java/io/fission/HelloWorld.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.fission; - -import org.springframework.http.RequestEntity; -import org.springframework.http.ResponseEntity; - -import io.fission.Function; -import io.fission.Context; - -public class HelloWorld implements Function { - - @Override - public ResponseEntity call(RequestEntity req, Context context) { - return ResponseEntity.ok("Hello World!"); - } - -} diff --git a/examples/jvm/java/src/test/java/io/fission/HelloWorldTest.java b/examples/jvm/java/src/test/java/io/fission/HelloWorldTest.java deleted file mode 100644 index 8133c35c..00000000 --- a/examples/jvm/java/src/test/java/io/fission/HelloWorldTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.fission; - -import java.net.URI; -import java.net.URISyntaxException; - -import org.springframework.http.HttpStatus; -import org.springframework.http.RequestEntity; -import org.springframework.http.ResponseEntity; -import org.springframework.util.Assert; - -public class HelloWorldTest { - - public void testResponse() { - HelloWorld hw = new HelloWorld(); - RequestEntity request = null; - try { - request = RequestEntity.get(new URI("http://example.com/bar")).build(); - } catch (URISyntaxException e) { - e.printStackTrace(); - } - ResponseEntity resp = hw.call(request, null); - Assert.hasText(resp.getBody().toString(), "Hello World!"); - } -} \ No newline at end of file diff --git a/examples/message-queue/nats-streaming/README.md b/examples/message-queue/nats-streaming/README.md deleted file mode 100644 index 53a5a7b8..00000000 --- a/examples/message-queue/nats-streaming/README.md +++ /dev/null @@ -1,42 +0,0 @@ -# Message Queue Trigger Demonstration - NATS Streaming - -## Create spec - -```bash -$ fission spec init -$ fission env create --name go --image fission/go-env-1.12:1.7.1 --builder fission/go-builder-1.12:1.7.1 --period 5 --spec -$ fission pkg create --name publisher --src mqtrigger/* --spec -$ fission fn create --name publisher --env go --pkg publisher --entrypoint "Handler" --spec -$ fission fn create --name hello --env go --src https://raw.githubusercontent.com/fission/fission/master/examples/go/hello.go --entrypoint "Handler" --spec -$ fission mqt create --name mqtrigger --function hello --mqtype nats-streaming --topic foobar --spec -``` - -## Apply CRDs - -```bash -$ fission spec apply - -# wait for package build status become succeeded -$ fission pkg list -NAME BUILD_STATUS ENV LASTUPDATEDAT -hello-98476132-84ff-4e74-8b0f-2d1005871d1c succeeded go 19 Dec 19 17:31 UTC -publisher succeeded go 19 Dec 19 17:19 UTC - -# you can rebuild the package if it shows failed -$ fission pkg rebuild --name - -$ fission fn test --name publisher -Publish Success - -$ kubectl -n fission-function get pod -l functionName=hello -NAME READY STATUS RESTARTS AGE -poolmgr-go-default-610954-55664ccc68-b258c 2/2 Running 0 18m - -# you should be able to see the function prints message -$ kubectl -n fission-function logs -f -c go poolmgr-go-default-610954-55664ccc68-b258c -{"level":"info","ts":1576775701.7085218,"caller":"go/server.go:209","msg":"listening on 8888 ..."} -{"level":"info","ts":1576776720.3545933,"logger":"specialize_v2_handler","caller":"go/server.go:171","msg":"specializing ..."} -{"level":"info","ts":1576776720.3546736,"logger":"specialize_v2_handler","caller":"go/server.go:62","msg":"loading plugin","location":"/userfunc/15382797-f381-48af-9189-561f45f9285c/hello-98476132-84ff-4e74-8b0f-2d1005871d1c-7693uh-pwsz5u"} -{"level":"info","ts":1576776720.3640525,"logger":"specialize_v2_handler","caller":"go/server.go:180","msg":"done"} -2019/12/19 17:32:00 Hello, world! -``` diff --git a/examples/message-queue/nats-streaming/hello.go b/examples/message-queue/nats-streaming/hello.go deleted file mode 100644 index 6fd7af5c..00000000 --- a/examples/message-queue/nats-streaming/hello.go +++ /dev/null @@ -1,13 +0,0 @@ -package main - -import ( - "log" - "net/http" -) - -// Handler is the entry point for this fission function -func Handler(w http.ResponseWriter, r *http.Request) { - log.Print("Hello, world!") - msg := "Hello, world!\n" - w.Write([]byte(msg)) -} diff --git a/examples/message-queue/nats-streaming/mqtrigger/go.mod b/examples/message-queue/nats-streaming/mqtrigger/go.mod deleted file mode 100644 index 8b77e245..00000000 --- a/examples/message-queue/nats-streaming/mqtrigger/go.mod +++ /dev/null @@ -1,12 +0,0 @@ -module github.com/fission/mqtrigger - -go 1.12 - -require ( - github.com/golang/protobuf v1.3.3 // indirect - github.com/kr/pretty v0.2.0 // indirect - github.com/nats-io/nats-streaming-server v0.17.0 // indirect - github.com/nats-io/stan.go v0.6.0 - github.com/satori/go.uuid v1.2.0 - gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect -) diff --git a/examples/message-queue/nats-streaming/mqtrigger/go.sum b/examples/message-queue/nats-streaming/mqtrigger/go.sum deleted file mode 100644 index aae5a92c..00000000 --- a/examples/message-queue/nats-streaming/mqtrigger/go.sum +++ /dev/null @@ -1,104 +0,0 @@ -github.com/DataDog/datadog-go v2.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= -github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878 h1:EFSB7Zo9Eg91v7MJPVsifUysc/wPdN+NOnVe6bWbdBM= -github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878/go.mod h1:3AMJUQhVx52RsWOnlkpikZr01T/yAVN2gn0861vByNg= -github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= -github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= -github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= -github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= -github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= -github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= -github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= -github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= -github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= -github.com/hashicorp/go-hclog v0.9.1 h1:9PZfAcVEvez4yhLH2TBU64/h/z4xlFI80cWXRrxuKuM= -github.com/hashicorp/go-hclog v0.9.1/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= -github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0= -github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= -github.com/hashicorp/go-msgpack v0.5.5 h1:i9R9JSrqIz0QVLz3sz+i3YJdT7TTSLcfLLzJi9aZTuI= -github.com/hashicorp/go-msgpack v0.5.5/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= -github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= -github.com/hashicorp/go-uuid v1.0.0 h1:RS8zrF7PhGwyNPOtxSClXXj9HA8feRnJzgnI1RJCSnM= -github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo= -github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/raft v1.1.1 h1:HJr7UE1x/JrJSc9Oy6aDBHtNHUUBHjcQjTgvUVihoZs= -github.com/hashicorp/raft v1.1.1/go.mod h1:vPAJM8Asw6u8LxC3eJCUZmRP/E4QmUGE1R7g7k8sG/8= -github.com/hashicorp/raft-boltdb v0.0.0-20171010151810-6e5ba93211ea/go.mod h1:pNv7Wc3ycL6F5oOWn+tPGo2gWD4a5X+yp/ntwdKLjRk= -github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= -github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= -github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU= -github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= -github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/nats-io/jwt v0.3.0 h1:xdnzwFETV++jNc4W1mw//qFyJGb2ABOombmZJQS4+Qo= -github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= -github.com/nats-io/jwt v0.3.2 h1:+RB5hMpXUUA2dfxuhBTEkMOrYmM+gKIZYS1KjSostMI= -github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= -github.com/nats-io/nats-server/v2 v2.1.4 h1:BILRnsJ2Yb/fefiFbBWADpViGF69uh4sxe8poVDQ06g= -github.com/nats-io/nats-server/v2 v2.1.4/go.mod h1:Jw1Z28soD/QasIA2uWjXyM9El1jly3YwyFOuR8tH1rg= -github.com/nats-io/nats-streaming-server v0.17.0 h1:eYhSmjRmRsCYNsoUshmZ+RgKbhq6B+7FvMHXo3M5yMs= -github.com/nats-io/nats-streaming-server v0.17.0/go.mod h1:ewPBEsmp62Znl3dcRsYtlcfwudxHEdYMtYqUQSt4fE0= -github.com/nats-io/nats.go v1.9.1 h1:ik3HbLhZ0YABLto7iX80pZLPw/6dx3T+++MZJwLnMrQ= -github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= -github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= -github.com/nats-io/nkeys v0.1.3 h1:6JrEfig+HzTH85yxzhSVbjHRJv9cn0p6n3IngIcM5/k= -github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= -github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= -github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= -github.com/nats-io/stan.go v0.6.0 h1:26IJPeykh88d8KVLT4jJCIxCyUBOC5/IQup8oWD/QYY= -github.com/nats-io/stan.go v0.6.0/go.mod h1:eIcD5bi3pqbHT/xIIvXMwvzXYElgouBvaVRftaE+eac= -github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= -github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM= -github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= -github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.8 h1:+fpWZdT24pJBiqJdAwYBjPSk+5YmQzYNPYzQsdzLkt8= -github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= -github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= -github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= -go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk= -go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc= -golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200206161412-a0c6ece9d31a h1:aczoJ0HPNE92XKa7DrIzkNN6esOKO2TBwiiYoKcINhA= -golang.org/x/crypto v0.0.0-20200206161412-a0c6ece9d31a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190523142557-0e01d883c5c5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0= -golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/examples/message-queue/nats-streaming/mqtrigger/main.go b/examples/message-queue/nats-streaming/mqtrigger/main.go deleted file mode 100644 index 627649e3..00000000 --- a/examples/message-queue/nats-streaming/mqtrigger/main.go +++ /dev/null @@ -1,39 +0,0 @@ -package main - -import ( - "fmt" - "log" - "net/http" - - nats "github.com/nats-io/stan.go" - uuid "github.com/satori/go.uuid" -) - -const ( - authToken = "defaultFissionAuthToken" - host = "nats-streaming.fission" - clusterID = "fissionMQTrigger" - topic = "foobar" -) - -func Handler(w http.ResponseWriter, r *http.Request) { - addr := fmt.Sprintf("nats://%v@%v:4222", authToken, host) - nc, err := nats.Connect(clusterID, uuid.NewV4().String(), nats.NatsURL(addr)) - if err != nil { - log.Fatal(err) - } - - log.Printf("Publishing message to topic '%v'\n", topic) - - err = nc.Publish(topic, []byte("dummy")) - if err != nil { - w.WriteHeader(http.StatusBadRequest) - w.Write([]byte(err.Error())) - log.Printf("error sending message to topic: %v", err.Error()) - return - } - nc.Close() - - w.WriteHeader(http.StatusOK) - w.Write([]byte("Publish Success")) -} diff --git a/examples/message-queue/nats-streaming/specs/README b/examples/message-queue/nats-streaming/specs/README deleted file mode 100644 index 1db3f9a5..00000000 --- a/examples/message-queue/nats-streaming/specs/README +++ /dev/null @@ -1,42 +0,0 @@ - -Fission Specs -============= - -This is a set of specifications for a Fission app. This includes functions, -environments, and triggers; we collectively call these things "resources". - -How to use these specs ----------------------- - -These specs are handled with the 'fission spec' command. See 'fission spec --help'. - -'fission spec apply' will "apply" all resources specified in this directory to your -cluster. That means it checks what resources exist on your cluster, what resources are -specified in the specs directory, and reconciles the difference by creating, updating or -deleting resources on the cluster. - -'fission spec apply' will also package up your source code (or compiled binaries) and -upload the archives to the cluster if needed. It uses 'ArchiveUploadSpec' resources in -this directory to figure out which files to archive. - -You can use 'fission spec apply --watch' to watch for file changes and continuously keep -the cluster updated. - -You can add YAMLs to this directory by writing them manually, but it's easier to generate -them. Use 'fission function create --spec' to generate a function spec, -'fission environment create --spec' to generate an environment spec, and so on. - -You can edit any of the files in this directory, except 'fission-deployment-config.yaml', -which contains a UID that you should never change. To apply your changes simply use -'fission spec apply'. - -fission-deployment-config.yaml ------------------------------- - -fission-deployment-config.yaml contains a UID. This UID is what fission uses to correlate -resources on the cluster to resources in this directory. - -All resources created by 'fission spec apply' are annotated with this UID. Resources on -the cluster that are _not_ annotated with this UID are never modified or deleted by -fission. - diff --git a/examples/message-queue/nats-streaming/specs/env-go.yaml b/examples/message-queue/nats-streaming/specs/env-go.yaml deleted file mode 100644 index c17d8d00..00000000 --- a/examples/message-queue/nats-streaming/specs/env-go.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: fission.io/v1 -kind: Environment -metadata: - creationTimestamp: null - name: go - namespace: default -spec: - builder: - command: build - image: fission/go-builder-1.12:1.7.1 - imagepullsecret: "" - keeparchive: false - poolsize: 3 - resources: {} - runtime: - image: fission/go-env-1.12:1.7.1 - version: 2 diff --git a/examples/message-queue/nats-streaming/specs/fission-deployment-config.yaml b/examples/message-queue/nats-streaming/specs/fission-deployment-config.yaml deleted file mode 100644 index 6c962999..00000000 --- a/examples/message-queue/nats-streaming/specs/fission-deployment-config.yaml +++ /dev/null @@ -1,7 +0,0 @@ -# This file is generated by the 'fission spec init' command. -# See the README in this directory for background and usage information. -# Do not edit the UID below: that will break 'fission spec apply' -apiVersion: fission.io/v1 -kind: DeploymentConfig -name: nats-streaming -uid: 9d6b82e4-3d73-49de-9007-1e47fbc377de diff --git a/examples/message-queue/nats-streaming/specs/function-hello.yaml b/examples/message-queue/nats-streaming/specs/function-hello.yaml deleted file mode 100644 index 85954c0e..00000000 --- a/examples/message-queue/nats-streaming/specs/function-hello.yaml +++ /dev/null @@ -1,54 +0,0 @@ -include: -- hello.go -kind: ArchiveUploadSpec -name: hello-go-zqZW - ---- -apiVersion: fission.io/v1 -kind: Package -metadata: - creationTimestamp: null - name: hello-98476132-84ff-4e74-8b0f-2d1005871d1c - namespace: default -spec: - deployment: - checksum: {} - environment: - name: go - namespace: default - source: - checksum: {} - type: url - url: archive://hello-go-zqZW -status: - buildstatus: pending - lastUpdateTimestamp: "2019-12-19T17:31:23.43918Z" - ---- -apiVersion: fission.io/v1 -kind: Function -metadata: - creationTimestamp: null - name: hello - namespace: default -spec: - InvokeStrategy: - ExecutionStrategy: - ExecutorType: poolmgr - MaxScale: 0 - MinScale: 0 - SpecializationTimeout: 120 - TargetCPUPercent: 0 - StrategyType: execution - configmaps: null - environment: - name: go - namespace: default - functionTimeout: 60 - package: - functionName: Handler - packageref: - name: hello-98476132-84ff-4e74-8b0f-2d1005871d1c - namespace: default - resources: {} - secrets: null diff --git a/examples/message-queue/nats-streaming/specs/function-publisher.yaml b/examples/message-queue/nats-streaming/specs/function-publisher.yaml deleted file mode 100644 index a3161f83..00000000 --- a/examples/message-queue/nats-streaming/specs/function-publisher.yaml +++ /dev/null @@ -1,27 +0,0 @@ -apiVersion: fission.io/v1 -kind: Function -metadata: - creationTimestamp: null - name: publisher - namespace: default -spec: - InvokeStrategy: - ExecutionStrategy: - ExecutorType: poolmgr - MaxScale: 0 - MinScale: 0 - SpecializationTimeout: 120 - TargetCPUPercent: 0 - StrategyType: execution - configmaps: null - environment: - name: go - namespace: default - functionTimeout: 60 - package: - functionName: Handler - packageref: - name: publisher - namespace: default - resources: {} - secrets: null diff --git a/examples/message-queue/nats-streaming/specs/package-publisher.yaml b/examples/message-queue/nats-streaming/specs/package-publisher.yaml deleted file mode 100644 index 8d47d3d3..00000000 --- a/examples/message-queue/nats-streaming/specs/package-publisher.yaml +++ /dev/null @@ -1,25 +0,0 @@ -include: -- mqtrigger/* -kind: ArchiveUploadSpec -name: mqtrigger-Z3l6 - ---- -apiVersion: fission.io/v1 -kind: Package -metadata: - creationTimestamp: null - name: publisher - namespace: default -spec: - deployment: - checksum: {} - environment: - name: go - namespace: default - source: - checksum: {} - type: url - url: archive://mqtrigger-Z3l6 -status: - buildstatus: pending - lastUpdateTimestamp: "2019-12-19T17:18:45.81397Z" diff --git a/examples/nodejs/README.md b/examples/nodejs/README.md deleted file mode 100644 index 31298bfc..00000000 --- a/examples/nodejs/README.md +++ /dev/null @@ -1,131 +0,0 @@ -# Fission Node.js Examples - -This is V2 example, check [here](README_V1.md) for V1. - -This directory contains several examples to get you started using Node.js with Fission. - -Before running any of these functions, make sure you have created a `nodejs` Fission environment: - -```bash -# Create an environment with default nodejs images -$ fission env create --name nodeenv --image fission/node-env:latest --builder fission/node-builder:latest -# Create zip file from our example -$ zip -jr nodejs.zip nodejs/ -# Create a package with the zip file -$ fission pkg create --sourcearchive nodejs.zip --env nodeenv -``` - -## Function signature - -Every Node.js function has the same basic form: - -```javascript -module.exports = async function(context) { - return { - status: 200, - body: 'Your body here', - headers: { - 'Foo': 'Bar' - } - } -} -``` -## hello.js - -This is a basic "Hello, World!" example. It simply returns a status of `200` and text body. - -### Usage -Since it is an `async` function, you can `await` `Promise`s, as demonstrated in the `weather.js` function. - -```bash -# Create a function -$ fission fn create --name hello --pkg [pkgname] --entrypoint "hello" - -# Test the function -$ fission fn test --name hello -``` - -## index.js - -This file does nothing but for demonstrating `require` feature. - -### Usage -```bash -# Create a function, you can skip `--entrypoint` as node will look for `index.js` by default -$ fission fn create --name index --pkg [pkgname] - -# Test the function -$ fission fn test --name index -``` - -## multi-entry.js - -This is a multiple exports example. There are two exports: entry1 and entry2 - -### Usage -```bash -# Create a function for entry1 -$ fission fn create --name entry1 --pkg [pkgname] --entrypoint "multi-entry.entry1" - -# Test the function -$ fission fn test --name entry1 - -# Create a function for entry2 -$ fission fn create --name entry2 --pkg [pkgname] --entrypoint "multi-entry.entry2" - -# Test the function -$ fission fn test --name entry2 -``` - -## hello-callback.js - -This is a basic "Hello, World!" example implemented with the legacy callback implementation. If you declare your function with two arguments (`context`, `callback`), a callback taking three arguments (`status`, `body`, `headers`) is provided. - -⚠️️ Callback support is only provided for backwards compatibility! We recommend that you use `async` functions instead. - -### Usage - -```bash -# Create a function -$ fission fn create --name hello-callback --pkg [pkgname] --entrypoint "hello-callback" - -# Map GET /hello-callback to your new function -$ fission route create --method GET --url /hello-callback --function hello-callback - -# Run the function. -$ curl http://$FISSION_ROUTER/hello-callback -Hello, world! -``` - -## kubeEventsSlack.js - -This example watches Kubernetes events and sends them to a Slack channel. To use this, create an incoming webhook for your Slack channel, and replace the `slackWebhookPath` in the example code. - -### Usage - -```bash -# Upload your function code to fission -$ fission fn create --name kubeEventsSlack --pkg [pkgname] --entrypoint "hello-callback" - -# Watch all services in the default namespace: -$ fission watch create --function kubeEventsSlack --type service --ns default -``` - -## weather.js - -In this example, the Yahoo Weather API is used to current weather at a given location. - -### Usage - -```bash -# Upload your function code to fission -$ fission function create --name weather --pkg [pkgname] --entrypoint "weather" - -# Map GET /stock to your new function -$ fission route create --method POST --url /weather --function weather - -# Run the function. -$ curl -H "Content-Type: application/json" -X POST -d '{"location":"Sieteiglesias, Spain"}' http://$FISSION_ROUTER/weather - -{"text":"It is 2 celsius degrees in Sieteiglesias, Spain and Mostly Clear"} -``` diff --git a/examples/nodejs/README_V1.md b/examples/nodejs/README_V1.md deleted file mode 100644 index d70da2e3..00000000 --- a/examples/nodejs/README_V1.md +++ /dev/null @@ -1,105 +0,0 @@ -# Fission Node.js Examples - -This directory contains several examples to get you started using Node.js with Fission. - -## Environment - -Before running any of these functions, make sure you have created a `nodejs` Fission environment: - -``` -$ fission env create --name nodejs --image fission/node-env -``` - -Note: The default `fission/node-env` image is based on Alpine, which is much smaller than the main Debian Node image (65MB vs 680MB) while still being suitable for most use cases. -If you need to use the full Debian image use the `fission/node-env-debian` image instead. -See the [official Node docker hub repo](https://hub.docker.com/_/node/) for considerations -relating to this choice. - -## Function signature - -Every Node.js function has the same basic form: - -```javascript -module.exports = async function(context) { - return { - status: 200, - body: 'Your body here', - headers: { - 'Foo': 'Bar' - } - } -} -``` - -Since it is an `async` function, you can `await` `Promise`s, as demonstrated in the `weather.js` function. - -## hello.js - -This is a basic "Hello, World!" example. It simply returns a status of `200` and text body. - -### Usage - -```bash -# Upload your function code to fission -$ fission function create --name hello --env nodejs --code hello.js - -# Map GET /hello to your new function -$ fission route create --method GET --url /hello --function hello - -# Run the function. -$ curl http://$FISSION_ROUTER/hello -Hello, world! -``` - -## hello-callback.js - -This is a basic "Hello, World!" example implemented with the legacy callback implementation. If you declare your function with two arguments (`context`, `callback`), a callback taking three arguments (`status`, `body`, `headers`) is provided. - -⚠️️ Callback support is only provided for backwards compatibility! We recommend that you use `async` functions instead. - -### Usage - -```bash -# Upload your function code to fission -$ fission function create --name hello-callback --env nodejs --code hello-callback.js - -# Map GET /hello-callback to your new function -$ fission route create --method GET --url /hello-callback --function hello-callback - -# Run the function. -$ curl http://$FISSION_ROUTER/hello-callback -Hello, world! -``` - -## kubeEventsSlack.js - -This example watches Kubernetes events and sends them to a Slack channel. To use this, create an incoming webhook for your Slack channel, and replace the `slackWebhookPath` in the example code. - -### Usage - -```bash -# Upload your function code to fission -$ fission fn create --name kubeEventsSlack --env nodejs --code kubeEventsSlack.js - -# Watch all services in the default namespace: -$ fission watch create --function kubeEventsSlack --type service --ns default -``` - -## weather.js - -In this example, the Yahoo Weather API is used to current weather at a given location. - -### Usage - -```bash -# Upload your function code to fission -$ fission function create --name weather --env nodejs --code weather.js - -# Map GET /stock to your new function -$ fission route create --method POST --url /weather --function weather - -# Run the function. -$ curl -H "Content-Type: application/json" -X POST -d '{"location":"Sieteiglesias, Spain"}' http://$FISSION_ROUTER/weather - -{"text":"It is 2 celsius degrees in Sieteiglesias, Spain and Mostly Clear"} -``` diff --git a/examples/nodejs/hello-callback.js b/examples/nodejs/hello-callback.js deleted file mode 100644 index 62b87897..00000000 --- a/examples/nodejs/hello-callback.js +++ /dev/null @@ -1,4 +0,0 @@ - -module.exports = function(context, callback) { - callback(200, "Hello, world callback!\n"); -} diff --git a/examples/nodejs/hello.js b/examples/nodejs/hello.js deleted file mode 100644 index aa94dc47..00000000 --- a/examples/nodejs/hello.js +++ /dev/null @@ -1,7 +0,0 @@ - -module.exports = async function(context) { - return { - status: 200, - body: "hello, world!\n" - }; -} diff --git a/examples/nodejs/index.js b/examples/nodejs/index.js deleted file mode 100644 index d2baebe6..00000000 --- a/examples/nodejs/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./hello'); diff --git a/examples/nodejs/kubeEventsSlack.js b/examples/nodejs/kubeEventsSlack.js deleted file mode 100644 index f797a3b3..00000000 --- a/examples/nodejs/kubeEventsSlack.js +++ /dev/null @@ -1,67 +0,0 @@ -'use strict'; - -// -// Watch kubernetes events and send them to a slack channel. This -// uses Slack's incoming webhooks. To use this, create an incoming -// webhook for your slack channel through Slack's UI, and populate the -// relative path below. -// -// Create the function in fission: -// -// fission fn create --name kubeEventsSlack --env nodejs --code kubeEventsSlack.js -// -// Then, watch all services in the default namespace: -// -// fission watch create --function kubeEventsSlack --type service --ns default -// - -let https = require('https'); - -const slackWebhookPath = "YOUR RELATIVE PATH HERE"; // Something like "/services/XXX/YYY/zZz123" - -function upcaseFirst(s) { - return s.charAt(0).toUpperCase() + s.slice(1).toLowerCase(); -} - -async function sendSlackMessage(msg) { - let postData = `{"text": "${msg}"}`; - let options = { - hostname: "hooks.slack.com", - path: slackWebhookPath, - method: "POST", - headers: { - "Content-Type": "application/json" - } - }; - - return new Promise(function(resolve, reject) { - let req = https.request(options, function(res) { - console.log(`slack request status = ${res.statusCode}`); - return resolve(); - }); - req.write(postData); - req.end(); - }); -} - -module.exports = async function(context) { - console.log(context.request.headers); - - let obj = context.request.body; - let version = obj.metadata.resourceVersion; - let eventType = context.request.get('X-Kubernetes-Event-Type'); - let objType = context.request.get('X-Kubernetes-Object-Type'); - - let msg = `${upcaseFirst(eventType)} ${objType} ${obj.metadata.name}`; - console.log(msg, version); - - if (eventType == 'DELETED' || eventType == 'ADDED') { - console.log("sending event to slack") - await sendSlackMessage(msg); - } - - return { - status: 200, - body: "" - } -} diff --git a/examples/nodejs/multi-entry.js b/examples/nodejs/multi-entry.js deleted file mode 100644 index b98be60e..00000000 --- a/examples/nodejs/multi-entry.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports.entry1 = async function(context) { - return { - status: 200, - body: "Hello, entry 1!\n" - }; -} - -module.exports.entry2 = async function(context) { - return { - status: 200, - body: "Hello, entry 2!\n" - }; -} diff --git a/examples/nodejs/package.json b/examples/nodejs/package.json deleted file mode 100644 index 1414092a..00000000 --- a/examples/nodejs/package.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "fission-nodejs-example", - "version": "0.1.0", - "author": "Soam Vasani", - "contributors": [ - { - "name": "Soam Vasani", - "email": "soamvasani+1@gmail.com" - }, - { - "name": "Gary Yeap", - "email": "contact@garyyeap.com" - } - ], - "description": "Nodejs example for Fission framework", - "engines": { - "node": ">=7.6.0" - }, - "dependencies": { - "body-parser": "*", - "co": "~4.6.0", - "express": "*", - "minimist": "*", - "morgan": "*", - "mz": "~2.7.0", - "request": "^2.81.0", - "request-promise-native": "^1.0.3", - "underscore": ">=1.8.3" - } -} diff --git a/examples/nodejs/weather.js b/examples/nodejs/weather.js deleted file mode 100644 index 2f824fc8..00000000 --- a/examples/nodejs/weather.js +++ /dev/null @@ -1,40 +0,0 @@ -'use strict'; - -const rp = require('request-promise-native'); - -module.exports = async function (context) { - const stringBody = JSON.stringify(context.request.body); - const body = JSON.parse(stringBody); - const location = body.location; - - if (!location) { - return { - status: 400, - body: { - text: 'You must provide a location.' - } - }; - } - - try { - const response = await rp(`https://query.yahooapis.com/v1/public/yql?q=select item.condition from weather.forecast where woeid in (select woeid from geo.places(1) where text="${location}") and u="c"&format=json`); - const condition = JSON.parse(response).query.results.channel.item.condition; - const text = condition.text; - const temperature = condition.temp; - return { - status: 200, - body: { - text: `It is ${temperature} celsius degrees in ${location} and ${text}` - }, - headers: { - 'Content-Type': 'application/json' - } - }; - } catch (e) { - console.error(e); - return { - status: 500, - body: e - }; - } -} \ No newline at end of file diff --git a/examples/perl/hello.pm b/examples/perl/hello.pm deleted file mode 100644 index 680a4f64..00000000 --- a/examples/perl/hello.pm +++ /dev/null @@ -1,36 +0,0 @@ -=pod - -You return a CODEREF from the package that will be called as your function. - -The code in the server is something like this (simplified): - - my $sub = require('hello.pm'); - $sub->(request); - -As you can see, you get the L object as first argument -to your function. You can use it to retrieve params given to your function or -anything else Dancer2 offers. You can also use Dancer2 and use its DSL. - -=cut - -use utf8; -use strict; -use warnings; - -# Get more helper functions (status and send_as below) -use Dancer2; - -return sub { - my ($request) = @_; - - my ($name) = $request->query_parameters->{'name'} // 'world'; - - # set status code by name - status 'i_m_a_teapot'; - - # send message as JSON - send_as JSON => { - msg => "Hello, $name", - auth => $request->header('Authorization'), # read request header - }; -}; diff --git a/examples/php7/hello.php b/examples/php7/hello.php deleted file mode 100644 index 340116ab..00000000 --- a/examples/php7/hello.php +++ /dev/null @@ -1,3 +0,0 @@ -warning("Hello logger"); \ No newline at end of file diff --git a/examples/php7/hellopsr.php b/examples/php7/hellopsr.php deleted file mode 100644 index 31c9bdb4..00000000 --- a/examples/php7/hellopsr.php +++ /dev/null @@ -1,12 +0,0 @@ -getBody()->write("Hello from handler PHP"); - $logger->warning("Hello logger"); -} \ No newline at end of file diff --git a/examples/php7/multifile/README.md b/examples/php7/multifile/README.md deleted file mode 100644 index f5f80422..00000000 --- a/examples/php7/multifile/README.md +++ /dev/null @@ -1,69 +0,0 @@ -This is an example of creating a deployment package with multiple -files including external libraries via composer. - -### Create an environment - -``` -fission env create --name php --image fission/php-env:latest --builder fission/php-builder:latest --version 2 -``` - -### Create a zip file with all your files - -``` -zip -r multifile.zip . -i *.php *.txt composer.json -``` - -### Create a package -``` -fission package create --sourcearchive multifile.zip --env php -``` -This command will print the created package. We will use it in the next step. - - -### Create a function - -Since there are multiple files, you have to specify an _entrypoint_ to -for the function. Its format is `::`. In our -example, that's `handlers/FileReader.php::execute`, to run function `execute` in `handlers/FileReader.php`. - -``` -fission function create --name multifile --env php --pkg --entrypoint "handlers/FileReader.php::execute" -``` - -### Test it - -``` -fission function test --name multifile -``` - -You should see the "Hello, world" message. - - -## Updating the function - -### Edit a file - -``` -echo "I said hellooooo!" > message.txt -``` - -### Update the deployment package - -``` -zip -r multifile.zip . -i *.php *.txt composer.json -``` - -### Update the package - -``` -fission package update --name --sourcearchive multifile.zip --env php -``` - -### Test it - -``` -fission function test --name multifile -``` - -You should now see your new, edited message. - diff --git a/examples/php7/multifile/composer.json b/examples/php7/multifile/composer.json deleted file mode 100644 index 24b5ba72..00000000 --- a/examples/php7/multifile/composer.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "example/php7", - "description": "Example for php7 environment", - "require": { - "psr/log": "^1.1", - "psr/http-message": "^1.0" - }, - "authors": [ - { - "name": "Alberto Lopez", - "email": "alberto.lopez.benito@gmail.com" - } - ] -} diff --git a/examples/php7/multifile/handlers/FileReader.php b/examples/php7/multifile/handlers/FileReader.php deleted file mode 100644 index a5fc028f..00000000 --- a/examples/php7/multifile/handlers/FileReader.php +++ /dev/null @@ -1,16 +0,0 @@ -getBody()->write(file_get_contents(__DIR__ . '/message.txt')); - $logger->debug('File read: example.txt'); -} diff --git a/examples/php7/multifile/handlers/message.txt b/examples/php7/multifile/handlers/message.txt deleted file mode 100644 index 91fb05b9..00000000 --- a/examples/php7/multifile/handlers/message.txt +++ /dev/null @@ -1 +0,0 @@ -I said hellooooo! diff --git a/examples/php7/stock.php b/examples/php7/stock.php deleted file mode 100644 index ede840f5..00000000 --- a/examples/php7/stock.php +++ /dev/null @@ -1,47 +0,0 @@ -withStatus(500); - $response->getBody()->write($message); - return $response; -} - -function handler($context){ - /** @var ResponseInterface $response */ - $response = $context["response"]; - /** @var ServerRequestInterface $request */ - $request = $context["request"]; - /** @var LoggerInterface $logger */ - $logger = $context["logger"]; - - $logger->debug("Request : ",$request->getParsedBody()); - if($request->getMethod() != "POST") - return sendError($response,"You must use POST method"); - - $body = $request->getParsedBody(); - if(!isset($body["currency"])) - return sendError($response,"'currency' is not present in the POST request"); - - $allowedCurrency = ["ltc","btc"]; - if(!in_array($body["currency"],$allowedCurrency)) - return sendError($response,"'currency' is non allowed. Use one of them : ".implode(",",$allowedCurrency)); - - $curl = curl_init(); - curl_setopt_array($curl, array( - CURLOPT_RETURNTRANSFER => 1, - CURLOPT_URL => 'https://api.cryptonator.com/api/ticker/'.$body["currency"].'-usd' - )); - $result = curl_exec($curl); - curl_close($curl); - - $result = json_decode($result,true); - if($result){ - $logger->debug("Response API",$result); - $response->getBody()->write(json_encode(array("text"=>sprintf("%s-USB = %02f",$body["currency"],$result["ticker"]["price"])))); - }else - return sendError($response,"Cryptonator API not available"); - -} diff --git a/examples/python/README.md b/examples/python/README.md deleted file mode 100644 index 17522d9e..00000000 --- a/examples/python/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# Python Examples - -This directory contains a Python examples to show different the features of the Fission Python environment: -- `hello.py` is a simple Pythonic _hello world_ function. -- `requestdata.py` shows how you can access the HTTP request fields, such as the body, headers and query. -- `statuscode.py` is an example of how you can change the response status code. -- `multifile/` shows how to create Fission Python functions with multiple source files. -- `guestbook/` is a more realistic demonstration of using Python and Fission to create a serverless guestbook. -- `sourcepkg/` is an example of how to use the Fission Python Build environment to resolve (pip) dependencies - before deploying the function. - -## Getting Started - -Create a Fission Python environment with the default Python runtime image (this does not include the build environment): -``` -fission environment create --name python --image fission/python-env -``` - -Use the `hello.py` to create a Fission Python function: -``` -fission function create --name hello-py --env python --code hello.py -``` - -Test the function: -``` -fission function test --name hello-py -``` - -For a full guide see the [official documentation on Python with Fission](https://docs.fission.io/languages/python/). diff --git a/examples/python/guestbook/add.py b/examples/python/guestbook/add.py deleted file mode 100644 index f7a747ae..00000000 --- a/examples/python/guestbook/add.py +++ /dev/null @@ -1,18 +0,0 @@ -# -# Handles POST /guestbook -- adds item to guestbook -# - -from flask import request, redirect -import redis - -# Connect to redis. -redisConnection = redis.StrictRedis(host='redis.guestbook', port=6379, db=0) - -def main(): - # Read the item from POST params, add it to redis, and redirect - # back to the list - item = request.form['text'] - redisConnection.rpush('guestbook', item) - r = redirect('/guestbook', code=303) - r.autocorrect_location_header = False - return r diff --git a/examples/python/guestbook/deploy.sh b/examples/python/guestbook/deploy.sh deleted file mode 100755 index 815c0115..00000000 --- a/examples/python/guestbook/deploy.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -set -e - -kubectl create -f redis.yaml - -if [ -z "$FISSION_URL" ] -then - echo "Need $FISSION_URL set to a fission controller address" - exit 1 -fi - -# Create python env if it doesn't exist -fission env get --name python || fission env create --name python --image fission/python-env - -# Register functions and routes with fission -fission function create --name guestbook-get --env python --code get.py --url /guestbook --method GET -fission function create --name guestbook-add --env python --code add.py --url /guestbook --method POST diff --git a/examples/python/guestbook/get.py b/examples/python/guestbook/get.py deleted file mode 100644 index a95016b4..00000000 --- a/examples/python/guestbook/get.py +++ /dev/null @@ -1,28 +0,0 @@ -# -# Handles GET /guestbook -- returns a list of items in the guestbook -# with a form to add more. -# - -from flask import current_app, escape -import redis - -# Connect to redis. This is run only when this file is loaded; as -# long as the pod is alive, the connection is reused. -redisConnection = redis.StrictRedis(host='redis.guestbook', port=6379, db=0) - -def main(): - messages = redisConnection.lrange('guestbook', 0, -1) - - items = [("
  • %s
  • " % escape(m.decode('utf-8'))) for m in messages] - ul = "
      %s
    " % "\n".join(items) - return """ - -

    Guestbook

    -
    - - -
    -
    - %s - - """ % ul diff --git a/examples/python/guestbook/redis.yaml b/examples/python/guestbook/redis.yaml deleted file mode 100644 index 4269b0b5..00000000 --- a/examples/python/guestbook/redis.yaml +++ /dev/null @@ -1,45 +0,0 @@ -apiVersion: v1 -kind: Namespace -metadata: - name: guestbook - labels: - name: guestbook - ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - labels: - run: redis - name: redis - namespace: guestbook -spec: - replicas: 1 - selector: - matchLabels: - run: redis - template: - metadata: - labels: - run: redis - spec: - containers: - - image: redis - name: redis - ---- -apiVersion: v1 -kind: Service -metadata: - labels: - run: redis - name: redis - namespace: guestbook -spec: - selector: - run: redis - type: ClusterIP - ports: - - port: 6379 - protocol: TCP - targetPort: 6379 diff --git a/examples/python/hello.py b/examples/python/hello.py deleted file mode 100644 index 2c3a3088..00000000 --- a/examples/python/hello.py +++ /dev/null @@ -1,2 +0,0 @@ -def main(): - return "Hello, world!\n" diff --git a/examples/python/multifile/README.md b/examples/python/multifile/README.md deleted file mode 100644 index f822b5fc..00000000 --- a/examples/python/multifile/README.md +++ /dev/null @@ -1,62 +0,0 @@ -This is an example of creating a deployment package with multiple -files including some static data in text file. - -### Create an environment - -``` -fission env create --name python --image fission/python-env:0.4.0rc --version 2 -``` - -### Create a zip file with all your files - -``` -zip -jr multifile.zip *.py *.txt -``` - -### Create a function - -Since there are multiple files, you have to specify an _entrypoint_ to -for the function. Its format is `.`. In our -example, that's `main.main`, to run function `main` in `main.py`. - -``` -fission function create --name multifile --env python --code multifile.zip --entrypoint main.main -``` - -### Test it - -``` -fission function test --name multifile -``` - -You should see the "Hello, world" message. - - -## Updating the function - -### Edit a file - -``` -echo "I said hellooooo!" > message.txt -``` - -### Update the deployment package - -``` -zip -jr multifile.zip *.py *.txt -``` - -### Update the function - -``` -fission function update --name multifile --code multifile.zip -``` - -### Test it - -``` -fission function test --name multifile -``` - -You should now see your new, edited message. - diff --git a/examples/python/multifile/__init__.py b/examples/python/multifile/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/examples/python/multifile/main.py b/examples/python/multifile/main.py deleted file mode 100644 index bffcf997..00000000 --- a/examples/python/multifile/main.py +++ /dev/null @@ -1,11 +0,0 @@ -from flask import current_app -import sys -import readfile -import os - -def main(): - current_app.logger.info("Hi") - - current_dir = os.path.dirname(__file__) - - return readfile.readFile(os.path.join(current_dir, "message.txt")) diff --git a/examples/python/multifile/message.txt b/examples/python/multifile/message.txt deleted file mode 100644 index af5626b4..00000000 --- a/examples/python/multifile/message.txt +++ /dev/null @@ -1 +0,0 @@ -Hello, world! diff --git a/examples/python/multifile/readfile.py b/examples/python/multifile/readfile.py deleted file mode 100644 index 02e892bf..00000000 --- a/examples/python/multifile/readfile.py +++ /dev/null @@ -1,3 +0,0 @@ -def readFile(name): - with open(name) as f: - return f.read() diff --git a/examples/python/requestdata.py b/examples/python/requestdata.py deleted file mode 100644 index 93f725a5..00000000 --- a/examples/python/requestdata.py +++ /dev/null @@ -1,7 +0,0 @@ -from flask import request -from flask import current_app - -def main(): - current_app.logger.info("Received request") - msg = "---HEADERS---\n%s\n--BODY--\n%s\n-----\n" % (request.headers, request.get_data()) - return msg diff --git a/examples/python/sourcepkg/__init__.py b/examples/python/sourcepkg/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/examples/python/sourcepkg/build.sh b/examples/python/sourcepkg/build.sh deleted file mode 100755 index e9215130..00000000 --- a/examples/python/sourcepkg/build.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -pip3 install -r ${SRC_PKG}/requirements.txt -t ${SRC_PKG} && cp -r ${SRC_PKG} ${DEPLOY_PKG} \ No newline at end of file diff --git a/examples/python/sourcepkg/requirements.txt b/examples/python/sourcepkg/requirements.txt deleted file mode 100644 index c3726e8b..00000000 --- a/examples/python/sourcepkg/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -pyyaml diff --git a/examples/python/sourcepkg/user.py b/examples/python/sourcepkg/user.py deleted file mode 100644 index aef11272..00000000 --- a/examples/python/sourcepkg/user.py +++ /dev/null @@ -1,11 +0,0 @@ -import yaml - -document = """ - a: 1 - b: - c: 3 - d: 4 -""" - -def main(): - return yaml.dump(yaml.load(document), default_flow_style=None) diff --git a/examples/python/statuscode.py b/examples/python/statuscode.py deleted file mode 100644 index 7d747157..00000000 --- a/examples/python/statuscode.py +++ /dev/null @@ -1,4 +0,0 @@ -def main(): - # You can return any http status code you like, simply place a comma after - # your return statement, and typing in the status code. - return "Not Found\n", 404 diff --git a/examples/ruby/README.md b/examples/ruby/README.md deleted file mode 100644 index 741b9a04..00000000 --- a/examples/ruby/README.md +++ /dev/null @@ -1,115 +0,0 @@ -# Ruby examples - -This directory contains several examples to get you started using Ruby -with Fission. - -Before running any of these functions, make sure you have created a -`ruby` Fission environment: - -``` -$ fission env create --name ruby --image USER/ruby-env -``` - -## Method signature - -A standard Ruby function has the basic form: - -```ruby -def handler(context) - return [200, {}, []] -end -``` - -If the fission context is not required, the function can be simplified: - -```ruby -def handler - [200, {}, ["Hello, world!\n"]] -end -``` - -If a simple text response is to be returned, with a status of 200, this -can be further simplified. - -```ruby -def handler - "Hello, world!\n" -end -``` - -## Hello example (`hello.rb`) - -This example is the simplest possible Ruby function, as described above. - -To run the example: - -``` -$ fission function create --name hello --env ruby --code examples/ruby/hello.rb - -$ fission route create --method GET --url /hello --function hello - -$ curl http://$FISSION_ROUTER/hello - Hello, world! -``` - -## Request data example (`request_data.rb`) - -This example shows basic use of the `Fission::Context` and -`Fission::Request` objects. - -To run the example: - -``` -$ fission function create --name request --env ruby --code examples/ruby/request_data.rb - -$ fission route create --method GET --url /request/{id} --function request - -$ curl http://$FISSION_ROUTER/request/123?key=abc - ---ENV--- - GATEWAY_INTERFACE=CGI/1.1 - PATH_INFO=/ - QUERY_STRING=key=abc - REMOTE_ADDR=172.17.0.8 - REMOTE_HOST=172.17.0.8 - REQUEST_METHOD=GET - REQUEST_URI=http://192.168.64.200:31314/?key=abc - SCRIPT_NAME= - SERVER_NAME=192.168.64.200 - SERVER_PORT=31314 - SERVER_PROTOCOL=HTTP/1.1 - SERVER_SOFTWARE=WEBrick/1.3.1 (Ruby/2.4.1/2017-03-22) - HTTP_HOST=192.168.64.200:31314 - HTTP_USER_AGENT=curl/7.52.1 - HTTP_ACCEPT=*/* - HTTP_X_FISSION_PARAMS_ID=123 - HTTP_X_FORWARDED_FOR=172.17.0.1 - HTTP_ACCEPT_ENCODING=gzip - rack.version=1=3 - ... - HTTP_VERSION=HTTP/1.1 - REQUEST_PATH=/ - - ---HEADERS--- - Accept: */* - Accept-Encoding: gzip - Host: 192.168.64.200:31314 - User-Agent: curl/7.52.1 - Version: HTTP/1.1 - X-Fission-Params-Id: 123 - X-Forwarded-For: 172.17.0.1 - - ---PARAMS--- - key=abc - id=123 - - --BODY-- - -``` - -## V2 Specification Example (with builder support) - -``` -$ fission function create --name parse --env ruby --src "parse/*" --entrypoint handler -$ fission fn test --name parse --body 'This is my message' - This is my message -``` diff --git a/examples/ruby/events_to_slack.rb b/examples/ruby/events_to_slack.rb deleted file mode 100644 index 861ab50c..00000000 --- a/examples/ruby/events_to_slack.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true -require 'net/http' -require 'uri' -require 'json' - -SLACK_BASE_URL = 'https://hooks.slack.com/' -SLACK_WEBHOOK_PATH = 'YOUR RELATIVE PATH HERE' # Something like "/services/XXX/YYY/zZz123" - -def send_slack_message(message) - uri = URI.join(SLACK_BASE_URL, SLACK_WEBHOOK_PATH) - data = "{'channel': '#hackdays-serverless', 'username': 'fissionbot', 'text': \"#{message}\", 'icon_emoji': ':fission:'}" - res = Net::HTTP.post_form(uri, payload: data) - res.success? -end - -def handler(context) - request = context.request - - event_type = request.headers['X-Kubernetes-Event-Type'] - object_type = request.headers['X-Kubernetes-Object-Type'] - - object = JSON.parse(request.body.read) - object_name = object.dig('metadata', 'name') - object_namespace = object.dig('metadata', 'namespace') - - message = "#{event_type} #{object_type} #{object_namespace}/#{object_name}" - - if send_slack_message(message) - "Slack message sent - #{message}" - else - Rack::Response.new(["Failed to send Slack message - #{message}"], 500).finish - end -end diff --git a/examples/ruby/hello.rb b/examples/ruby/hello.rb deleted file mode 100644 index 75e4c88a..00000000 --- a/examples/ruby/hello.rb +++ /dev/null @@ -1,4 +0,0 @@ -# frozen_string_literal: true -def handler - "Hello, world!\n" -end diff --git a/examples/ruby/parse/Gemfile b/examples/ruby/parse/Gemfile deleted file mode 100644 index b24e9c93..00000000 --- a/examples/ruby/parse/Gemfile +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -source "https://rubygems.org" - -git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } - -gem "nokogiri" \ No newline at end of file diff --git a/examples/ruby/parse/Gemfile.lock b/examples/ruby/parse/Gemfile.lock deleted file mode 100644 index e1124d51..00000000 --- a/examples/ruby/parse/Gemfile.lock +++ /dev/null @@ -1,15 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - mini_portile2 (2.4.0) - nokogiri (1.10.8) - mini_portile2 (~> 2.4.0) - -PLATFORMS - ruby - -DEPENDENCIES - nokogiri - -BUNDLED WITH - 1.16.1 diff --git a/examples/ruby/parse/parse.rb b/examples/ruby/parse/parse.rb deleted file mode 100644 index 8f999b85..00000000 --- a/examples/ruby/parse/parse.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -require 'nokogiri' - -def handler(context) - context.logger.info("Received request") - - doc = Nokogiri::XML(context.request.body.read) - ele = doc.at_xpath('//message') - msg = ele.nil? ? 'No Message' : ele.content - - Rack::Response.new([msg, "\n"]).finish -end \ No newline at end of file diff --git a/examples/ruby/request_data.rb b/examples/ruby/request_data.rb deleted file mode 100644 index e05cc10a..00000000 --- a/examples/ruby/request_data.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true -def handler(context) - context.logger.info("Received request") - - msg = <<~MSG - ---ENV--- - #{context.request.env.map { |h| h.join('=') }.join("\n") } - - ---HEADERS--- - #{context.request.headers.map { |h| h.join(': ') }.join("\n") } - - ---PARAMS--- - #{context.request.params.map { |h| h.join('=') }.join("\n") } - - --BODY-- - #{context.request.body.read} - MSG - - Rack::Response.new([msg]).finish -end diff --git a/examples/spec-example/hello-spec-exmaple/README.md b/examples/spec-example/hello-spec-exmaple/README.md deleted file mode 100644 index 5b3b7e74..00000000 --- a/examples/spec-example/hello-spec-exmaple/README.md +++ /dev/null @@ -1,11 +0,0 @@ -This is the root directory of a declaratively specified fission "application". The app -contains source code for one function (a simple "hello world") in the hello/hello.py -file. - -The `specs` directory contains YAML files that specify the Fission environment and -function. - -You can create this app on your cluster by running `fission spec apply` from this -directory. See `fission spec --help` for other options. - -After applying the spec, you can test the function with `fission fn test --name hello`. diff --git a/examples/spec-example/hello-spec-exmaple/hello/__init__.py b/examples/spec-example/hello-spec-exmaple/hello/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/examples/spec-example/hello-spec-exmaple/hello/build.sh b/examples/spec-example/hello-spec-exmaple/hello/build.sh deleted file mode 100755 index 6f1ed084..00000000 --- a/examples/spec-example/hello-spec-exmaple/hello/build.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -set -e - -# check syntax -python3 -m compileall -l ${SRC_PKG} - -# install deps -pip3 install -r ${SRC_PKG}/requirements.txt -t ${SRC_PKG} && cp -r ${SRC_PKG} ${DEPLOY_PKG} diff --git a/examples/spec-example/hello-spec-exmaple/hello/hello.py b/examples/spec-example/hello-spec-exmaple/hello/hello.py deleted file mode 100644 index 95c7208b..00000000 --- a/examples/spec-example/hello-spec-exmaple/hello/hello.py +++ /dev/null @@ -1,4 +0,0 @@ -import yaml - -def main(): - return "hello, world!!\n" diff --git a/examples/spec-example/hello-spec-exmaple/hello/requirements.txt b/examples/spec-example/hello-spec-exmaple/hello/requirements.txt deleted file mode 100644 index c3726e8b..00000000 --- a/examples/spec-example/hello-spec-exmaple/hello/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -pyyaml diff --git a/examples/spec-example/hello-spec-exmaple/specs/env.yaml b/examples/spec-example/hello-spec-exmaple/specs/env.yaml deleted file mode 100644 index 082c5e98..00000000 --- a/examples/spec-example/hello-spec-exmaple/specs/env.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: fission.io/v1 -kind: Environment -metadata: - name: python-27 - namespace: default -spec: - version: 2 - builder: - command: build - image: fission/python-builder - runtime: - image: fission/python-env diff --git a/examples/spec-example/hello-spec-exmaple/specs/fission-deployment-config.yaml b/examples/spec-example/hello-spec-exmaple/specs/fission-deployment-config.yaml deleted file mode 100644 index 5b63e83f..00000000 --- a/examples/spec-example/hello-spec-exmaple/specs/fission-deployment-config.yaml +++ /dev/null @@ -1,3 +0,0 @@ -kind: DeploymentConfig -name: spec-example -uid: 27438a48-4191-4b5e-95b2-7793624317b9 diff --git a/examples/spec-example/hello-spec-exmaple/specs/hello.yaml b/examples/spec-example/hello-spec-exmaple/specs/hello.yaml deleted file mode 100644 index b7280658..00000000 --- a/examples/spec-example/hello-spec-exmaple/specs/hello.yaml +++ /dev/null @@ -1,46 +0,0 @@ -apiVersion: fission.io/v1 -kind: Function -metadata: - name: hello - namespace: default -spec: - InvokeStrategy: - ExecutionStrategy: - ExecutorType: poolmgr - MaxScale: 0 - MinScale: 0 - SpecializationTimeout: 120 - TargetCPUPercent: 0 - StrategyType: execution - environment: - name: python-27 - namespace: default - package: - packageref: - name: hello-pkg - namespace: default - functionName: hello.main - ---- -apiVersion: fission.io/v1 -kind: Package -metadata: - name: hello-pkg - namespace: default -spec: - source: - url: archive://hello-archive - buildcmd: "./build.sh" - environment: - name: python-27 - namespace: default -status: - buildstatus: pending - ---- -kind: ArchiveUploadSpec -name: hello-archive -include: - - "hello/*.py" - - "hello/*.sh" - - "hello/requirements.txt" diff --git a/examples/spec-example/nodejs-bodyParser-limit-example/hello/hello.js b/examples/spec-example/nodejs-bodyParser-limit-example/hello/hello.js deleted file mode 100644 index 4b099700..00000000 --- a/examples/spec-example/nodejs-bodyParser-limit-example/hello/hello.js +++ /dev/null @@ -1,11 +0,0 @@ -const process = require("process"); - -module.exports = async function (context) { - let message = - "BODY_PARSER_LIMIT received from env variable " + - process.env.BODY_PARSER_LIMIT; - return { - status: 200, - body: message, - }; -}; diff --git a/examples/spec-example/nodejs-bodyParser-limit-example/hello/package.json b/examples/spec-example/nodejs-bodyParser-limit-example/hello/package.json deleted file mode 100644 index 605772b6..00000000 --- a/examples/spec-example/nodejs-bodyParser-limit-example/hello/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "fission-nodejs-bodyParser-example", - "version": "0.1.0", - "author": "Rahul Bhati", - "contributors": [ - { - "name": "Rahul Bhati", - "email": "rjbhati009@gmail.com" - } - ], - "description": "Nodejs example for setting bodyParser limit param via environment variable", - "engines": { - "node": ">=7.6.0" - }, - "dependencies": {} -} diff --git a/examples/spec-example/nodejs-bodyParser-limit-example/specs/README b/examples/spec-example/nodejs-bodyParser-limit-example/specs/README deleted file mode 100644 index 1db3f9a5..00000000 --- a/examples/spec-example/nodejs-bodyParser-limit-example/specs/README +++ /dev/null @@ -1,42 +0,0 @@ - -Fission Specs -============= - -This is a set of specifications for a Fission app. This includes functions, -environments, and triggers; we collectively call these things "resources". - -How to use these specs ----------------------- - -These specs are handled with the 'fission spec' command. See 'fission spec --help'. - -'fission spec apply' will "apply" all resources specified in this directory to your -cluster. That means it checks what resources exist on your cluster, what resources are -specified in the specs directory, and reconciles the difference by creating, updating or -deleting resources on the cluster. - -'fission spec apply' will also package up your source code (or compiled binaries) and -upload the archives to the cluster if needed. It uses 'ArchiveUploadSpec' resources in -this directory to figure out which files to archive. - -You can use 'fission spec apply --watch' to watch for file changes and continuously keep -the cluster updated. - -You can add YAMLs to this directory by writing them manually, but it's easier to generate -them. Use 'fission function create --spec' to generate a function spec, -'fission environment create --spec' to generate an environment spec, and so on. - -You can edit any of the files in this directory, except 'fission-deployment-config.yaml', -which contains a UID that you should never change. To apply your changes simply use -'fission spec apply'. - -fission-deployment-config.yaml ------------------------------- - -fission-deployment-config.yaml contains a UID. This UID is what fission uses to correlate -resources on the cluster to resources in this directory. - -All resources created by 'fission spec apply' are annotated with this UID. Resources on -the cluster that are _not_ annotated with this UID are never modified or deleted by -fission. - diff --git a/examples/spec-example/nodejs-bodyParser-limit-example/specs/env-node.yaml b/examples/spec-example/nodejs-bodyParser-limit-example/specs/env-node.yaml deleted file mode 100644 index 35d79d0a..00000000 --- a/examples/spec-example/nodejs-bodyParser-limit-example/specs/env-node.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: fission.io/v1 -kind: Environment -metadata: - creationTimestamp: null - name: node - namespace: default -spec: - builder: - command: build - image: fission/node-builder:latest - imagepullsecret: "" - keeparchive: false - poolsize: 3 - resources: {} - runtime: - image: fission/node-env:latest - container: - env: - - name: BODY_PARSER_LIMIT - value: 100mb - version: 2 diff --git a/examples/spec-example/nodejs-bodyParser-limit-example/specs/fission-deployment-config.yaml b/examples/spec-example/nodejs-bodyParser-limit-example/specs/fission-deployment-config.yaml deleted file mode 100644 index 32f59282..00000000 --- a/examples/spec-example/nodejs-bodyParser-limit-example/specs/fission-deployment-config.yaml +++ /dev/null @@ -1,7 +0,0 @@ -# This file is generated by the 'fission spec init' command. -# See the README in this directory for background and usage information. -# Do not edit the UID below: that will break 'fission spec apply' -apiVersion: fission.io/v1 -kind: DeploymentConfig -name: node-spec -uid: 7a2704fb-6cff-4b4a-b5f8-71fe73365538 diff --git a/examples/spec-example/nodejs-bodyParser-limit-example/specs/function-hello.yaml b/examples/spec-example/nodejs-bodyParser-limit-example/specs/function-hello.yaml deleted file mode 100644 index b7d4c656..00000000 --- a/examples/spec-example/nodejs-bodyParser-limit-example/specs/function-hello.yaml +++ /dev/null @@ -1,54 +0,0 @@ -include: -- hello/* -kind: ArchiveUploadSpec -name: hello-dBc6 - ---- -apiVersion: fission.io/v1 -kind: Package -metadata: - creationTimestamp: null - name: hello-a98928ed-6b06-482f-9eb5-541540e714b1 - namespace: default -spec: - deployment: - checksum: {} - environment: - name: node - namespace: default - source: - checksum: {} - type: url - url: archive://hello-dBc6 -status: - buildstatus: pending - lastUpdateTimestamp: "2020-05-20T14:12:17Z" - ---- -apiVersion: fission.io/v1 -kind: Function -metadata: - creationTimestamp: null - name: hello - namespace: default -spec: - InvokeStrategy: - ExecutionStrategy: - ExecutorType: poolmgr - MaxScale: 0 - MinScale: 0 - SpecializationTimeout: 120 - TargetCPUPercent: 0 - StrategyType: execution - configmaps: null - environment: - name: node - namespace: default - functionTimeout: 60 - package: - functionName: hello - packageref: - name: hello-a98928ed-6b06-482f-9eb5-541540e714b1 - namespace: default - resources: {} - secrets: null diff --git a/examples/spec-example/podspec-example/README.md b/examples/spec-example/podspec-example/README.md deleted file mode 100644 index 9800286c..00000000 --- a/examples/spec-example/podspec-example/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# Adding podspec for builder of environment - -If you see the files in the `specs` directory you will get to know that we have just generated the -environment spec using the command -``` -fission env create --name python --image fission/python-env --builder fission/python-builder --spec -``` -and changed the env-python.yaml file to have below `podspec` for builder for the environment. - -``` -nodeSelector: - machinecap: high -tolerations: -- key: "env" - value: "prod" - operator: "Equal" - effect: "NoSchedule" - -``` - -If we create this environment, the builder pod that will be created will have the `PodSpec` that -we have mentioned for builder in the environment spec. - - diff --git a/examples/spec-example/podspec-example/specs/README b/examples/spec-example/podspec-example/specs/README deleted file mode 100644 index 1db3f9a5..00000000 --- a/examples/spec-example/podspec-example/specs/README +++ /dev/null @@ -1,42 +0,0 @@ - -Fission Specs -============= - -This is a set of specifications for a Fission app. This includes functions, -environments, and triggers; we collectively call these things "resources". - -How to use these specs ----------------------- - -These specs are handled with the 'fission spec' command. See 'fission spec --help'. - -'fission spec apply' will "apply" all resources specified in this directory to your -cluster. That means it checks what resources exist on your cluster, what resources are -specified in the specs directory, and reconciles the difference by creating, updating or -deleting resources on the cluster. - -'fission spec apply' will also package up your source code (or compiled binaries) and -upload the archives to the cluster if needed. It uses 'ArchiveUploadSpec' resources in -this directory to figure out which files to archive. - -You can use 'fission spec apply --watch' to watch for file changes and continuously keep -the cluster updated. - -You can add YAMLs to this directory by writing them manually, but it's easier to generate -them. Use 'fission function create --spec' to generate a function spec, -'fission environment create --spec' to generate an environment spec, and so on. - -You can edit any of the files in this directory, except 'fission-deployment-config.yaml', -which contains a UID that you should never change. To apply your changes simply use -'fission spec apply'. - -fission-deployment-config.yaml ------------------------------- - -fission-deployment-config.yaml contains a UID. This UID is what fission uses to correlate -resources on the cluster to resources in this directory. - -All resources created by 'fission spec apply' are annotated with this UID. Resources on -the cluster that are _not_ annotated with this UID are never modified or deleted by -fission. - diff --git a/examples/spec-example/podspec-example/specs/env-python.yaml b/examples/spec-example/podspec-example/specs/env-python.yaml deleted file mode 100644 index 3f09753d..00000000 --- a/examples/spec-example/podspec-example/specs/env-python.yaml +++ /dev/null @@ -1,25 +0,0 @@ -apiVersion: fission.io/v1 -kind: Environment -metadata: - creationTimestamp: null - name: python - namespace: default -spec: - builder: - command: build - image: fission/python-builder - podspec: - nodeSelector: - machinecap: high - tolerations: - - key: "env" - value: "prod" - operator: "Equal" - effect: "NoSchedule" - keeparchive: false - poolsize: 3 - resources: {} - runtime: - image: fission/python-env - terminationGracePeriod: 360 - version: 2 diff --git a/examples/spec-example/podspec-example/specs/fission-deployment-config.yaml b/examples/spec-example/podspec-example/specs/fission-deployment-config.yaml deleted file mode 100644 index 70028adf..00000000 --- a/examples/spec-example/podspec-example/specs/fission-deployment-config.yaml +++ /dev/null @@ -1,7 +0,0 @@ -# This file is generated by the 'fission spec init' command. -# See the README in this directory for background and usage information. -# Do not edit the UID below: that will break 'fission spec apply' -apiVersion: fission.io/v1 -kind: DeploymentConfig -name: podspec-example -uid: c0803d62-03a2-4934-b9b2-82f2a221a333 diff --git a/examples/tensorflow-serving/README.md b/examples/tensorflow-serving/README.md deleted file mode 100644 index f4c2e7de..00000000 --- a/examples/tensorflow-serving/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# Tensorflow Serving Environment Example - -## Create Environment - -```bash -$ fission env create --name tensorflow --image fission/tensorflow-serving-env --version 2 -``` - -## Create Package - -```bash -$ zip -r half_plus_two.zip ./half_plus_two -$ fission pkg create --env tensorflow --deploy half_plus_two.zip -``` - -## Create Function - -Here, the `--entrypoint` represents the name of the top directory contains the trained model and what kind of API the model supports. -Currently, three API are supported: `predict`, `classify`, `regress`. `predict` API will be used if no API kind was given. - -```bash -$ fission fn create --name t1 --pkg --env tensorflow --entrypoint "half_plus_two:predict" -$ fission fn test --name t1 --body '{"instances": [1.0, 2.0, 0.0]}' --method POST -``` diff --git a/examples/tensorflow-serving/half_plus_two/00000123/saved_model.pb b/examples/tensorflow-serving/half_plus_two/00000123/saved_model.pb deleted file mode 100644 index c79ebe01c240863890d2048ebee5da046c93a90a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9337 zcmd5?-H+Q?70=Cg&ZL>loqnWu+U*k2cJN9~CPSAtD$q^EYC-ByXeq3a#&T>=YfUE3 z#-4Uk9@qySKtgB*LLeaoJRFNP?*|B_`#=yP=L}aV{~eBI(Xxr`jb;%kKVUy5zRJ(1}=3h!?$(sr7^K- zap<}umft1qE3k3u+4{&ekDc+0`HSBZ0{5Ww$Q^q=+k~>D-!55P%Jyc!oR)oi?77qS z1(0u~7H|iu-?r?r@Axw=s53^{xS$&mA=G*ri-nI$F~W zTfz^Y;pb&29=P9~z+)&rG0bDyfU&9=oJVV!ER3ipH7aiFYjD z%E3SLP=8`fJ^Nc{#>r%4BVF+9se>+iV_T?h4N7Cc{pBO`%l|A$F9SL;H6ZtR}XHv|2@W{ z*CL=2pI(N#8rMKgL26>XMZn zhQvi^3O>3qwsdbK99dyoP?77<-y&zdb_;^5q}95Fr^X1%PmNb^$&Ied?IYNH`qG$M zw)LSivbiR-4%MOIiEA11sMOSI6?is`PfvK^np$3~z;NMF@KLJ*2LMm~DVDD9V9lTx zpe$+)&kRgRG@PtkSR0c0cm-;njfrHSiD}sr6j+|-zyo-0VD1e^XbX%CQE_E$!>ZeE zBtt=|dst0traSfxXKW|Pwy$E|q5`%h+!p7E#&4G}-Cx;SY46VcJKbL8bbLH^Uytb@ z_rZisqvMPnAFF{b@`=it+`iDU>{saQ{-Y;9=y$b^umI<~M7sgK7cBrIjxw><-Q3%5QE0lR%vg>wL&9tW`Zu|L|5XxmDHbG`nLqCMkm48492uU6X;YiEr!$_FdWur5-4U0y5 z7>cz-ibedgh@(G;EBSMws~)aoZ0^tD|Hhxgls|_|Rd|UdRhW|H&*7T>9H#s^Tp~r< zpTo>xL4TSn`E#W#S>*JG54k_hW&T`=b~*#KrFkv#(@go(WU9idB^M>2xrW2Ej-?E zQPQ`g~3L(AO-9rWcf9Li;K9@5SOt${6p|@Ydtpu0EjYQ)7u%LG{I42@G zD?@1Lgxa7|tIJ)|Kcmg=a_&12j1AIqK`1ft-k{RV~874_fkns8G{s>Aas=i0hkvLRPTUB)U81l286j`!h!A__Oy*}v? zU|Pi-x)V>RPW-07r*d0W{`oHZu{06t5_c*}@I{c$&-PSftzeW@Qnk)OnCtim?3OH5{B>~oy7xOP+54MzVA~}PvRIg)m5ayo*9GZvoM}jk>>Jxnrz6AC8 zvWU+{Y$ZIw4j6VL67VQ~_Nin6@+4T``&8+~#hxJij6h3}oOcTlw_{t$)e)WEL|NhYG+QYkh_R-hwcaM&Y&cvAdD~SiE zu&GEvWBm&j)0$<9%k$`f@;Z+Ie%{64_%LJlhVKPz=Z%z5=h)_7$od@jgaCo@&A&i% z9DN-FlbR&^I2`g#t@Ahhb(rPgmk9M1aieM*iK*sgOQZ}I&yAwwY?eI`aRts19kWin zA$Pv!l_mJGpj``1y*=2%807G}Fd)W&3R~q)u~NQR`CnfHD65OyG(Th&SA( z?ueH=dyH_`oW=IB#p2ZuW2&f5za2G@uEP$!DjG;~c{0+oq9feqD)4s#?};zdvyIMz z!3Gsmg)ECok<-em;%7UNXb_AZIARPi0!|QQH6c97q(#%>(gougwvKM`%BD(uDLu8p z#t;00;EaJsTr^3V_u~?EQd%Z0G;6JDvy8GC*$Cdiju0j4$*+?0OH+CE%=-!4PcPR}?Dl#HG<{2>fwDH$S;sNX$g&7^(P_&P%Kt2eyYYLKeZ_2$x< zDd|!WeUa_H$adckfeHgnrc{V9%$ zIC#g|jvP99^f!clMsR{&Fpy+4Az^sMhZ6m6Z%dg7^}F}P`XOH*okZ{|T(3+V!u2L! zA0Ag2UWMzGjy7N4{tJQH|GSL0VVnEI(goz#PtdlyJHe4D7LWLeLwki?dp;s^j<7GP z`>sBtCcG2Q4(Ualu|`ecez#d+Sb6A|q3oG1I+HRe%5dB9kznv>_A{0(7vVK*PVE<{g%@bvqt>~q z--3!9Cwi1~&JvKZ1G>iTBL~N diff --git a/examples/tensorflow-serving/half_plus_two/00000123/variables/variables.data-00000-of-00001 b/examples/tensorflow-serving/half_plus_two/00000123/variables/variables.data-00000-of-00001 deleted file mode 100644 index 15b75d6ef6bffc336d138d923badb3928b8c4c13..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12 RcmZQzV6bOkU~m8;2LJ>^0RR91 diff --git a/examples/tensorflow-serving/half_plus_two/00000123/variables/variables.index b/examples/tensorflow-serving/half_plus_two/00000123/variables/variables.index deleted file mode 100644 index 7ec9fb4fe2dd21d0a6c324aecd7658fc37cf2326..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 151 zcmZQzVB=tvV&Y(AVB}8ZU=(7|U@>L0P?u+5