Skip to content

Commit 890b4f1

Browse files
coreydaleyclaude
andcommitted
fix(docker): cache go mod download and npm install as separate layers
Previously COPY . was the first step, so every source change invalidated the layer and caused go build to re-download all modules on every CI run. Now go.mod/go.sum and package.json/package-lock.json are copied first so module downloads are cached independently of source changes. Also expose port 8026 (webhook capture server). Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 0391c3a commit 890b4f1

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

Dockerfile

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@ FROM golang:alpine AS builder
22

33
ARG VERSION=dev
44

5-
COPY . /app
6-
75
WORKDIR /app
86

9-
RUN apk upgrade && apk add git npm && \
10-
npm install && npm run package && \
11-
CGO_ENABLED=0 go build -ldflags "-s -w -X github.com/coreydaley/messagepit/config.Version=${VERSION}" -o /messagepit
7+
RUN apk add --no-cache git npm
8+
9+
# Cache Go module downloads separately from source — only re-runs when go.mod/go.sum change
10+
COPY go.mod go.sum ./
11+
RUN go mod download
12+
13+
# Cache npm installs separately — only re-runs when package files change
14+
COPY package.json package-lock.json ./
15+
RUN npm install
16+
17+
# Copy remaining source and build
18+
COPY . .
19+
RUN npm run package && \
20+
CGO_ENABLED=0 go build -ldflags "-s -w -X github.com/coreydaley/messagepit/config.Version=${VERSION}" -o /messagepit
1221

1322
FROM alpine:latest
1423

@@ -21,7 +30,7 @@ COPY --from=builder /messagepit /messagepit
2130

2231
RUN apk upgrade --no-cache && apk add --no-cache tzdata
2332

24-
EXPOSE 1025/tcp 1110/tcp 1775/tcp 8025/tcp
33+
EXPOSE 1025/tcp 1110/tcp 1775/tcp 8025/tcp 8026/tcp
2534

2635
HEALTHCHECK --interval=15s --start-period=10s --start-interval=1s CMD ["/messagepit", "readyz"]
2736

0 commit comments

Comments
 (0)