Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vendor with go mod #3387

Merged
merged 3 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Dockerfile* linguist-language=Dockerfile
vendor.mod linguist-language=Go-Module
vendor.sum linguist-language=Go-Checksums
Comment on lines +2 to +3
Copy link
Member Author

@crazy-max crazy-max Dec 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not yet in use, correct? (more of a "local dependabot check")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is only intended for local check

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sample output:

$ DISABLE_WARN_OUTSIDE_CONTAINER=1 make mod-outdated
./scripts/vendor outdated
+ go-mod-outdated -update -direct
+ go list -mod=vendor -mod=readonly -modfile=vendor.mod -u -m -json all
+--------------------------------------+-----------------------------------------------------+------------------------------------+--------+------------------+
|                MODULE                |                       VERSION                       |            NEW VERSION             | DIRECT | VALID TIMESTAMPS |
+--------------------------------------+-----------------------------------------------------+------------------------------------+--------+------------------+
| github.com/containerd/console        | v1.0.2                                              | v1.0.3                             | true   | true             |
| github.com/containerd/containerd     | v1.5.5                                              | v1.5.8                             | true   | true             |
| github.com/creack/pty                | v1.1.11                                             | v1.1.17                            | true   | true             |
| github.com/docker/docker             | v20.10.3-0.20210811141259-343665850e3a+incompatible | v20.10.12+incompatible             | true   | true             |
| github.com/google/go-cmp             | v0.2.0                                              | v0.5.6                             | true   | true             |
| github.com/mitchellh/mapstructure    | v1.3.2                                              | v1.4.3                             | true   | true             |
| github.com/moby/buildkit             | v0.8.2-0.20210615162540-9f254e18360a                | v0.9.3                             | true   | true             |
| github.com/opencontainers/image-spec | v1.0.1                                              | v1.0.2                             | true   | true             |
| github.com/spf13/cobra               | v1.1.3                                              | v1.3.0                             | true   | true             |
| github.com/tonistiigi/fsutil         | v0.0.0-20210609172227-d72af97c0eaf                  | v0.0.0-20211208191308-f95797418e48 | true   | true             |
| github.com/tonistiigi/go-rosetta     | v0.0.0-20200727161949-f79598599c5d                  | v0.0.0-20201102221648-9ba854641817 | true   | true             |
| golang.org/x/sys                     | v0.0.0-20210823070655-63515b42dcdf                  | v0.0.0-20211216021012-1d35b9e2eb4e | true   | true             |
| golang.org/x/term                    | v0.0.0-20201117132131-f5c789dd3221                  | v0.0.0-20210927222741-03fcf44c2211 | true   | true             |
| golang.org/x/text                    | v0.3.3                                              | v0.3.7                             | true   | true             |
| k8s.io/api                           | v0.16.9                                             | v0.23.0                            | true   | true             |
| k8s.io/apimachinery                  | v0.16.9                                             | v0.23.0                            | true   | true             |
| k8s.io/client-go                     | v0.16.9                                             | v1.5.2                             | true   | true             |
+--------------------------------------+-----------------------------------------------------+------------------------------------+--------+------------------+

./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
22 changes: 22 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ 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 = ["."]
}

target "mod-outdated" {
dockerfile = "./dockerfiles/Dockerfile.vendor"
target = "outdated"
args = {
// used to invalidate cache (more info https://github.com/moby/buildkit/issues/1213)
UUID = uuidv4()
}
output = ["type=cacheonly"]
}

target "test" {
target = "test"
output = ["type=cacheonly"]
Expand Down
16 changes: 14 additions & 2 deletions docker.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,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
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
41 changes: 41 additions & 0 deletions dockerfiles/Dockerfile.vendor
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# syntax=docker/dockerfile:1.3-labs

ARG GO_VERSION=1.16.11
ARG MODOUTDATED_VERSION=v0.8.0

FROM golang:${GO_VERSION}-alpine AS base
RUN apk add --no-cache bash git rsync
WORKDIR /src

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 UUID
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.

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

set -eu

TYP=$1

usage() {
echo "usage: ./scripts/vendor <update|validate|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)
}

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
crazy-max marked this conversation as resolved.
Show resolved Hide resolved
}

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