Skip to content

Commit 75d1905

Browse files
authored
build: Optimize Dockerfile by splitting out dependency installation and go build (#286)
Create a separate step in the Docker image to install the dependencies. This makes local dev a bunch faster, because Docker doesn't redownload all the dependencies each time you make a small file changes.
1 parent fcb104f commit 75d1905

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
FROM golang:1.24-alpine AS builder
22
WORKDIR /app
3+
4+
# Copy go mod files first and download dependencies
5+
# This creates a separate layer that only invalidates when dependencies change
6+
COPY go.mod go.sum ./
7+
RUN go mod download
8+
9+
# Copy the rest of the source code
310
COPY . .
11+
412
ARG GO_BUILD_TAGS
513
RUN go build ${GO_BUILD_TAGS:+-tags="$GO_BUILD_TAGS"} -o /build/registry ./cmd/registry
614

0 commit comments

Comments
 (0)