Fix deploy: force Docker rebuild, add version check and redeploy script

This commit is contained in:
shop
2026-06-25 17:10:54 +03:00
parent efc95d48c4
commit 306002bfa1
9 changed files with 82 additions and 7 deletions
+7 -2
View File
@@ -1,6 +1,7 @@
package handlers
import (
"fmt"
"html/template"
"log"
"net/http"
@@ -9,6 +10,7 @@ import (
"shop/internal/auth"
"shop/internal/models"
"shop/internal/repository"
"shop/internal/version"
)
type CustomerHandler struct {
@@ -26,6 +28,7 @@ type shopPage struct {
Title string
User *models.User
CartCount int
Version string
Products interface{}
Categories interface{}
Error string
@@ -73,13 +76,14 @@ func NewCustomerHandler(
func (h *CustomerHandler) render(w http.ResponseWriter, name string, data any) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
if err := h.templates.ExecuteTemplate(w, name, data); err != nil {
log.Printf("render %s: %v", name, err)
}
}
func (h *CustomerHandler) basePage(r *http.Request, w http.ResponseWriter, title string) shopPage {
p := shopPage{Title: title}
p := shopPage{Title: title, Version: version.Version}
if uid, ok := auth.UserIDFromSession(h.userSession, r); ok {
if u, err := h.users.GetByID(r.Context(), uid); err == nil {
p.User = &u
@@ -373,5 +377,6 @@ func (h *CustomerHandler) Account(w http.ResponseWriter, r *http.Request) {
func (h *CustomerHandler) Health(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"status":"ok"}`))
w.Header().Set("Cache-Control", "no-store")
fmt.Fprintf(w, `{"status":"ok","version":%q}`, version.Version)
}
+1 -1
View File
@@ -118,7 +118,7 @@
<div class="footer__brand">
<span class="logo__icon"></span>
<span class="logo__text">Shop</span>
<p class="footer__copy">© 2026 Shop. Все права защищены.</p>
<p class="footer__copy">© 2026 Shop · v{{.Version}}</p>
</div>
<div class="footer__links">
<a href="/account">Личный кабинет</a>
+4
View File
@@ -0,0 +1,4 @@
package version
// Version задаётся при сборке: -ldflags "-X shop/internal/version.Version=..."
var Version = "dev"