diff --git a/.ko.yaml b/.ko.yaml index 1a9cb8d..33cc1f4 100644 --- a/.ko.yaml +++ b/.ko.yaml @@ -1 +1,9 @@ defaultBaseImage: cgr.dev/chainguard/static:latest +builds: + - id: wicket + dir: . + main: . + flags: + - -trimpath + ldflags: + - -X main.version={{.Env.VERSION}} diff --git a/.tangled/workflows/ci.yml b/.tangled/workflows/ci.yml index b25fdf6..2fc247a 100644 --- a/.tangled/workflows/ci.yml +++ b/.tangled/workflows/ci.yml @@ -28,5 +28,6 @@ steps: command: | go install github.com/google/ko@latest export PATH="$(go env GOPATH)/bin:$PATH" + export VERSION="$(date -u +%Y%m%d%H%M%S)-$(git rev-parse --short HEAD)" echo "${ATCR_APP_PASSWORD}" | docker login atcr.io -u guid.foo --password-stdin - ko build --bare --tags "latest,$(date -u +%Y%m%d%H%M%S)-$(git rev-parse --short HEAD)" . + ko build --bare --tags "latest,${VERSION}" . diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 880a404..0000000 --- a/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM golang:1.25 AS build -WORKDIR /src -COPY go.mod go.sum* ./ -RUN go mod download -COPY . . -RUN CGO_ENABLED=0 go build -o /wicket . - -FROM scratch -COPY --from=build /wicket /wicket -ENTRYPOINT ["/wicket"] diff --git a/server.go b/server.go index 0906d5d..c6a3c1f 100644 --- a/server.go +++ b/server.go @@ -15,6 +15,8 @@ import ( "github.com/google/uuid" ) +var version = "dev" + type Server struct { broker *Broker config *atomic.Pointer[Configuration] @@ -28,6 +30,12 @@ func NewServer(broker *Broker, config *atomic.Pointer[Configuration]) http.Handl func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { setCORSHeaders(w) + if r.Method == "GET" && r.URL.Path == "/" { + w.Header().Set("Content-Type", "text/plain") + fmt.Fprintf(w, "wicket %s\n", version) + return + } + if r.Method == "GET" && r.URL.Path == "/_health" { w.WriteHeader(http.StatusNoContent) return diff --git a/server_test.go b/server_test.go index dc6d134..0db4a4d 100644 --- a/server_test.go +++ b/server_test.go @@ -27,6 +27,30 @@ func newTestServer(cfg *Configuration) (*httptest.Server, *Broker, context.Cance return httptest.NewServer(handler), broker, cancel } +func TestServer_rootBanner(t *testing.T) { + ts, _, cancel := newTestServer(nil) + defer cancel() + defer ts.Close() + + resp, err := http.Get(ts.URL + "/") + if err != nil { + t.Fatalf("GET / failed: %v", err) + } + defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { + t.Errorf("expected 200, got %d", resp.StatusCode) + } + if ct := resp.Header.Get("Content-Type"); ct != "text/plain" { + t.Errorf("expected text/plain, got %s", ct) + } + buf := make([]byte, 1024) + n, _ := resp.Body.Read(buf) + body := string(buf[:n]) + if !strings.Contains(body, "wicket") { + t.Errorf("expected body to contain 'wicket', got %q", body) + } +} + func TestServer_healthEndpoint(t *testing.T) { ts, _, cancel := newTestServer(nil) defer cancel()