Skip to content

Commit 396ff9b

Browse files
atulmguptaCopilot
andauthored
Fix/automation worker build (#60)
* fix(ci): work around Go 1.25 inliner crash in automation-worker build The automation-worker build was failing on CI runners with: internal compiler error: panic: runtime error: invalid memory address at /usr/local/go/src/sync/atomic/type.go:47:6 while compiling internal/api. This is a Go 1.25 inliner bug that triggers on the large internal/api package (~219 files) under runner memory pressure. Fix applies three defense-in-depth flags to the build: - GOMEMLIMIT=2GiB caps Go GC growth so peak RSS fits runner budgets - -p 2 limits parallel compile jobs (default = NumCPU, often too many) - -gcflags=all=-l disables inlining, sidestepping the crash Locally verified: docker build --no-cache produces a 56.4MB image in 71s (vs 36s with inlining); the resulting binary boots and exits cleanly from the built-in healthcheck path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Expose Leaflet globally; update i18n placeholders Add leafletGlobal.ts to mirror Leaflet onto window.L so classic plugins (leaflet-draw, markercluster, etc.) can find L when evaluated. Import this module in GeofenceDrawer and MarkerCluster before the plugin imports to ensure plugins don't throw `L is not defined`. Also update en.json placeholder formatting for pagination strings (noData, showing, pageOf) from JS template literals to i18n-style {{}} placeholders. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent acbb9e1 commit 396ff9b

5 files changed

Lines changed: 43 additions & 4 deletions

File tree

Dockerfile.automation

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@ RUN go mod tidy
1414

1515
ARG VERSION=dev
1616

17-
RUN CGO_ENABLED=0 GOOS=linux go build \
17+
# Memory-conservative compile to avoid Go 1.25 inliner crashes on
18+
# constrained CI runners. The `internal/api` package is large (~219 files)
19+
# and the inliner can panic at sync/atomic/type.go under memory pressure.
20+
# - GOMEMLIMIT bounds Go's GC growth so peak RSS stays within runner limits
21+
# - `-p 2` caps parallel compile jobs (default = NumCPU, often too high)
22+
# - `-gcflags=all=-l` disables inlining (sidesteps the inliner crash with
23+
# a small binary-size / perf cost that's negligible for an I/O-bound
24+
# worker)
25+
RUN GOMEMLIMIT=2GiB CGO_ENABLED=0 GOOS=linux go build \
26+
-p 2 \
27+
-gcflags=all=-l \
1828
-ldflags="-s -w -X main.Version=${VERSION}" \
1929
-o /bin/automation-worker ./cmd/automation-worker
2030

web/src/components/maps/GeofenceDrawer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useEffect, useRef } from 'react';
22
import { useMap } from 'react-leaflet';
33
import L from 'leaflet';
4+
import './leafletGlobal';
45
import 'leaflet-draw';
56
import 'leaflet-draw/dist/leaflet.draw.css';
67

web/src/components/maps/MarkerCluster.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useEffect, useMemo, useRef } from 'react';
22
import { useMap } from 'react-leaflet';
33
import L from 'leaflet';
4+
import './leafletGlobal';
45
import 'leaflet.markercluster';
56
import 'leaflet.markercluster/dist/MarkerCluster.css';
67
import 'leaflet.markercluster/dist/MarkerCluster.Default.css';
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Mirror Leaflet onto `window.L` so classical plugins can find it.
3+
*
4+
* Plugins like `leaflet-draw`, `leaflet.markercluster`, and `leaflet.heat`
5+
* are written as classical browser scripts that look up `window.L` at
6+
* evaluation time instead of importing leaflet themselves. Vite's ESM
7+
* bundle imports leaflet locally and never attaches it to `window`, so the
8+
* plugins crash with `ReferenceError: L is not defined` the moment any
9+
* route that touches the maps barrel is loaded.
10+
*
11+
* Importing this module via a SIDE-EFFECT import BEFORE the plugin import
12+
* is the canonical fix:
13+
*
14+
* import './leafletGlobal'; // hoisted, but evaluated first
15+
* import 'leaflet.markercluster'; // can now resolve window.L
16+
*
17+
* ES module imports are evaluated in source order, so listing this above
18+
* the plugin guarantees `window.L` exists by the time the plugin runs.
19+
*/
20+
import L from 'leaflet';
21+
22+
const w = globalThis as unknown as { L?: typeof L };
23+
if (typeof window !== 'undefined' && !w.L) {
24+
w.L = L;
25+
}
26+
27+
export {};

web/src/i18n/en.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,9 +1878,9 @@
18781878
"responseBody": "Response Body",
18791879
"previous": "Previous",
18801880
"next": "Next",
1881-
"noData": "No ${label.toLowerCase()}",
1882-
"showing": "Showing ${page * limit + 1}–${Math.min((page + 1) * limit, total)} of ${fmtInt(total)}",
1883-
"pageOf": "Page ${page + 1} of ${totalPages}"
1881+
"noData": "No {{label}}",
1882+
"showing": "Showing {{from}}–{{to}} of {{total}}",
1883+
"pageOf": "Page {{page}} of {{total}}"
18841884
},
18851885
"backup": {
18861886
"title": "Backup & Restore",

0 commit comments

Comments
 (0)