Skip to content

Commit 8876566

Browse files
committed
Add cache buster for css asset
1 parent c084c62 commit 8876566

6 files changed

Lines changed: 16 additions & 5 deletions

File tree

.github/workflows/docker.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,7 @@ jobs:
4848
push: true
4949
tags: ${{ steps.meta.outputs.tags }}
5050
labels: ${{ steps.meta.outputs.labels }}
51+
build-args: |
52+
VERSION=${{ github.ref_name }}
5153
cache-from: type=gha
5254
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ RUN go mod download
99

1010
COPY . .
1111

12-
RUN CGO_ENABLED=1 GOOS=linux go build -a -ldflags '-linkmode external -extldflags "-static"' -o server .
12+
ARG VERSION=dev
13+
RUN CGO_ENABLED=1 GOOS=linux go build -a -ldflags '-linkmode external -extldflags "-static" -X main.Version='${VERSION} -o server .
1314

1415
FROM alpine:latest
1516

internal/handlers/handlers.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ type Handler struct {
2222
db *database.DB
2323
scraper Scraper
2424
templates *template.Template
25+
version string
2526
}
2627

27-
func New(db *database.DB, scraper Scraper) (*Handler, error) {
28+
func New(db *database.DB, scraper Scraper, version string) (*Handler, error) {
2829
tmpl, err := template.ParseGlob("web/templates/*.html")
2930
if err != nil {
3031
return nil, err
@@ -34,6 +35,7 @@ func New(db *database.DB, scraper Scraper) (*Handler, error) {
3435
db: db,
3536
scraper: scraper,
3637
templates: tmpl,
38+
version: version,
3739
}, nil
3840
}
3941

@@ -112,12 +114,14 @@ func (h *Handler) Calendar(w http.ResponseWriter, r *http.Request) {
112114
PrevMonth int
113115
NextYear int
114116
NextMonth int
117+
Version string
115118
}{
116119
OrganizationID: orgID,
117120
OrganizationTitle: getOrganizationTitle(org),
118121
Calendar: cal,
119122
Year: year,
120123
Month: int(month),
124+
Version: h.version,
121125
}
122126

123127
prevMonth := month - 1
@@ -222,11 +226,13 @@ func (h *Handler) List(w http.ResponseWriter, r *http.Request) {
222226
OrganizationTitle string
223227
Events []*database.Event
224228
Color string
229+
Version string
225230
}{
226231
OrganizationID: orgID,
227232
OrganizationTitle: getOrganizationTitle(org),
228233
Events: events,
229234
Color: color,
235+
Version: h.version,
230236
}
231237

232238
if err := h.templates.ExecuteTemplate(w, "list.html", data); err != nil {

main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
"github.com/romanzipp/linke-calendar/internal/scraper"
1616
)
1717

18+
var Version = "dev"
19+
1820
func main() {
1921
configPath := os.Getenv("CONFIG_PATH")
2022
if configPath == "" {
@@ -46,7 +48,7 @@ func main() {
4648
log.Fatalf("Failed to start scraper scheduler: %v", err)
4749
}
4850

49-
h, err := handlers.New(db, scheduler.GetScraper())
51+
h, err := handlers.New(db, scheduler.GetScraper(), Version)
5052
if err != nil {
5153
log.Fatalf("Failed to create handlers: %v", err)
5254
}

web/templates/calendar.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<meta name="robots" content="noindex">
77
<title>{{.OrganizationTitle}} - Kalender</title>
8-
<link rel="stylesheet" href="/static/css/style.css?v=0.1.11">
8+
<link rel="stylesheet" href="/static/css/style.css{{if ne .Version "dev"}}?v={{.Version}}{{end}}">
99
<script src="/static/js/htmx.min.js"></script>
1010
</head>
1111
<body class="bg-transparent">

web/templates/list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<meta name="robots" content="noindex">
77
<title>{{.OrganizationTitle}} - Termine</title>
8-
<link rel="stylesheet" href="/static/css/style.css?v=0.1.11">
8+
<link rel="stylesheet" href="/static/css/style.css{{if ne .Version "dev"}}?v={{.Version}}{{end}}">
99
</head>
1010
<body class="bg-transparent">
1111
<div class="w-full mx-auto{{if eq .Color "white"}} text-white{{end}}">

0 commit comments

Comments
 (0)