mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Fix run env vars passed in via command line to test locally and updated docs to match.
This commit is contained in:
committed by
Reed Allman
parent
7b408468fa
commit
af918fdfe9
@@ -1,7 +1,7 @@
|
||||
FROM funcy/ruby:dev
|
||||
|
||||
WORKDIR /function
|
||||
ADD Gemfile /function/
|
||||
ADD Gemfile* /function/
|
||||
RUN bundle install
|
||||
|
||||
ADD . /function/
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
0.0.1
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -ex
|
||||
|
||||
# build image
|
||||
docker build -t username/func-checker .
|
||||
@@ -1,3 +1,4 @@
|
||||
name: username/func-checker
|
||||
build:
|
||||
- ./build.sh
|
||||
version: 0.0.1
|
||||
entrypoint: ruby function.rb
|
||||
runtime: ruby
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user