From 8fe7cb691d015b0d6e40785189036ef648328ecf Mon Sep 17 00:00:00 2001 From: Alex Ellis <AlexEllis2@gmail.com> Date: Thu, 22 Dec 2016 13:08:32 +0000 Subject: [PATCH] Initial --- watchdog/Dockerfile | 7 +++++++ watchdog/Dockerfile.build | 6 ++++++ watchdog/build.sh | 7 +++++++ watchdog/main.go | 42 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 watchdog/Dockerfile create mode 100644 watchdog/Dockerfile.build create mode 100755 watchdog/build.sh create mode 100644 watchdog/main.go diff --git a/watchdog/Dockerfile b/watchdog/Dockerfile new file mode 100644 index 00000000..d55ad676 --- /dev/null +++ b/watchdog/Dockerfile @@ -0,0 +1,7 @@ +FROM alpine:edge + +COPY ./fwatchdog /usr/bin/fwatchdog +ENV fprocess "cat -b" + +EXPOSE 8080 +CMD ["fwatchdog"] diff --git a/watchdog/Dockerfile.build b/watchdog/Dockerfile.build new file mode 100644 index 00000000..b9ea1866 --- /dev/null +++ b/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 diff --git a/watchdog/build.sh b/watchdog/build.sh new file mode 100755 index 00000000..76164212 --- /dev/null +++ b/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 + diff --git a/watchdog/main.go b/watchdog/main.go new file mode 100644 index 00000000..0e603bcb --- /dev/null +++ b/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()) +} + -- GitLab