Skip to content

docs: include required tools in source tree - #4903

Merged
thaJeztah merged 2 commits into
docker:masterfrom
thaJeztah:carry_docs_no_internet
Mar 21, 2025
Merged

docs: include required tools in source tree#4903
thaJeztah merged 2 commits into
docker:masterfrom
thaJeztah:carry_docs_no_internet

Conversation

@thaJeztah

@thaJeztahthaJeztah commented Feb 29, 2024

Copy link
Copy Markdown
Member

In order to be able to build the documentation without internet access (as is required by some distribution build systems), all of the source code needed for the build needs to be available in the source tarball.

This used to be possible with the docker-cli sources but was accidentally broken with some CI changes that switched to downloading the tools (by modifying go.mod as part of the docs build script).

This pattern also maked documentation builds less reproducible since the tool version used was not based on the source code version.

Fixes: commit 7dc35c0 ("validate manpages target")
Fixes: commit a650f4d ("switch to cli-docs-tool for yaml docs generation")

- What I did

- How I did it

- How to verify it

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah

Copy link
Copy Markdown
MemberAuthor

(Also wondering if we can rewrite things to be a go:generate)

@thaJeztah
thaJeztahforce-pushed the carry_docs_no_internet branch from f6f0e4b to b46bfe4CompareApril 12, 2024 11:29
@codecov-commenter

codecov-commenter commented Apr 12, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.43%. Comparing base (b199ece) to head (535bb6c).
Report is 12 commits behind head on master.

Additional details and impacted files
@@ Coverage Diff @@## master #4903 +/- ##
=======================================
Coverage 59.43% 59.43% =======================================
Files 358 358 Lines 29765 29765 =======================================
Hits 17690 17690 Misses 11111 11111 Partials 964 964 
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment threadman/tools.go
Comment on lines -1 to -10
//go:build tools

package main

import (
_ "github.com/cpuguy83/go-md2man/v2"
)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I removed the tools.go here, as we already vendor the dependency as indirect dependency of docker/cli-docs-tool. I could keep if it that's a concern (but things would show up pretty fast if we'd miss the dependency at some point)

@thaJeztah
thaJeztahforce-pushed the carry_docs_no_internet branch from 1ff8868 to 1c298b1CompareMarch 19, 2025 14:45
Comment threadvendor.mod Outdated
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Ah, yes, but we're not on go1.24 yet 😅

At least currently it works, so I guess it's fine with how we have it right now?

@thaJeztah

Copy link
Copy Markdown
MemberAuthor

Let me move this one out of draft; I have a follow-up to rewrite some code to use more of the man-page code from cli-docs-tool, but didn't want to stuff that in with this PR.

@thaJeztah
thaJeztah marked this pull request as ready for review March 19, 2025 18:25
@thaJeztah
thaJeztah requested a review from a team as a code ownerMarch 19, 2025 18:25
Comment threadscripts/docs/generate-man.sh Outdated
Comment on lines +25 to +29
tee "${ROOTDIR}/go.mod" >&2 <<- EOF
module github.com/docker/cli

go 1.23.0
EOF

Copy link
Copy Markdown
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
Copy Markdown
MemberAuthor

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

Comment threadscripts/docs/generate-man.sh Outdated
Comment threadscripts/docs/generate-md.sh Outdated
Comment threadscripts/docs/generate-yaml.sh Outdated
Comment threadscripts/vendor Outdated
}
update() (
set -x
"${SCRIPTDIR}"/with-go-mod.sh go mod tidy -modfile vendor.mod

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Again, I think it's better to document that the invoker of these should run with-go-mod.sh, especially since that'll cause less churn if there's more than one usage of go.mod within a given script.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

❤️ your comments made me realise that I don't have to include it in each script; I moved it to the Makefile instead; it's not perfect, but at least keeps the scripts themselves clean. Possibly we could move it into a Makefile var / macro as well so that it can be overridden (to run the scripts without the with-go-mod.sh script before it).

In order to be able to build the documentation without internet access
(as is required by some distribution build systems), all of the source
code needed for the build needs to be available in the source tarball.
This used to be possible with the docker-cli sources but was
accidentally broken with some CI changes that switched to downloading
the tools (by modifying go.mod as part of the docs build script).
This pattern also maked documentation builds less reproducible since the
tool version used was not based on the source code version.
Fixes: 7dc35c0 ("validate manpages target")
Fixes: a650f4d ("switch to cli-docs-tool for yaml docs generation")
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah
thaJeztahforce-pushed the carry_docs_no_internet branch from 1c298b1 to 8eb269fCompareMarch 20, 2025 23:20
Comment threadman/tools.go
_ "github.com/spf13/cobra/doc"
_ "github.com/spf13/pflag"
)
import _ "github.com/cpuguy83/go-md2man/v2"

Copy link
Copy Markdown
MemberAuthor

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!) 🙈 😂

if [ ! -x "$(command -v $GO_MD2MAN)" ]; then
(
set -x
go build -mod=vendor -modfile=vendor.mod -o ./build/tools/go-md2man ./vendor/github.com/cpuguy83/go-md2man/v2

Copy link
Copy Markdown
MemberAuthor

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

@tianon-ssotianon-sso left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice, much better (just a couple really minor nits but overall LGTM ❤️)

Comment threadscripts/docs/generate-man.sh Outdated
Comment threadscripts/docs/generate-man.sh Outdated
Use the same script as is used in moby/moby, which more gracefully
handles an existing `go.mod` (which can be symlinked) into account.
- keep the scripts called generic, and update the Makefile to invoke
them with the "with-go-mod.sh" script.
- use "go run" instead of building temporary binaries
- check if go-md2man exists before building a binary
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah
thaJeztahforce-pushed the carry_docs_no_internet branch from 8eb269f to 535bb6cCompareMarch 20, 2025 23:37
@thaJeztahthaJeztah added this to the 28.0.3 milestone Mar 21, 2025
@thaJeztah

Copy link
Copy Markdown
MemberAuthor

@Benehiko@vvoland PTAL

I'll have a look at some follow-ups as well;

@thaJeztah
thaJeztah requested a review from vvolandMarch 21, 2025 13:17
@thaJeztah
thaJeztah requested a review from BenehikoMarch 21, 2025 13:17
@thaJeztah
thaJeztah merged commit 61cd986 into docker:masterMar 21, 2025
@thaJeztah
thaJeztah deleted the carry_docs_no_internet branch March 21, 2025 17:49
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@thaJeztah@codecov-commenter@crazy-max@vvoland@tianon-sso@cyphar