mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
0794db8426d87010ea5bd7af4fdadec18996e58e
Note: currently running at: http://gateway.iron.computer:8080/
MicroServices Gateway / API Gateway
First things first, create an app/service:
TOOD: App or service??
iron create app
# OR
curl -H "Content-Type: application/json" -X POST -d '{"name":"myapp"}' http://localhost:8080/api/v1/apps
Now add routes to the app. First we'll add a route to the output of a docker container:
iron add route myapp /hello iron/hello
# OR
curl -H "Content-Type: application/json" -X POST -d '{"path":"/hello", "image":"iron/hello", "type":"run"}' http://localhost:8080/api/v1/apps/myapp/routes
And how about a slackbot endpoint:
curl -H "Content-Type: application/json" -X POST -d '{"path":"/guppy","image":"treeder/guppy:0.0.2", "content_type": "application/json"}' http://localhost:8080/api/v1/apps/myapp/routes
Test out the route:
Surf to: http://localhost:8080/hello?app=myapp
Now try mapping an app endpoint:
curl -H "Content-Type: application/json" -X POST -d '{"path":"/sinatra","image":"treeder/hello-sinatra", "type":"app", "cpath":"/"}' http://localhost:8080/api/v1/apps/myapp/routes
And test it out:
curl -i -X GET http://localhost:8080/sinatra?app=myapp
And another:
curl -H "Content-Type: application/json" -X POST -d '{"path":"/sinatra/ping","image":"treeder/hello-sinatra", "type":"app", "cpath":"/ping"}' http://localhost:8080/api/v1/apps/myapp/routes
And test it out:
curl -i -X GET http://localhost:8080/sinatra?app=myapp
You'all also get a custom URL like this when in production.
appname.iron.computer
Updating Your Images
Tag your images with a version, eg treeder/guppy:0.0.5 then use that including the tag and update
the route.
Building/Testing
Build:
# one time:
glide install
# then every time
./build.sh
Test it, the iron token and project id are for cache.
docker run -e "IRON_TOKEN=GP8cqlKSrcpmqeR8x9WKD4qSAss" -e "IRON_PROJECT_ID=4fd2729368a0197d1102056b" -e "CLOUDFLARE_EMAIL=treeder@gmail.com" -e "CLOUDFLARE_API_KEY=X" --rm -it --privileged -p 8080:8080 iron/gateway
Push it:
docker push iron/gateway
Get it on a server and point router.iron.computer (on cloudflare) to the machine.
After deploying, running it with:
docker run -e "IRON_TOKEN=GP8cqlKSrcpmqeR8x9WKD4qSAss" -e "IRON_PROJECT_ID=4fd2729368a0197d1102056b" --name irongateway -it --privileged --net=host -p 8080:8080 -d --name irongateway iron/gateway
TODOS
- Check if image exists when registering the endpoint, not at run time
- Put stats into influxdb or something to show to user (requests, errors)
- Store recent logs for user.
- Allow env vars for config on the app and routes (routes override apps).
- Provide a base url for each app, eg: appname.userid.iron.computer
- Allow setting content-type on a route, then use that when responding
- Maybe use STDERR for logs and STDOUT is used for the response.
Description
Languages
Go
97.4%
Shell
1.2%
Ruby
0.5%
Makefile
0.4%
Dockerfile
0.4%
Other
0.1%