Fixed builds, added metric output.

This commit is contained in:
Travis Reeder
2016-06-16 19:32:12 -07:00
parent 222c434fa2
commit 60db6e1d51
7 changed files with 111 additions and 73 deletions

1
.gitignore vendored
View File

@@ -9,3 +9,4 @@ app.zip
/app
vendor/
/microgateway
/gateway

View File

@@ -1,7 +1,7 @@
FROM treeder/go-dind
FROM iron/dind
RUN mkdir /app
ADD app /app/gateway
ADD gateway /app/
WORKDIR /app
ENTRYPOINT rc default && sleep 1 && ./gateway && sleep 1
CMD ["./gateway"]

View File

@@ -14,6 +14,8 @@ Now add routes to the app. First we'll add a route to the output of a docker con
curl -H "Content-Type: application/json" -X POST -d '{"path":"/hello.rb","image":"treeder/hello.rb", "type":"run"}' http://localhost:8080/test/1/projects/123/apps/myapp/routes
```
curl -H "Content-Type: application/json" -X POST -d '{"path":"/helloiron","image":"iron/hello", "type":"run"}' http://localhost:8080/test/1/projects/123/apps/myapp/routes
Test out the route:
```sh
@@ -44,27 +46,27 @@ 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.projectid.iron.computer
```
## Building/Testing
```sh
dj go build
docker run -e "IRON_TOKEN=GP8cqlKSrcpmqeR8x9WKD4qSAss" -e "IRON_PROJECT_ID=4fd2729368a0197d1102056b" --rm -it --privileged --net=host -v "$PWD":/app -w /app -p 8080:8080 treeder/go-dind sh -c 'rc default && ./app'
```
Then run the commands above to use it.
Build image:
Build:
```sh
docker build -t iron/gateway:latest .
# one time:
glide install
# then every time
./build.sh
```
Test it, the iron token and project id are for cache.
```sh
docker run -e "IRON_TOKEN=GP8cqlKSrcpmqeR8x9WKD4qSAss" -e "IRON_PROJECT_ID=4fd2729368a0197d1102056b" --rm -it --privileged --net=host -p 8080:8080 iron/gateway
docker run -e "IRON_TOKEN=GP8cqlKSrcpmqeR8x9WKD4qSAss" -e "IRON_PROJECT_ID=4fd2729368a0197d1102056b" --rm -it --privileged -p 8080:8080 iron/gateway
```
Push it:
@@ -80,61 +82,3 @@ After deploying, running it with:
```sh
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
```
# Previous version:
## What's going on?
- worker.rb connects to router and adds routes.
- client.rb connects to router which checks the routing table, proxies the request to one of the destinations and returns the response.
The idea here is that IronWorker backend can tell the router that it started a process and to start routing requests.
## Usage
```
iron worker upload --name hello-sinatra --host YOURHOST treeder/hello-sinatra
```
Then hit the url:
```
http://router.iron.io/?rhost=YOURHOST
```
## Todo
This is just a simple prototype. To get to production would need:
- Ability to start new workers based on some auto scaling scheme.
- Authentication (same as always).
## Testing for reals on staging
### 1) Deploy router
Using DockerJockey:
```
dj run --on aws -i --name router -v "$(pwd)":/app -w /app -p 80:8080 treeder/golang-ubuntu:1.3.3on14.04 ./router
```
### 2) Update DNS
Update DNS entry `router.iron.io` to point to the newly launched server after dj deploy.
Or SimpleDeployer:
- start router.go on remote server (there's a test project on SD already:
- http://www.simpledeployer.com/projects/ea129e74-52fa-11e2-a91a-12313d008ea2/servers
- this is on aws+sandbox@iron.io account
- go build ./src/router; sudo ./router
- iron_worker upload -e staging --project-id 515b657bc731ff1e69000917 --host routertest-staging.irondns.info sinatra
- visit http://routertest.iron.io (or ruby client.rb)
- BOOM!
## Deploying to production
- just deploy as normal from SD project
- use routertest.irondns.info for host

4
build.sh Executable file
View File

@@ -0,0 +1,4 @@
set -ex
docker run --rm -v "$PWD":/go/src/github.com/iron-io/microgateway -w /go/src/github.com/iron-io/microgateway iron/go:dev sh -c 'go build -o gateway'
docker build -t iron/gateway:latest .

74
glide.lock generated Normal file
View File

@@ -0,0 +1,74 @@
hash: a104a522dc2ba982d25101330bbd5d44778565128f0cb09f34061c167921046c
updated: 2016-06-15T17:17:05.21953321-07:00
imports:
- name: github.com/amir/raidman
version: 91c20f3f475cab75bb40ad7951d9bbdde357ade7
subpackages:
- proto
- name: github.com/BurntSushi/toml
version: f0aeabca5a127c4078abb8c8d64298b147264b55
- name: github.com/cactus/go-statsd-client
version: 91c326c3f7bd20f0226d3d1c289dd9f8ce28d33d
subpackages:
- statsd
- name: github.com/dgrijalva/jwt-go
version: c04502f106d7c5b3fae17c5da49a1bbdd3006b3c
- name: github.com/golang/protobuf
version: 0c1f6d65b5a189c2250d10e71a5506f06f9fa0a0
subpackages:
- proto
- name: github.com/gorilla/context
version: aed02d124ae4a0e94fea4541c8effd05bf0c8296
- name: github.com/gorilla/mux
version: 9fa818a44c2bf1396a17f9d5a3c0f6dd39d2ff8e
- name: github.com/iron-io/common
version: 7c9faec363c808052742b4c4b84876c4c2172308
subpackages:
- httpshutdown
- msgpack
- semaphore
- serverutil
- name: github.com/iron-io/go
version: 277190779e20ad6bff386a5f7f6a8009d73fa475
subpackages:
- common
- common/httpshutdown
- common/msgpack
- common/semaphore
- common/stats
- common/serverutil
- name: github.com/iron-io/golog
version: 5b80d97af5a2a5d386e7609efb82192ae99a7c67
- name: github.com/iron-io/iron_go
version: 920c950272e820d9e2562fcbf40303f05564f118
subpackages:
- cache
- worker
- api
- config
- name: github.com/mattn/go-colorable
version: 9056b7a9f2d1f2d96498d6d146acd1f9d5ed3d59
- name: github.com/mattn/go-isatty
version: 56b76bdf51f7708750eac80fa38b952bb9f32639
- name: github.com/vmihailenco/bufio
version: 24e7e48f60fc2d9e99e43c07485d9fff42051e66
- name: github.com/vrischmann/envconfig
version: 9e6e1c4d3b73427d03118518603bb904d9c55236
- name: golang.org/x/net
version: 3f122ce3dbbe488b7e6a8bdb26f41edec852a40b
subpackages:
- proxy
- name: golang.org/x/sys
version: 62bee037599929a6e9146f29d10dd5208c43507d
subpackages:
- unix
- name: gopkg.in/inconshreveable/log15.v2
version: b105bd37f74e5d9dc7b6ad7806715c7a2b83fd3f
subpackages:
- stack
- term
- name: gopkg.in/mgo.v2
version: 29cc868a5ca65f401ff318143f9408d02f4799cc
subpackages:
- bson
devImports: []

13
glide.yaml Normal file
View File

@@ -0,0 +1,13 @@
package: github.com/iron-io/microgateway
import:
- package: github.com/gorilla/mux
- package: github.com/iron-io/common
- package: github.com/iron-io/go
subpackages:
- common
- package: github.com/iron-io/golog
- package: github.com/iron-io/iron_go
subpackages:
- cache
- worker
- package: gopkg.in/inconshreveable/log15.v2

View File

@@ -4,17 +4,16 @@ import (
"bufio"
"bytes"
"fmt"
// "github.com/gorilla/mux"
"github.com/iron-io/go/common"
"github.com/iron-io/golog"
"io"
"io/ioutil"
"log"
"math/rand"
"net/http"
"os"
"os/exec"
"strings"
log "github.com/Sirupsen/logrus"
)
type RunningApp struct {
@@ -95,13 +94,16 @@ func DockerRun(image string, w http.ResponseWriter) {
log.Printf("Waiting for command to finish...")
if err = cmd.Wait(); err != nil {
// this probably shouldn't be fatal? test with iron/error image
log.Fatal(err)
}
log.WithFields(log.Fields{"metric": "ran", "value": 1, "type": "count"}).Infoln("")
log.Printf("Command finished with error: %v", err)
buff.Flush()
golog.Infoln("Docker ran successfully:", b.String())
fmt.Fprintln(w, b.String())
}
func DockerHost(el *Route3, w http.ResponseWriter) {
ra := runningImages[el.Image]
if ra == nil {