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.
This commit is contained in:
parent
fcb104f9f5
commit
75d1905998
1 changed files with 8 additions and 0 deletions
|
|
@ -1,6 +1,14 @@
|
||||||
FROM golang:1.24-alpine AS builder
|
FROM golang:1.24-alpine AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy go mod files first and download dependencies
|
||||||
|
# This creates a separate layer that only invalidates when dependencies change
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
# Copy the rest of the source code
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
ARG GO_BUILD_TAGS
|
ARG GO_BUILD_TAGS
|
||||||
RUN go build ${GO_BUILD_TAGS:+-tags="$GO_BUILD_TAGS"} -o /build/registry ./cmd/registry
|
RUN go build ${GO_BUILD_TAGS:+-tags="$GO_BUILD_TAGS"} -o /build/registry ./cmd/registry
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue