-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
neonvm: Add new skeleton neonvm-daemon binary
Extracted the minimal version from a PR, because it's clear that this daemon is required in multiple places, and we don't know which PR will merge first.
- Loading branch information
Showing
8 changed files
with
145 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
ARG GO_BASE_IMG=autoscaling-go-base:dev | ||
FROM $GO_BASE_IMG AS builder | ||
|
||
# Build the Go binary | ||
COPY . . | ||
|
||
# Build | ||
RUN CGO_ENABLED=0 go build -a -o /neonvmd neonvm/daemon/main.go | ||
|
||
FROM scratch | ||
COPY --from=builder /neonvmd /neonvmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"time" | ||
|
||
"go.uber.org/zap" | ||
) | ||
|
||
func main() { | ||
addr := flag.String("addr", "", `address to bind for HTTP requests`) | ||
flag.Parse() | ||
|
||
if *addr == "" { | ||
fmt.Println("neonvm-daemon missing -addr flag") | ||
os.Exit(1) | ||
} | ||
|
||
logConfig := zap.NewProductionConfig() | ||
logConfig.Sampling = nil // Disable sampling, which the production config enables by default. | ||
logConfig.Level.SetLevel(zap.InfoLevel) // Only "info" level and above (i.e. not debug logs) | ||
logger := zap.Must(logConfig.Build()).Named("neonvm-daemon") | ||
defer logger.Sync() //nolint:errcheck // what are we gonna do, log something about it? | ||
|
||
logger.Info("Starting neonvm-daemon", zap.String("addr", *addr)) | ||
|
||
srv := cpuServer{} | ||
srv.run(logger, *addr) | ||
} | ||
|
||
type cpuServer struct{} | ||
|
||
func (s *cpuServer) run(logger *zap.Logger, addr string) { | ||
logger = logger.Named("cpu-srv") | ||
|
||
mux := http.NewServeMux() | ||
mux.HandleFunc("/cpu", func(w http.ResponseWriter, r *http.Request) { | ||
if r.Method == http.MethodGet { | ||
logger.Error("unimplemented!") | ||
w.WriteHeader(http.StatusInternalServerError) | ||
} else if r.Method == http.MethodPut { | ||
logger.Error("unimplemented!") | ||
w.WriteHeader(http.StatusInternalServerError) | ||
} else { | ||
// unknown method | ||
w.WriteHeader(http.StatusNotFound) | ||
} | ||
}) | ||
|
||
timeout := 5 * time.Second | ||
server := http.Server{ | ||
Addr: addr, | ||
Handler: mux, | ||
ReadTimeout: timeout, | ||
ReadHeaderTimeout: timeout, | ||
WriteTimeout: timeout, | ||
} | ||
|
||
err := server.ListenAndServe() | ||
if err != nil { | ||
logger.Fatal("CPU server exited with error", zap.Error(err)) | ||
} | ||
logger.Info("CPU server exited without error") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters