mirror of
https://github.com/cupcakearmy/master-thesis.git
synced 2025-09-06 02:30:43 +00:00
Clear History
This commit is contained in:
11
code/images/sidecar/Dockerfile
Normal file
11
code/images/sidecar/Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
||||
FROM golang:1.20 as builder
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
RUN go build
|
||||
|
||||
FROM ubuntu
|
||||
RUN apt-get update && apt-get install -y dnsutils
|
||||
WORKDIR /app
|
||||
COPY --from=builder /app .
|
||||
EXPOSE 42069
|
||||
CMD /app/sidecar
|
3
code/images/sidecar/go.mod
Normal file
3
code/images/sidecar/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module iluzio.nicco.io/sidecar
|
||||
|
||||
go 1.20
|
44
code/images/sidecar/main.go
Normal file
44
code/images/sidecar/main.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var SERVICE = os.Getenv("SERVICE")
|
||||
|
||||
func getIPs() []string {
|
||||
out, err := exec.Command("dig", "+short", "+search", SERVICE).Output()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return []string{}
|
||||
}
|
||||
|
||||
trimmed := strings.TrimSpace(fmt.Sprintf("%s", out))
|
||||
if trimmed == "" {
|
||||
return []string{}
|
||||
} else {
|
||||
return strings.Split(trimmed, "\n")
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/discoverable", func(w http.ResponseWriter, r *http.Request) {
|
||||
ips := getIPs()
|
||||
plain := r.URL.Query().Get("format") == "plain"
|
||||
if plain {
|
||||
fmt.Fprintf(w, "%s\n", strings.Join(ips, "\n"))
|
||||
} else {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(ips)
|
||||
}
|
||||
})
|
||||
|
||||
log.Fatal(http.ListenAndServe(":42069", nil))
|
||||
|
||||
}
|
Reference in New Issue
Block a user