Fix run env vars passed in via command line to test locally and updated docs to match.

This commit is contained in:
Travis Reeder
2017-05-30 10:54:34 -07:00
committed by Reed Allman
parent 7b408468fa
commit af918fdfe9
14 changed files with 79 additions and 41 deletions

View File

@@ -1,7 +1,7 @@
FROM funcy/ruby:dev
WORKDIR /function
ADD Gemfile /function/
ADD Gemfile* /function/
RUN bundle install
ADD . /function/

View File

@@ -1 +0,0 @@
0.0.1

View File

@@ -1,5 +0,0 @@
#!/bin/bash
set -ex
# build image
docker build -t username/func-checker .

View File

@@ -1,3 +1,4 @@
name: username/func-checker
build:
- ./build.sh
version: 0.0.1
entrypoint: ruby function.rb
runtime: ruby

View File

@@ -1,6 +1,11 @@
require 'json'
require 'uri'
puts "Running checker..."
payload = STDIN.read
puts "payload #{payload}"
p ENV
if payload != ""
payload = JSON.parse(payload)
@@ -13,4 +18,24 @@ if payload != ""
end
end
puts "all good"
end
end
# Also check for expected env vars: https://gitlab.oracledx.com/odx/functions/blob/master/docs/writing.md#inputs
e = ENV["REQUEST_URL"]
puts e
uri = URI.parse(e)
if !uri.scheme.start_with?('http')
raise "invalid REQUEST_URL, does not start with http"
end
e = ENV["METHOD"]
if !(e == "GET" || e == "POST" || e == "DELETE" || e == "PATCH" || e == "PUT")
raise "Invalid METHOD: #{e}"
end
e = ENV["APP_NAME"]
if e == nil || e == ''
raise "No APP_NAME found"
end
e = ENV["ROUTE"]
if e == nil || e == ''
raise "No ROUTE found"
end

View File

@@ -1,9 +1,8 @@
#!/bin/bash
set -x
./build.sh
set -ex
PAYLOAD='{"env_vars": {"FOO": "bar"}}'
# test it
echo $PAYLOAD | docker run --rm -i -e TEST=1 -e FOO=bar username/func-checker
: ${FN:="fn"}
echo $PAYLOAD | $FN run -e FOO=bar