Skip to content
Snippets Groups Projects
Commit 8fe7cb69 authored by Alex Ellis's avatar Alex Ellis
Browse files

Initial

parent d94cfeb6
No related branches found
No related tags found
No related merge requests found
FROM alpine:edge
COPY ./fwatchdog /usr/bin/fwatchdog
ENV fprocess "cat -b"
EXPOSE 8080
CMD ["fwatchdog"]
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
#!/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
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% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment