mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Examples changes (#201)
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
FROM iron/ruby:dev
|
||||
|
||||
WORKDIR /worker
|
||||
ADD Gemfile* /worker/
|
||||
WORKDIR /function
|
||||
ADD Gemfile /function/
|
||||
RUN bundle install
|
||||
|
||||
ADD . /worker/
|
||||
ADD . /function/
|
||||
|
||||
ENTRYPOINT ["ruby", "checker.rb"]
|
||||
ENTRYPOINT ["ruby", "function.rb"]
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
json (1.8.3)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
json (> 1.8.2)
|
||||
|
||||
BUNDLED WITH
|
||||
1.10.5
|
||||
@@ -1,22 +1,78 @@
|
||||
This is a worker that we can use to check inputs to the job, such as env vars.
|
||||
# Environment Checker Function Image
|
||||
|
||||
Pass in checks via the payload:
|
||||
This images compares the payload info with the header.
|
||||
|
||||
```json
|
||||
{
|
||||
"env_vars": {
|
||||
"foo": "bar"
|
||||
}
|
||||
}
|
||||
```
|
||||
## Requirements
|
||||
|
||||
That will check that there is an env var called foo with the value bar passed to the task.
|
||||
- IronFunctions API
|
||||
|
||||
## Building Image
|
||||
## Development
|
||||
|
||||
Install [dj](https://github.com/treeder/dj/), then run:
|
||||
### Building image locally
|
||||
|
||||
```
|
||||
docker build -t iron/checker .
|
||||
docker run -e 'PAYLOAD={"env_vars": {"FOO": "bar"}}' -e "FOO=bar" iron/checker
|
||||
# SET BELOW TO YOUR DOCKER HUB USERNAME
|
||||
USERNAME=YOUR_DOCKER_HUB_USERNAME
|
||||
|
||||
# build it
|
||||
./build.sh
|
||||
```
|
||||
|
||||
### Publishing to DockerHub
|
||||
|
||||
```
|
||||
# tagging
|
||||
docker run --rm -v "$PWD":/app treeder/bump patch
|
||||
docker tag $USERNAME/func-checker:latest $USERNAME/func-checker:`cat VERSION`
|
||||
|
||||
# pushing to docker hub
|
||||
docker push $USERNAME/func-checker
|
||||
```
|
||||
|
||||
### Testing image
|
||||
|
||||
```
|
||||
./test.sh
|
||||
```
|
||||
|
||||
## Running it on IronFunctions
|
||||
|
||||
### Let's define some environment variables
|
||||
|
||||
```
|
||||
# Set your Function server address
|
||||
# Eg. 127.0.0.1:8080
|
||||
FUNCAPI=YOUR_FUNCTIONS_ADDRESS
|
||||
```
|
||||
|
||||
### Running with IronFunctions
|
||||
|
||||
With this command we are going to create an application with name `checker`.
|
||||
|
||||
```
|
||||
curl -X POST --data '{
|
||||
"app": {
|
||||
"name": "checker",
|
||||
}
|
||||
}' http://$FUNCAPI/v1/apps
|
||||
```
|
||||
|
||||
Now, we can create our route
|
||||
|
||||
```
|
||||
curl -X POST --data '{
|
||||
"route": {
|
||||
"image": "'$USERNAME'/func-checker",
|
||||
"path": "/check",
|
||||
"config": { "TEST": "1" }
|
||||
}
|
||||
}' http://$FUNCAPI/v1/apps/checker/routes
|
||||
```
|
||||
|
||||
#### Testing function
|
||||
|
||||
Now that we created our IronFunction route, let's test our new route
|
||||
|
||||
```
|
||||
curl -X POST --data '{ "env_vars": { "config_test": "1" } }' http://$FUNCAPI/r/checker/check
|
||||
```
|
||||
1
examples/checker/VERSION
Normal file
1
examples/checker/VERSION
Normal file
@@ -0,0 +1 @@
|
||||
0.0.1
|
||||
5
examples/checker/build.sh
Executable file
5
examples/checker/build.sh
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
set -ex
|
||||
|
||||
# build image
|
||||
docker build -t iron/func-checker .
|
||||
@@ -1,13 +0,0 @@
|
||||
require 'json'
|
||||
|
||||
payload = JSON.parse(ENV['PAYLOAD'])
|
||||
|
||||
# payload contains checks
|
||||
if payload["env_vars"]
|
||||
payload["env_vars"].each do |k,v|
|
||||
if ENV[k] != v
|
||||
raise "Env var #{k} does not match"
|
||||
end
|
||||
end
|
||||
end
|
||||
puts "all good"
|
||||
16
examples/checker/function.rb
Normal file
16
examples/checker/function.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
require 'json'
|
||||
|
||||
payload = STDIN.read
|
||||
if payload != ""
|
||||
payload = JSON.parse(payload)
|
||||
|
||||
# payload contains checks
|
||||
if payload["env_vars"]
|
||||
payload["env_vars"].each do |k,v|
|
||||
if ENV[k] != v
|
||||
raise "Env var #{k} does not match"
|
||||
end
|
||||
end
|
||||
end
|
||||
puts "all good"
|
||||
end
|
||||
3
examples/checker/functions.yml
Normal file
3
examples/checker/functions.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
image: iron/func-checker
|
||||
build:
|
||||
- ./build.sh
|
||||
9
examples/checker/test.sh
Executable file
9
examples/checker/test.sh
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
set -x
|
||||
|
||||
./build.sh
|
||||
|
||||
PAYLOAD='{"env_vars": {"FOO": "bar"}}'
|
||||
|
||||
# test it
|
||||
echo $PAYLOAD | docker run --rm -i -e TEST=1 -e FOO=bar iron/func-checker
|
||||
Reference in New Issue
Block a user