Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
alexellis committed Dec 22, 2016
1 parent d94cfeb commit 8fe7cb6
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
7 changes: 7 additions & 0 deletions watchdog/Dockerfile
@@ -0,0 +1,7 @@
FROM alpine:edge

COPY ./fwatchdog /usr/bin/fwatchdog
ENV fprocess "cat -b"

EXPOSE 8080
CMD ["fwatchdog"]
6 changes: 6 additions & 0 deletions watchdog/Dockerfile.build
@@ -0,0 +1,6 @@
FROM golang:1.7.3
RUN mkdir -p /go/src/fwatchdog
COPY main.go /go/src/fwatchdog
WORKDIR /go/src/fwatchdog
RUN go get -d -v
RUN go build
7 changes: 7 additions & 0 deletions watchdog/build.sh
@@ -0,0 +1,7 @@
#!/bin/bash

docker build -t watchdog:latest . -f Dockerfile.build
docker create --name buildoutput watchdog:latest
docker cp buildoutput:/go/src/fwatchdog/fwatchdog ./
docker rm buildoutput

42 changes: 42 additions & 0 deletions watchdog/main.go
@@ -0,0 +1,42 @@
package main

import (
"io/ioutil"
"log"
"net/http"
"os"
"os/exec"
"strings"
"time"
)

func main() {
s := &http.Server{
Addr: ":8080",
ReadTimeout: 2 * time.Second,
WriteTimeout: 2 * time.Second,
MaxHeaderBytes: 1 << 20,
}

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.Method == "POST" {
process := os.Getenv("fprocess")
parts := strings.Split(process, " ")
targetCmd := exec.Command(parts[0], parts[1:]...)
writer, _ := targetCmd.StdinPipe()
res, _ := ioutil.ReadAll(r.Body)
writer.Write(res)
writer.Close()
out, err := targetCmd.Output()
if err != nil {
panic(err)
}

os.Stdout.Write(out)
w.Write(out)
}
})

log.Fatal(s.ListenAndServe())
}

0 comments on commit 8fe7cb6

Please sign in to comment.