Skip to content

Conversation

@thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Feb 29, 2024

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
Member Author

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

@thaJeztah thaJeztah force-pushed the carry_docs_no_internet branch from f6f0e4b to b46bfe4 Compare April 12, 2024 11:29
@codecov-commenter
Copy link

codecov-commenter commented Apr 12, 2024

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 on lines 1 to 10
//go:build tools

package main

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.

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 thaJeztah force-pushed the carry_docs_no_internet branch from 1ff8868 to 1c298b1 Compare March 19, 2025 14:45
vendor.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
Member

Choose a reason for hiding this comment

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

We could make use of the new tool directive starting Go 1.24:

Copy link
Member Author

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
Member Author

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 owner March 19, 2025 18:25
@thaJeztah thaJeztah requested a review from tianon-sso March 19, 2025 18:25
Comment on lines +25 to +29
tee "${ROOTDIR}/go.mod" >&2 <<- EOF
module github.com/docker/cli
go 1.23.0
EOF
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

scripts/vendor Outdated
}
update() (
set -x
"${SCRIPTDIR}"/with-go-mod.sh go mod tidy -modfile vendor.mod
Copy link
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
Member Author

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 thaJeztah force-pushed the carry_docs_no_internet branch from 1c298b1 to 8eb269f Compare March 20, 2025 23:20
_ "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!) 🙈 😂

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

Copy link
Member

@tianon-sso tianon-sso left a comment

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 ❤️)

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 thaJeztah force-pushed the carry_docs_no_internet branch from 8eb269f to 535bb6c Compare March 20, 2025 23:37
@thaJeztah thaJeztah added this to the 28.0.3 milestone Mar 21, 2025
@thaJeztah
Copy link
Member Author

@Benehiko @vvoland PTAL

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

@thaJeztah thaJeztah requested a review from vvoland March 21, 2025 13:17
@thaJeztah thaJeztah requested a review from Benehiko March 21, 2025 13:17
@thaJeztah thaJeztah merged commit 61cd986 into docker:master Mar 21, 2025
102 checks passed
@thaJeztah thaJeztah deleted the carry_docs_no_internet branch March 21, 2025 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants