Skip to content

Commit 3190456

Browse files
authored
Merge pull request docker-archive#1014 from chris-crone/containerize-go-mod-tidy
Containerize go mod tidy
2 parents 32efa58 + 78190f8 commit 3190456

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Dockerfile

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ COPY --from=make-cli /out/* .
9595
FROM scratch AS cross
9696
COPY --from=make-cross /out/* .
9797

98-
FROM base as test
98+
FROM base AS test
9999
ENV CGO_ENABLED=0
100100
ARG BUILD_TAGS
101101
ARG GIT_TAG
@@ -106,11 +106,20 @@ RUN --mount=target=. \
106106
GIT_TAG=${GIT_TAG} \
107107
make -f builder.Makefile test
108108

109-
FROM base as check-license-headers
109+
FROM base AS check-license-headers
110110
RUN go get -u github.com/kunalkushwaha/ltag
111111
RUN --mount=target=. \
112112
make -f builder.Makefile check-license-headers
113113

114-
FROM base as check-go-mod
114+
FROM base AS make-go-mod-tidy
115+
COPY . .
116+
RUN --mount=type=cache,target=/go/pkg/mod \
117+
go mod tidy
118+
119+
FROM scratch AS go-mod-tidy
120+
COPY --from=make-go-mod-tidy /compose-cli/go.mod .
121+
COPY --from=make-go-mod-tidy /compose-cli/go.sum .
122+
123+
FROM base AS check-go-mod
115124
COPY . .
116125
RUN make -f builder.Makefile check-go-mod

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ moby-cli-link: ## Create com.docker.cli symlink if does not already exist
9292
validate-headers: ## Check license header for all files
9393
@docker build . --target check-license-headers
9494

95+
go-mod-tidy: ## Run go mod tidy in a container and output resulting go.mod and go.sum
96+
@docker build . --target go-mod-tidy --output .
97+
9598
validate-go-mod: ## Validate go.mod and go.sum are up-to-date
9699
@docker build . --target check-go-mod
97100

@@ -128,4 +131,4 @@ help: ## Show help
128131

129132
FORCE:
130133

131-
.PHONY: all validate protos cli e2e-local cross test cache-clear lint check-dependencies serve classic-link help clean-aci-e2e
134+
.PHONY: all validate protos cli e2e-local cross test cache-clear lint check-dependencies serve classic-link help clean-aci-e2e go-mod-tidy

0 commit comments

Comments
 (0)