Switch demo service to a Go binary on scratch

The python:3.12-slim base pushed a 30 MB layer that timed out on the way
to Harbor (Cloudflare 524). A static Go binary keeps the image near 5 MB
with the same endpoints, port and APP_MESSAGE variable.
This commit is contained in:
2026-10-23 08:50:10 +00:00
parent 2c21665d0e
commit fdb7ee666d
5 changed files with 66 additions and 47 deletions

52
main.go Normal file
View File

@@ -0,0 +1,52 @@
// Minimal HTTP service for testing AISP's Gitea -> build -> release -> deploy flow.
package main
import (
"encoding/json"
"log"
"net/http"
"os"
"time"
)
const version = "v1"
func main() {
port := getenv("PORT", "8080")
hostname, _ := os.Hostname()
startedAt := time.Now().UTC().Format(time.RFC3339)
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
reply(w, http.StatusOK, map[string]string{"status": "ok"})
})
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
reply(w, http.StatusNotFound, map[string]string{"error": "not found"})
return
}
log.Printf("%s %s %s", r.RemoteAddr, r.Method, r.URL.Path)
reply(w, http.StatusOK, map[string]string{
"service": "aisp-ci-demo",
"version": version,
"message": getenv("APP_MESSAGE", "Hello from AISP"),
"hostname": hostname,
"startedAt": startedAt,
})
})
log.Printf("aisp-ci-demo %s listening on :%s", version, port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}
func reply(w http.ResponseWriter, status int, body any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
_ = json.NewEncoder(w).Encode(body)
}
func getenv(key, fallback string) string {
if value := os.Getenv(key); value != "" {
return value
}
return fallback
}