Skip to content

Commit

Permalink
vendor with go mod
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Dec 14, 2021
1 parent 6fbf816 commit fc57f10
Show file tree
Hide file tree
Showing 537 changed files with 64,718 additions and 13,904 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
/man/man*/
/docs/yaml/gen/
profile.out
/vndr.log

# top-level go.mod is not meant to be checked in
/go.mod
3 changes: 2 additions & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ on:
pull_request:

jobs:
lint:
validate:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target:
- lint
- shellcheck
- validate-vendor
steps:
-
name: Checkout
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ Thumbs.db
/man/man8/
/docs/yaml/gen/
profile.out
/vndr.log

# top-level go.mod is not meant to be checked in
/go.mod
16 changes: 11 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,18 @@ dynbinary: ## build dynamically linked binary
plugins: ## build example CLI plugins
./scripts/build/plugins

vendor: vendor.conf ## check that vendor matches vendor.conf
.PHONY: vendor
vendor: ## update vendor with go modules
rm -rf vendor
bash -c 'vndr |& grep -v -i clone | tee ./vndr.log'
scripts/validate/check-git-diff vendor
scripts/validate/check-all-packages-vendored
./scripts/vendor update

.PHONY: validate-vendor
validate-vendor: ## validate vendor
./scripts/vendor validate

.PHONY: mod-outdated
mod-outdated: ## check outdated dependencies
./scripts/vendor outdated

.PHONY: authors
authors: ## generate AUTHORS file from git history
Expand All @@ -73,6 +80,5 @@ help: ## print this help

.PHONY: ci-validate
ci-validate:
time make -B vendor
time make manpages
time make yamldocs
26 changes: 26 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,32 @@ target "shellcheck" {
output = ["type=cacheonly"]
}

target "validate-vendor" {
dockerfile = "./dockerfiles/Dockerfile.vendor"
target = "validate"
output = ["type=cacheonly"]
}

target "update-vendor" {
dockerfile = "./dockerfiles/Dockerfile.vendor"
target = "update"
output = ["."]
}

// Used to invalidate cache for mod-outdated run stage
// See also https://github.com/moby/buildkit/issues/1213
variable "TIMESTAMP" {
default = ""
}
target "mod-outdated" {
dockerfile = "./dockerfiles/Dockerfile.vendor"
target = "outdated"
args = {
TIMESTAMP = TIMESTAMP
}
output = ["type=cacheonly"]
}

target "test" {
target = "test"
output = ["type=cacheonly"]
Expand Down
17 changes: 15 additions & 2 deletions docker.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ifeq ($(DOCKER_CLI_GO_BUILD_CACHE),y)
DOCKER_CLI_MOUNTS += -v "$(CACHE_VOLUME_NAME):/root/.cache/go-build"
endif
VERSION = $(shell cat VERSION)
TIMESTAMP = $(shell date '+%s')
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)

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

.PHONY: vendor
vendor: build_docker_image vendor.conf ## download dependencies (vendor/) listed in vendor.conf
$(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make vendor
vendor: ## update vendor with go modules
$(eval $@_TMP_OUT := $(shell mktemp -d -t dockercli-output.XXXXXXXXXX))
docker buildx bake --set "*.output=$($@_TMP_OUT)" update-vendor
rm -rf ./vendor
cp -R "$($@_TMP_OUT)"/out/* .
rm -rf $($@_TMP_OUT)/*

.PHONY: validate-vendor
validate-vendor: ## validate vendor
docker buildx bake validate-vendor

.PHONY: mod-outdated
mod-outdated: ## check outdated dependencies
TIMESTAMP=$(TIMESTAMP) docker buildx bake mod-outdated

.PHONY: authors
authors: ## generate AUTHORS file from git history
Expand Down
8 changes: 0 additions & 8 deletions dockerfiles/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=tmpfs,target=/go/src/ \
GO111MODULE=on go install gotest.tools/gotestsum@${GOTESTSUM_VERSION}

FROM golang AS vndr
ARG VNDR_VERSION=v0.1.2
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=tmpfs,target=/go/src/ \
GO111MODULE=on go install github.com/LK4D4/vndr@${VNDR_VERSION}

FROM golang AS goversioninfo
ARG GOVERSIONINFO_VERSION=v1.3.0
RUN --mount=type=cache,target=/root/.cache/go-build \
Expand All @@ -39,7 +32,6 @@ CMD bash
ENV DISABLE_WARN_OUTSIDE_CONTAINER=1
ENV PATH=$PATH:/go/src/github.com/docker/cli/build

COPY --from=vndr /go/bin/* /go/bin/
COPY --from=gotestsum /go/bin/* /go/bin/
COPY --from=goversioninfo /go/bin/* /go/bin/

Expand Down
46 changes: 46 additions & 0 deletions dockerfiles/Dockerfile.vendor
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# syntax=docker/dockerfile:1.3-labs

ARG GO_VERSION=1.16.11
ARG MODVENDOR_VERSION=v0.5.0
ARG MODOUTDATED_VERSION=v0.8.0

FROM golang:${GO_VERSION}-alpine AS base
RUN apk add --no-cache bash git rsync
WORKDIR /src
ARG MODVENDOR_VERSION
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
GO111MODULE=on go install "github.com/goware/modvendor@${MODVENDOR_VERSION}"

FROM base AS vendored
RUN --mount=target=/context \
--mount=target=.,type=tmpfs \
--mount=target=/go/pkg/mod,type=cache <<EOT
set -e
rsync -a /context/. .
./scripts/vendor update
mkdir /out
cp -r vendor.mod vendor.sum vendor /out
EOT

FROM scratch AS update
COPY --from=vendored /out /out

FROM vendored AS validate
RUN --mount=target=/context \
--mount=target=.,type=tmpfs <<EOT
set -e
rsync -a /context/. .
git add -A
rm -rf vendor
cp -rf /out/* .
./scripts/vendor validate
EOT

FROM psampaz/go-mod-outdated:${MODOUTDATED_VERSION} AS go-mod-outdated
FROM base AS outdated
ARG TIMESTAMP
RUN --mount=target=.,rw \
--mount=target=/go/pkg/mod,type=cache \
--mount=from=go-mod-outdated,source=/home/go-mod-outdated,target=/usr/bin/go-mod-outdated \
./scripts/vendor outdated
2 changes: 1 addition & 1 deletion man/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
package main

// Not used, but required for generating other man pages.
// Import it here so that the package is included by vndr.
// Import it here so that the package is included by go modules.
import _ "github.com/cpuguy83/go-md2man/v2"
12 changes: 0 additions & 12 deletions scripts/validate/check-all-packages-vendored

This file was deleted.

17 changes: 0 additions & 17 deletions scripts/validate/check-git-diff

This file was deleted.

65 changes: 65 additions & 0 deletions scripts/vendor
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash

set -eu

TYP=$1

usage() {
echo "usage: ./scripts/vendor <update|outdated>"
exit 1
}

if [ -z "$TYP" ]; then
usage
fi

# create dummy go.mod, see comment in vendor.mod
cat > go.mod <<EOL
module github.com/docker/cli
go 1.16
EOL

update() {
(set -x ; go mod vendor -modfile=vendor.mod)
if [ ! -x "$(command -v modvendor)" ]; then
echo "modvendor not found. Install with 'go install github.com/goware/modvendor@v0.5.0'"
exit 1
fi
(set -x ; modvendor -copy="**/*.c **/*.h **/*.proto" -v)
}

validate() {
(set -x ; go mod tidy -modfile=vendor.mod)
diff=$(git status --porcelain -- vendor.mod vendor.sum vendor)
if [ -n "$diff" ]; then
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "make -f docker.Makefile vendor"'
echo "$diff"
exit 1
fi
}

outdated() {
if [ ! -x "$(command -v go-mod-outdated)" ]; then
echo "go-mod-outdated not found. Install with 'go install github.com/psampaz/go-mod-outdated@v0.8.0'"
exit 1
fi
(set -x ; go list -mod=vendor -mod=readonly -modfile=vendor.mod -u -m -json all | go-mod-outdated -update -direct)
}

case $TYP in
"update")
update
;;
"validate")
update
validate
;;
"outdated")
outdated
;;
*)
echo >&2 "Unknown type $TYP"
exit 1
;;
esac
95 changes: 0 additions & 95 deletions vendor.conf

This file was deleted.

Loading

0 comments on commit fc57f10

Please sign in to comment.