Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,20 @@ dynbinary: ## build dynamically linked binary

.PHONY: plugins
plugins: ## build example CLI plugins
./scripts/build/plugins
scripts/build/plugins

.PHONY: vendor
vendor: ## update vendor with go modules
rm -rf vendor
./scripts/vendor update
scripts/with-go-mod.sh scripts/vendor update

.PHONY: validate-vendor
validate-vendor: ## validate vendor
./scripts/vendor validate
scripts/with-go-mod.sh scripts/vendor validate

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

.PHONY: authors
authors: ## generate AUTHORS file from git history
Expand Down Expand Up @@ -115,15 +115,15 @@ shell-completion: ## generate shell-completion scripts

.PHONY: manpages
manpages: ## generate man pages from go source and markdown
scripts/docs/generate-man.sh
scripts/with-go-mod.sh scripts/docs/generate-man.sh

.PHONY: mddocs
mddocs: ## generate markdown files from go source
scripts/docs/generate-md.sh
scripts/with-go-mod.sh scripts/docs/generate-md.sh

.PHONY: yamldocs
yamldocs: ## generate documentation YAML files consumed by docs repo
scripts/docs/generate-yaml.sh
scripts/with-go-mod.sh scripts/docs/generate-yaml.sh

.PHONY: help
help: ## print this help
Expand Down
6 changes: 3 additions & 3 deletions dockerfiles/Dockerfile.vendor
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RUN --mount=target=/context \
--mount=target=/go/pkg/mod,type=cache <<EOT
set -e
rsync -a /context/. .
./scripts/vendor update
./scripts/with-go-mod.sh ./scripts/vendor update
mkdir /out
cp -r vendor.mod vendor.sum vendor /out
EOT
Expand All @@ -32,12 +32,12 @@ rsync -a /context/. .
git add -A
rm -rf vendor
cp -rf /out/* .
./scripts/vendor validate
./scripts/with-go-mod.sh ./scripts/vendor validate
EOT

FROM psampaz/go-mod-outdated:${MODOUTDATED_VERSION} AS go-mod-outdated
FROM base AS outdated
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
./scripts/with-go-mod.sh ./scripts/vendor outdated
13 changes: 0 additions & 13 deletions docs/generate/go.mod

This file was deleted.

7 changes: 0 additions & 7 deletions docs/generate/tools.go

This file was deleted.

15 changes: 0 additions & 15 deletions man/go.mod

This file was deleted.

7 changes: 1 addition & 6 deletions man/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@

package main

import (
_ "github.com/cpuguy83/go-md2man/v2"
_ "github.com/spf13/cobra"
_ "github.com/spf13/cobra/doc"
_ "github.com/spf13/pflag"
)
import _ "github.com/cpuguy83/go-md2man/v2"
Copy link
Member Author

Choose a reason for hiding this comment

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

Turned out I needed the tools.go after all (don't ask!) 🙈 😂

41 changes: 14 additions & 27 deletions scripts/docs/generate-man.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,22 @@

set -eu

: "${MD2MAN_VERSION=v2.0.6}"
: "${GO_MD2MAN:=go-md2man}"

export GO111MODULE=auto

function clean {
rm -rf "$buildir"
}

buildir=$(mktemp -d -t docker-cli-docsgen.XXXXXXXXXX)
trap clean EXIT
if ! command -v "$GO_MD2MAN" > /dev/null; then
(
set -x
go build -mod=vendor -modfile=vendor.mod -o ./build/tools/go-md2man ./vendor/github.com/cpuguy83/go-md2man/v2
Copy link
Member Author

Choose a reason for hiding this comment

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

Now that we have this check; perhaps I should even consider using a regular go install for this. Packagers that want to build offline can pre-install go-md2man if needed I guess?

I'll leave that as a follow up I think

)
GO_MD2MAN=$(realpath ./build/tools/go-md2man)
fi

mkdir -p man/man1
(
set -x
cp -r . "$buildir/"
cd "$buildir"
# init dummy go.mod
./scripts/vendor init
# install go-md2man and copy man/tools.go in root folder
# to be able to fetch the required dependencies
go mod edit -modfile=vendor.mod -require=github.com/cpuguy83/go-md2man/v2@${MD2MAN_VERSION}
cp man/tools.go .
# update vendor
./scripts/vendor update
# build gen-manpages
go build -mod=vendor -modfile=vendor.mod -tags manpages -o /tmp/gen-manpages ./man/generate.go
# build go-md2man
go build -mod=vendor -modfile=vendor.mod -o /tmp/go-md2man ./vendor/github.com/cpuguy83/go-md2man/v2
go run -mod=vendor -modfile=vendor.mod -tags manpages ./man/generate.go --root "." --target "./man/man1"
)

mkdir -p man/man1
(set -x ; /tmp/gen-manpages --root "." --target "$(pwd)/man/man1")

(
cd man
for FILE in *.md; do
Expand All @@ -45,6 +29,9 @@ mkdir -p man/man1
continue
fi
mkdir -p "./man${num}"
(set -x ; /tmp/go-md2man -in "$FILE" -out "./man${num}/${name}")
(
set -x ;
"$GO_MD2MAN" -in "$FILE" -out "./man${num}/${name}"
)
done
)
29 changes: 1 addition & 28 deletions scripts/docs/generate-md.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,9 @@

set -eu

: "${CLI_DOCS_TOOL_VERSION=v0.9.0}"

export GO111MODULE=auto

function clean {
rm -rf "$buildir"
}

buildir=$(mktemp -d -t docker-cli-docsgen.XXXXXXXXXX)
trap clean EXIT

(
set -x
cp -r . "$buildir/"
cd "$buildir"
# init dummy go.mod
./scripts/vendor init
# install cli-docs-tool and copy docs/tools.go in root folder
# to be able to fetch the required dependencies
go mod edit -modfile=vendor.mod -require=github.com/docker/cli-docs-tool@${CLI_DOCS_TOOL_VERSION}
cp docs/generate/tools.go .
# update vendor
./scripts/vendor update
# build docsgen
go build -mod=vendor -modfile=vendor.mod -tags docsgen -o /tmp/docsgen ./docs/generate/generate.go
)

(
set -x
/tmp/docsgen --formats md --source "$(pwd)/docs/reference/commandline" --target "$(pwd)/docs/reference/commandline"
go run -mod=vendor -modfile=vendor.mod -tags docsgen ./docs/generate/generate.go --formats md --source "./docs/reference/commandline" --target "./docs/reference/commandline"
)

# remove generated help.md file
Expand Down
29 changes: 1 addition & 28 deletions scripts/docs/generate-yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,6 @@

set -eu

: "${CLI_DOCS_TOOL_VERSION=v0.9.0}"

export GO111MODULE=auto

function clean {
rm -rf "$buildir"
}

buildir=$(mktemp -d -t docker-cli-docsgen.XXXXXXXXXX)
trap clean EXIT

(
set -x
cp -r . "$buildir/"
cd "$buildir"
# init dummy go.mod
./scripts/vendor init
# install cli-docs-tool and copy docs/tools.go in root folder
# to be able to fetch the required dependencies
go mod edit -modfile=vendor.mod -require=github.com/docker/cli-docs-tool@${CLI_DOCS_TOOL_VERSION}
cp docs/generate/tools.go .
# update vendor
./scripts/vendor update
# build docsgen
go build -mod=vendor -modfile=vendor.mod -tags docsgen -o /tmp/docsgen ./docs/generate/generate.go
)

mkdir -p docs/yaml
set -x
/tmp/docsgen --formats yaml --source "$(pwd)/docs/reference/commandline" --target "$(pwd)/docs/yaml"
go run -mod=vendor -modfile=vendor.mod -tags docsgen ./docs/generate/generate.go --formats yaml --source "./docs/reference/commandline" --target "./docs/yaml"
15 changes: 0 additions & 15 deletions scripts/vendor
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ if [ -z "$TYP" ]; then
usage
fi

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

go 1.23.0
EOL
}

update() {
(set -x ; go mod tidy -modfile=vendor.mod; go mod vendor -modfile=vendor.mod)
}
Expand All @@ -44,20 +35,14 @@ outdated() {
}

case $TYP in
"init")
init
;;
"update")
init
update
;;
"validate")
init
update
validate
;;
"outdated")
init
outdated
;;
*)
Expand Down
33 changes: 33 additions & 0 deletions scripts/with-go-mod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
#
# This script is used to coerce certain commands which rely on the presence of
# a go.mod into working with our repository. It works by creating a fake
# go.mod, running a specified command (passed via arguments), and removing it
# when the command is finished. This script should be dropped when this
# repository is a proper Go module with a permanent go.mod.

set -e

SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOTDIR="$(cd "${SCRIPTDIR}/.." && pwd)"

if test -e "${ROOTDIR}/go.mod"; then
{
scriptname=$(basename "$0")
cat >&2 <<- EOF
$scriptname: WARN: go.mod exists in the repository root!
$scriptname: WARN: Using your go.mod instead of our generated version -- this may misbehave!
EOF
} >&2
else
set -x

tee "${ROOTDIR}/go.mod" >&2 <<- EOF
module github.com/docker/cli
go 1.23.0
EOF
Comment on lines +25 to +29
Copy link
Member

Choose a reason for hiding this comment

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

Should/could this instead be something like grep -E '^(module|go) ' vendor.mod | tee go.mod so there's less to dual-maintain?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh! Didn't do this one yet, might do so in a follow-up

trap 'rm -f "${ROOTDIR}/go.mod"' EXIT
fi

GO111MODULE=on GOTOOLCHAIN=local "$@"
2 changes: 2 additions & 0 deletions vendor.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ go 1.23.0
require (
dario.cat/mergo v1.0.1
github.com/containerd/platforms v1.0.0-rc.1
github.com/cpuguy83/go-md2man/v2 v2.0.6
github.com/creack/pty v1.1.24
github.com/distribution/reference v0.6.0
github.com/docker/cli-docs-tool v0.9.0
Expand Down Expand Up @@ -88,6 +89,7 @@ require (
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
go.etcd.io/etcd/raft/v3 v3.5.16 // indirect
Expand Down
3 changes: 3 additions & 0 deletions vendor.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3
github.com/containerd/platforms v1.0.0-rc.1 h1:83KIq4yy1erSRgOVHNk1HYdPvzdJ5CnsWaRoJX4C41E=
github.com/containerd/platforms v1.0.0-rc.1/go.mod h1:J71L7B+aiM5SdIEqmd9wp6THLVRzJGXfNuWCZCllLA4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.6 h1:XJtiaUW6dEEqVuZiMTn1ldk455QWwEIsMIJlo5vtkx0=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s=
github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE=
Expand Down Expand Up @@ -236,6 +238,7 @@ github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sirupsen/logrus v1.0.6/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
Expand Down
2 changes: 2 additions & 0 deletions vendor/github.com/cpuguy83/go-md2man/v2/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions vendor/github.com/cpuguy83/go-md2man/v2/.golangci.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions vendor/github.com/cpuguy83/go-md2man/v2/Dockerfile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading