Skip to content

Commit 9c54383

Browse files
committed
vendor with go mod
Signed-off-by: CrazyMax <[email protected]>
1 parent 6fbf816 commit 9c54383

492 files changed

Lines changed: 59611 additions & 16541 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.dockerignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
/man/man*/
55
/docs/yaml/gen/
66
profile.out
7-
/vndr.log
7+
8+
# top-level go.mod is not meant to be checked in yet
9+
/go.mod

.github/workflows/validate.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ on:
1111
pull_request:
1212

1313
jobs:
14-
lint:
14+
validate:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
fail-fast: false
1818
matrix:
1919
target:
2020
- lint
2121
- shellcheck
22+
- validate-vendor
2223
steps:
2324
-
2425
name: Checkout

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ Thumbs.db
1515
/man/man8/
1616
/docs/yaml/gen/
1717
profile.out
18-
/vndr.log
18+
19+
# top-level go.mod is not meant to be checked in yet
20+
/go.mod

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ dynbinary: ## build dynamically linked binary
4949
plugins: ## build example CLI plugins
5050
./scripts/build/plugins
5151

52-
vendor: vendor.conf ## check that vendor matches vendor.conf
52+
.PHONY: vendor
53+
vendor: ## update vendor with go modules
5354
rm -rf vendor
54-
bash -c 'vndr |& grep -v -i clone | tee ./vndr.log'
55-
scripts/validate/check-git-diff vendor
56-
scripts/validate/check-all-packages-vendored
55+
@echo "module github.com/docker/cli\n\ngo 1.16\n" > go.mod
56+
go mod tidy -modfile=vendor.mod
57+
go mod vendor -modfile=vendor.mod
5758

5859
.PHONY: authors
5960
authors: ## generate AUTHORS file from git history
@@ -73,6 +74,5 @@ help: ## print this help
7374

7475
.PHONY: ci-validate
7576
ci-validate:
76-
time make -B vendor
7777
time make manpages
7878
time make yamldocs

docker-bake.hcl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,32 @@ target "shellcheck" {
7878
output = ["type=cacheonly"]
7979
}
8080

81+
target "validate-vendor" {
82+
dockerfile = "./dockerfiles/Dockerfile.vendor"
83+
target = "validate"
84+
output = ["type=cacheonly"]
85+
}
86+
87+
target "update-vendor" {
88+
dockerfile = "./dockerfiles/Dockerfile.vendor"
89+
target = "update"
90+
output = ["."]
91+
}
92+
93+
// Used to invalidate cache for mod-outdated run stage
94+
// See also https://github.com/moby/buildkit/issues/1213
95+
variable "TIMESTAMP" {
96+
default = ""
97+
}
98+
target "mod-outdated" {
99+
dockerfile = "./dockerfiles/Dockerfile.vendor"
100+
target = "outdated"
101+
args = {
102+
TIMESTAMP = TIMESTAMP
103+
}
104+
output = ["type=cacheonly"]
105+
}
106+
81107
target "test" {
82108
target = "test"
83109
output = ["type=cacheonly"]

docker.Makefile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ifeq ($(DOCKER_CLI_GO_BUILD_CACHE),y)
2020
DOCKER_CLI_MOUNTS += -v "$(CACHE_VOLUME_NAME):/root/.cache/go-build"
2121
endif
2222
VERSION = $(shell cat VERSION)
23+
TIMESTAMP = $(shell date '+%s')
2324
ENVVARS = -e VERSION=$(VERSION) -e GITCOMMIT -e PLATFORM -e TESTFLAGS -e TESTDIRS -e GOOS -e GOARCH -e GOARM -e TEST_ENGINE_VERSION=$(E2E_ENGINE_VERSION)
2425

2526
# Some Dockerfiles use features that are only supported with BuildKit enabled
@@ -80,8 +81,20 @@ fmt: ## run gofmt
8081
$(DOCKER_RUN) $(DEV_DOCKER_IMAGE_NAME) make fmt
8182

8283
.PHONY: vendor
83-
vendor: build_docker_image vendor.conf ## download dependencies (vendor/) listed in vendor.conf
84-
$(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make vendor
84+
vendor: ## update vendor with go modules
85+
$(eval $@_TMP_OUT := $(shell mktemp -d -t dockercli-output.XXXXXXXXXX))
86+
docker buildx bake --set "*.output=$($@_TMP_OUT)" update-vendor
87+
rm -rf ./vendor
88+
cp -R "$($@_TMP_OUT)"/out/* .
89+
rm -rf $($@_TMP_OUT)/*
90+
91+
.PHONY: validate-vendor
92+
validate-vendor: ## validate vendor
93+
docker buildx bake validate-vendor
94+
95+
.PHONY: mod-outdated
96+
mod-outdated: ## check outdated dependencies
97+
TIMESTAMP=$(TIMESTAMP) docker buildx bake mod-outdated
8598

8699
.PHONY: authors
87100
authors: ## generate AUTHORS file from git history

dockerfiles/Dockerfile.dev

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
1212
--mount=type=tmpfs,target=/go/src/ \
1313
GO111MODULE=on go install gotest.tools/gotestsum@${GOTESTSUM_VERSION}
1414

15-
FROM golang AS vndr
16-
ARG VNDR_VERSION=v0.1.2
17-
RUN --mount=type=cache,target=/root/.cache/go-build \
18-
--mount=type=cache,target=/go/pkg/mod \
19-
--mount=type=tmpfs,target=/go/src/ \
20-
GO111MODULE=on go install github.com/LK4D4/vndr@${VNDR_VERSION}
21-
2215
FROM golang AS goversioninfo
2316
ARG GOVERSIONINFO_VERSION=v1.3.0
2417
RUN --mount=type=cache,target=/root/.cache/go-build \
@@ -39,7 +32,6 @@ CMD bash
3932
ENV DISABLE_WARN_OUTSIDE_CONTAINER=1
4033
ENV PATH=$PATH:/go/src/github.com/docker/cli/build
4134

42-
COPY --from=vndr /go/bin/* /go/bin/
4335
COPY --from=gotestsum /go/bin/* /go/bin/
4436
COPY --from=goversioninfo /go/bin/* /go/bin/
4537

dockerfiles/Dockerfile.vendor

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# syntax=docker/dockerfile:1.3-labs
2+
3+
ARG GO_VERSION=1.16.11
4+
5+
FROM golang:${GO_VERSION}-alpine AS base
6+
RUN apk add --no-cache git rsync
7+
WORKDIR /src
8+
9+
FROM base AS vendored
10+
RUN --mount=target=/context \
11+
--mount=target=.,type=tmpfs \
12+
--mount=target=/go/pkg/mod,type=cache <<EOT
13+
set -e
14+
rsync -a /context/. .
15+
echo "module github.com/docker/cli\n\ngo 1.16\n" > go.mod
16+
go mod tidy -modfile=vendor.mod
17+
go mod vendor -modfile=vendor.mod
18+
mkdir /out
19+
cp -r vendor.mod vendor.sum vendor /out
20+
EOT
21+
22+
FROM scratch AS update
23+
COPY --from=vendored /out /out
24+
25+
FROM vendored AS validate
26+
RUN --mount=target=/context \
27+
--mount=target=.,type=tmpfs <<EOT
28+
set -e
29+
rsync -a /context/. .
30+
git add -A
31+
rm -rf vendor
32+
cp -rf /out/* .
33+
diff=$(git status --porcelain -- vendor.mod vendor.sum vendor)
34+
if [ -n "$diff" ]; then
35+
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "make -f docker.Makefile vendor"'
36+
echo $diff
37+
exit 1
38+
fi
39+
EOT
40+
41+
FROM psampaz/go-mod-outdated:v0.8.0 AS go-mod-outdated
42+
FROM base AS outdated
43+
ARG TIMESTAMP
44+
RUN --mount=target=.,rw \
45+
--mount=target=/go/pkg/mod,type=cache \
46+
--mount=from=go-mod-outdated,source=/home/go-mod-outdated,target=/usr/bin/go-mod-outdated <<EOT
47+
echo "module github.com/docker/cli\n\ngo 1.16\n" > go.mod
48+
go list -mod=readonly -modfile=vendor.mod -u -m -json all | go-mod-outdated -update -direct
49+
EOT

man/import.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
package main
44

55
// Not used, but required for generating other man pages.
6-
// Import it here so that the package is included by vndr.
6+
// Import it here so that the package is included by go modules.
77
import _ "github.com/cpuguy83/go-md2man/v2"

scripts/validate/check-all-packages-vendored

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)