diff --git a/Dockerfile b/Dockerfile index 20b08c3..2767b5a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,8 @@ WORKDIR /build COPY go.mod go.sum ./ RUN go mod download COPY . . -RUN CGO_ENABLED=0 go build -o shared-sqs ./app/cmd/ +ARG VERSION=dev +RUN CGO_ENABLED=0 go build -ldflags "-X shared-sqs/app/models.Version=${VERSION}" -o shared-sqs ./app/cmd/ FROM alpine:3.19 RUN apk --no-cache add ca-certificates diff --git a/Makefile b/Makefile index 08a318c..4e0ce3a 100644 --- a/Makefile +++ b/Makefile @@ -3,19 +3,21 @@ # Registry: Docker Hub (naeel/shared-sqs) IMAGE_REPO=naeel/shared-sqs -VERSION=v0.1.0 +VERSION=v0.1.26 +LDFLAGS=-X shared-sqs/app/models.Version=$(VERSION) BINARY=shared-sqs .PHONY: build docker-build docker-push test run clean build: - CGO_ENABLED=0 go build -o $(BINARY) app/cmd/goaws.go + CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BINARY) ./app/cmd/ docker-build: - docker build -t $(IMAGE_REPO):$(VERSION) . + docker build --build-arg VERSION=$(VERSION) -t $(IMAGE_REPO):$(VERSION) -t $(IMAGE_REPO):latest . docker-push: docker push $(IMAGE_REPO):$(VERSION) + docker push $(IMAGE_REPO):latest test: go test ./... diff --git a/app/admin/admin.go b/app/admin/admin.go index ca9e5fb..b655ee2 100644 --- a/app/admin/admin.go +++ b/app/admin/admin.go @@ -727,6 +727,7 @@ func jsonErr(w http.ResponseWriter, code int, msg string) { // adminHealthDetail — ответ GET /admin/health type adminHealthDetail struct { Status string `json:"status"` + Version string `json:"version"` TenantCount int `json:"tenant_count"` QueueCount int `json:"queue_count"` MessageCount int `json:"message_count"` @@ -750,6 +751,7 @@ func (h *Handler) detailedHealth(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(adminHealthDetail{ Status: "ok", + Version: models.Version, TenantCount: 1, QueueCount: queueCount, MessageCount: msgCount, @@ -768,6 +770,7 @@ func (h *Handler) detailedHealth(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(adminHealthDetail{ Status: "ok", + Version: models.Version, TenantCount: len(tenants), QueueCount: queueCount, MessageCount: msgCount, diff --git a/app/models/constants.go b/app/models/constants.go index 1ed7cbf..3e055d5 100644 --- a/app/models/constants.go +++ b/app/models/constants.go @@ -4,6 +4,10 @@ import ( "time" ) +// Version — версия сервиса. Переопределяется при сборке: +// -ldflags "-X shared-sqs/app/models.Version=<версия>" +var Version = "dev" + var BaseXmlns = "http://queue.amazonaws.com/doc/2012-11-05/" var BaseResponseMetadata = ResponseMetadata{RequestId: "00000000-0000-0000-0000-000000000000"} diff --git a/app/router/router.go b/app/router/router.go index 5e4092f..ed90466 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -19,6 +19,7 @@ import ( sqs "shared-sqs/app/gosqs" "shared-sqs/app/interfaces" "shared-sqs/app/metrics" + "shared-sqs/app/models" "shared-sqs/app/tenant" "shared-sqs/app/ui" @@ -125,8 +126,9 @@ var routingTableV1 = map[string]func(r *http.Request) (int, interfaces.AbstractR } func health(w http.ResponseWriter, req *http.Request) { + w.Header().Set("Content-Type", "application/json") w.WriteHeader(200) - fmt.Fprint(w, "OK") + fmt.Fprintf(w, `{"status":"ok","version":%q}`, models.Version) } func actionHandler(w http.ResponseWriter, req *http.Request) { diff --git a/app/ui/index.html b/app/ui/index.html index 6f3a1a3..b1d9002 100644 --- a/app/ui/index.html +++ b/app/ui/index.html @@ -346,7 +346,8 @@ td.msg-expand { padding: 0 !important; border-bottom: 1px solid var(--border); }