-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
61 lines (46 loc) Β· 1.98 KB
/
Copy pathDockerfile
File metadata and controls
61 lines (46 loc) Β· 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Build stage β Go binary
FROM golang:1.25-alpine AS go-builder
RUN apk add --no-cache git ca-certificates tzdata
WORKDIR /src
COPY go.mod ./
COPY go.sum* ./
RUN go mod download 2>/dev/null || true
COPY . .
RUN go mod tidy
ARG VERSION=dev
ARG COMMIT=unknown
ARG BUILD_TIME=unknown
# Memory-conservative compile to avoid Go 1.25 inliner crashes on
# constrained CI runners. The `internal/api` package is large (~219 files)
# and the inliner can panic at sync/atomic/type.go under memory pressure.
# - GOMEMLIMIT bounds Go's GC growth so peak RSS stays within runner limits
# - `-p 2` caps parallel compile jobs (default = NumCPU, often too high)
# - `-gcflags=all=-l` disables inlining (sidesteps the inliner crash with
# a small binary-size / perf cost that's negligible for an I/O-bound
# worker)
RUN GOMEMLIMIT=2GiB CGO_ENABLED=0 GOOS=linux go build \
-p 2 \
-gcflags=all=-l \
-ldflags="-s -w -X main.Version=${VERSION} -X main.Commit=${COMMIT} -X main.buildTime=${BUILD_TIME}" \
-o /bin/teslasync ./cmd/teslasync
# Build stage β frontend assets
FROM node:20-alpine AS web-builder
WORKDIR /app
COPY web/package.json web/package-lock.json* ./
RUN if [ -f package-lock.json ]; then npm ci --legacy-peer-deps; else npm install --legacy-peer-deps; fi
COPY web/ .
# buildChangelog.mjs (prebuild) reads <repo-root>/CHANGELOG.md; place it where
# the script's REPO_ROOT (resolve(__dirname, '..', '..')) β '/' resolves it.
COPY CHANGELOG.md /CHANGELOG.md
RUN npm run build
# Runtime stage β distroless (no shell, no package manager, minimal attack surface)
FROM gcr.io/distroless/static:nonroot
COPY --from=go-builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=go-builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=go-builder /bin/teslasync /usr/local/bin/teslasync
COPY migrations /migrations
COPY docs/public/openapi.yaml /docs/public/openapi.yaml
COPY --from=web-builder /app/dist /web/dist
USER nonroot:nonroot
EXPOSE 8080
ENTRYPOINT ["teslasync"]