From 0e399ba2bf2fdb9057a282e6a4964c8624440149 Mon Sep 17 00:00:00 2001 From: Simon de Vlieger Date: Tue, 28 Apr 2026 08:03:20 +0200 Subject: [PATCH 1/2] docs: generate manpages Create manpages by using Cobra's built-in ability to do so. Add a hidden command that we call in our RPM specfile to generate the pages and install them in the appropriate location. Also adds a new Makefile option to generate the manpages. Signed-off-by: Simon de Vlieger --- .gitignore | 1 + Makefile | 5 +++++ cmd/image-builder/main.go | 1 + cmd/image-builder/manpages.go | 22 ++++++++++++++++++++++ go.mod | 2 ++ go.sum | 3 +++ image-builder.spec | 7 +++++++ 7 files changed, 41 insertions(+) create mode 100644 cmd/image-builder/manpages.go diff --git a/.gitignore b/.gitignore index 298a5214..45377f75 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ __pycache__ *.tar.bz2 recording-*.cast.json /image-builder +man diff --git a/Makefile b/Makefile index 53e00044..b3303842 100644 --- a/Makefile +++ b/Makefile @@ -109,9 +109,14 @@ build: $(BUILDDIR)/bin/ ## build the binary from source GOARCH="$$arch" go build -ldflags="-s -w" -o ./bin/bib-canary-"$$arch" ./cmd/cross-arch/; \ done +.PHONY: man +man: build $(BUILDDIR)/man/man1/ ## Generate man pages + $(BUILDDIR)/bin/image-builder doc $(BUILDDIR)/man/man1/ + .PHONY: clean clean: ## Remove all built binaries rm -rf $(BUILDDIR)/bin/ + rm -rf $(BUILDDIR)/man/ rm -rf $(CURDIR)/rpmbuild rm -rf $(CURDIR)/release_artifacts diff --git a/cmd/image-builder/main.go b/cmd/image-builder/main.go index 1657fc04..d0c868b5 100644 --- a/cmd/image-builder/main.go +++ b/cmd/image-builder/main.go @@ -702,6 +702,7 @@ operating systems like Fedora, CentOS and RHEL with easy customizations support. describeImgCmd.Flags().Bool("in-vm", false, `run container in a virtual machine`) rootCmd.AddCommand(describeImgCmd) + addDocCmd(rootCmd) verbose, err := rootCmd.PersistentFlags().GetBool("verbose") if err != nil { diff --git a/cmd/image-builder/manpages.go b/cmd/image-builder/manpages.go new file mode 100644 index 00000000..b6882f8c --- /dev/null +++ b/cmd/image-builder/manpages.go @@ -0,0 +1,22 @@ +package main + +import ( + "github.com/spf13/cobra" + "github.com/spf13/cobra/doc" +) + +func addDocCmd(rootCmd *cobra.Command) { + docCmd := &cobra.Command{ + Use: "doc ", + Short: "Generate man pages for this command", + Hidden: true, + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + header := &doc.GenManHeader{ + Section: "1", + } + return doc.GenManTree(rootCmd, header, args[0]) + }, + } + rootCmd.AddCommand(docCmd) +} diff --git a/go.mod b/go.mod index ab1d4570..5d0c1dc2 100644 --- a/go.mod +++ b/go.mod @@ -63,6 +63,7 @@ require ( github.com/containers/ocicrypt v1.2.1 // indirect github.com/containers/storage v1.59.1 // indirect github.com/coreos/go-semver v0.3.1 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect github.com/cyberphone/json-canonicalization v0.0.0-20241213102144-19d51d7fe467 // indirect github.com/cyphar/filepath-securejoin v0.4.1 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect @@ -125,6 +126,7 @@ require ( github.com/proglottis/gpgme v0.1.4 // indirect github.com/prometheus/client_golang v1.23.0 // indirect github.com/rivo/uniseg v0.4.7 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/secure-systems-lab/go-securesystemslib v0.9.0 // indirect github.com/sigstore/fulcio v1.6.6 // indirect github.com/sigstore/protobuf-specs v0.4.1 // indirect diff --git a/go.sum b/go.sum index a8911914..ea9aa830 100644 --- a/go.sum +++ b/go.sum @@ -96,6 +96,8 @@ github.com/containers/storage v1.59.1/go.mod h1:KoAYHnAjP3/cTsRS+mmWZGkufSY2GACi github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4= github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec= github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= +github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo= +github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/cyberphone/json-canonicalization v0.0.0-20241213102144-19d51d7fe467 h1:uX1JmpONuD549D73r6cgnxyUu18Zb7yHAy5AYU0Pm4Q= github.com/cyberphone/json-canonicalization v0.0.0-20241213102144-19d51d7fe467/go.mod h1:uzvlm1mxhHkdfqitSA92i7Se+S9ksOn3a3qmv/kyOCw= github.com/cyphar/filepath-securejoin v0.4.1 h1:JyxxyPEaktOD+GAnqIqTf9A8tHyAG22rowi7HkoSU1s= @@ -312,6 +314,7 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= +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/santhosh-tekuri/jsonschema/v6 v6.0.2 h1:KRzFb2m7YtdldCEkzs6KqmJw4nqEVZGK7IN2kJkjTuQ= github.com/santhosh-tekuri/jsonschema/v6 v6.0.2/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU= diff --git a/image-builder.spec b/image-builder.spec index e12b05bb..1b3b700e 100644 --- a/image-builder.spec +++ b/image-builder.spec @@ -92,12 +92,18 @@ GOTAGS="exclude_graphdriver_btrfs" export LDFLAGS="${LDFLAGS} -X 'main.version=%{version}'" %gobuild ${GOTAGS:+-tags=$GOTAGS} -o %{gobuilddir}/bin/image-builder %{goipath}/cmd/image-builder +# Generate man pages +mkdir -p man/man1 +%{gobuilddir}/bin/image-builder doc man/man1/ + %install install -m 0755 -vd %{buildroot}%{_bindir} install -m 0755 -vp %{gobuilddir}/bin/image-builder %{buildroot}%{_bindir}/ # tmpfiles.d snippet install -m 0755 -vd %{buildroot}%{_tmpfilesdir} install -m 0644 -vp data/tmpfiles.d/image-builder.conf %{buildroot}%{_tmpfilesdir}/image-builder.conf +install -m 0755 -vd %{buildroot}%{_mandir}/man1 +install -m 0644 -vp man/man1/image-builder*.1 %{buildroot}%{_mandir}/man1/ %check export GOFLAGS="-buildmode=pie" %if 0%{?rhel} @@ -115,6 +121,7 @@ cd $PWD/_build/src/%{goipath} %doc README.md %{_bindir}/image-builder %{_tmpfilesdir}/image-builder.conf +%{_mandir}/man1/image-builder*.1* %ghost %attr(0755, root, root) %dir /var/cache/image-builder %changelog From 1381236cb7828f9c9eb08dd29751583ba2047d96 Mon Sep 17 00:00:00 2001 From: Simon de Vlieger Date: Wed, 29 Apr 2026 06:51:10 +0200 Subject: [PATCH 2/2] spec: drop `%{gobuilddir}` This macro doesn't exist (yet) on ELs; instead use `_bin` as the prefix. This accidentally works because install quotes the paths so they work even when not expanded. We use `_bin` in our other spec files for Go projects. Signed-off-by: Simon de Vlieger --- image-builder.spec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/image-builder.spec b/image-builder.spec index 1b3b700e..755610cf 100644 --- a/image-builder.spec +++ b/image-builder.spec @@ -90,15 +90,15 @@ GOTAGS="exclude_graphdriver_btrfs" %endif export LDFLAGS="${LDFLAGS} -X 'main.version=%{version}'" -%gobuild ${GOTAGS:+-tags=$GOTAGS} -o %{gobuilddir}/bin/image-builder %{goipath}/cmd/image-builder +%gobuild ${GOTAGS:+-tags=$GOTAGS} -o _bin/image-builder %{goipath}/cmd/image-builder # Generate man pages mkdir -p man/man1 -%{gobuilddir}/bin/image-builder doc man/man1/ +_bin/image-builder doc man/man1/ %install install -m 0755 -vd %{buildroot}%{_bindir} -install -m 0755 -vp %{gobuilddir}/bin/image-builder %{buildroot}%{_bindir}/ +install -m 0755 -vp _bin/image-builder %{buildroot}%{_bindir}/ # tmpfiles.d snippet install -m 0755 -vd %{buildroot}%{_tmpfilesdir} install -m 0644 -vp data/tmpfiles.d/image-builder.conf %{buildroot}%{_tmpfilesdir}/image-builder.conf