Skip to content

Commit

Permalink
Add BuildOrigin field to podman info
Browse files Browse the repository at this point in the history
BuiltOrigin is a field that can be set at build time by packagers. This helps us trace how and where the binary was built and installed from, allowing us to see if the issue is due to a specfic installation or a general podman bug. This field shows up in podman version and in podman info when populated. Note that podman info has a new field, Client, that only appears when running podman info using the remote client.

Automatically set the BuildOrigin field when building the macOS pkginstaller to pkginstaller.

Usage: make podman-remote BUILD_ORIGIN="mypackaging"

Signed-off-by: Ashley Cui <[email protected]>
  • Loading branch information
ashley-cui committed Jan 22, 2025
1 parent 1194557 commit 0abcdcf
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 31 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ GOFLAGS ?= -trimpath
LDFLAGS_PODMAN ?= \
$(if $(GIT_COMMIT),-X $(LIBPOD)/define.gitCommit=$(GIT_COMMIT),) \
$(if $(BUILD_INFO),-X $(LIBPOD)/define.buildInfo=$(BUILD_INFO),) \
$(if $(BUILD_ORIGIN),-X $(LIBPOD)/define.buildOrigin=$(BUILD_ORIGIN),) \
-X $(LIBPOD)/config._installPrefix=$(PREFIX) \
-X $(LIBPOD)/config._etcDir=$(ETCDIR) \
-X $(PROJECT)/v5/pkg/systemd/quadlet._binDir=$(BINDIR) \
Expand Down
14 changes: 8 additions & 6 deletions cmd/podman/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package main
import "github.com/containers/podman/v5/libpod/define"

type clientInfo struct {
OSArch string `json:"OS"`
Provider string `json:"provider"`
Version string `json:"version"`
OSArch string `json:"OS"`
Provider string `json:"provider"`
Version string `json:"version"`
BuildOrigin string `json:"buildOrigin,omitempty" yaml:",omitempty"`
}

func getClientInfo() (*clientInfo, error) {
Expand All @@ -18,8 +19,9 @@ func getClientInfo() (*clientInfo, error) {
return nil, err
}
return &clientInfo{
OSArch: vinfo.OsArch,
Provider: p,
Version: vinfo.Version,
OSArch: vinfo.OsArch,
Provider: p,
Version: vinfo.Version,
BuildOrigin: vinfo.BuildOrigin,
}, nil
}
2 changes: 2 additions & 0 deletions cmd/podman/system/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ API Version:\t{{.APIVersion}}
Go Version:\t{{.GoVersion}}
{{if .GitCommit -}}Git Commit:\t{{.GitCommit}}\n{{end -}}
Built:\t{{.BuiltTime}}
{{if .BuildOrigin -}}Build Origin:\t{{.BuildOrigin}}\n{{end -}}
OS/Arch:\t{{.OsArch}}
{{- end}}
Expand All @@ -108,6 +109,7 @@ API Version:\t{{.APIVersion}}
Go Version:\t{{.GoVersion}}
{{if .GitCommit -}}Git Commit:\t{{.GitCommit}}\n{{end -}}
Built:\t{{.BuiltTime}}
{{if .BuildOrigin -}}Build Origin:\t{{.BuildOrigin}}\n{{end -}}
OS/Arch:\t{{.OsArch}}
{{- end}}{{- end}}
`
3 changes: 2 additions & 1 deletion contrib/pkginstaller/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ PRODUCTSIGN_IDENTITY=${PRODUCTSIGN_IDENTITY:-mock}
NO_CODESIGN=${NO_CODESIGN:-0}
HELPER_BINARIES_DIR="/opt/podman/bin"
MACHINE_POLICY_JSON_DIR="/opt/podman/config"
BUILD_ORIGIN="pkginstaller"

tmpBin="contrib/pkginstaller/tmp-bin"

Expand Down Expand Up @@ -47,7 +48,7 @@ function build_podman() {
}

function build_podman_arch(){
make -B GOARCH="$1" podman-remote HELPER_BINARIES_DIR="${HELPER_BINARIES_DIR}"
make -B GOARCH="$1" podman-remote HELPER_BINARIES_DIR="${HELPER_BINARIES_DIR}" BUILD_ORIGIN="${BUILD_ORIGIN}"
make -B GOARCH="$1" podman-mac-helper
mkdir -p "${tmpBin}"
cp bin/darwin/podman "${tmpBin}/podman-$1"
Expand Down
37 changes: 21 additions & 16 deletions libpod/define/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@ var (
// BuildInfo is the time at which the binary was built
// It will be populated by the Makefile.
buildInfo string
// BuildOrigin is the packager of the binary.
// It will be populated at build-time.
buildOrigin string
)

// Version is an output struct for API
type Version struct {
APIVersion string
Version string
GoVersion string
GitCommit string
BuiltTime string
Built int64
OsArch string
Os string
APIVersion string
Version string
GoVersion string
GitCommit string
BuiltTime string
Built int64
BuildOrigin string `json:",omitempty" yaml:",omitempty"`
OsArch string
Os string
}

// GetVersion returns a VersionOutput struct for API and podman
Expand All @@ -43,13 +47,14 @@ func GetVersion() (Version, error) {
}
}
return Version{
APIVersion: version.APIVersion[version.Libpod][version.CurrentAPI].String(),
Version: version.Version.String(),
GoVersion: runtime.Version(),
GitCommit: gitCommit,
BuiltTime: time.Unix(buildTime, 0).Format(time.ANSIC),
Built: buildTime,
OsArch: runtime.GOOS + "/" + runtime.GOARCH,
Os: runtime.GOOS,
APIVersion: version.APIVersion[version.Libpod][version.CurrentAPI].String(),
Version: version.Version.String(),
GoVersion: runtime.Version(),
GitCommit: gitCommit,
BuiltTime: time.Unix(buildTime, 0).Format(time.ANSIC),
Built: buildTime,
BuildOrigin: buildOrigin,
OsArch: runtime.GOOS + "/" + runtime.GOARCH,
Os: runtime.GOOS,
}, nil
}
18 changes: 16 additions & 2 deletions pkg/bindings/system/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (

"github.com/containers/podman/v5/libpod/define"
"github.com/containers/podman/v5/pkg/bindings"
"github.com/containers/podman/v5/pkg/domain/entities/types"
)

// Info returns information about the libpod environment and its stores
func Info(ctx context.Context, _ *InfoOptions) (*define.Info, error) {
func Info(ctx context.Context, _ *InfoOptions) (*types.SystemInfoReport, error) {
conn, err := bindings.GetClient(ctx)
if err != nil {
return nil, err
Expand All @@ -21,5 +22,18 @@ func Info(ctx context.Context, _ *InfoOptions) (*define.Info, error) {
defer response.Body.Close()

info := define.Info{}
return &info, response.Process(&info)
if err = response.Process(&info); err != nil {
return nil, err
}

clientVersion, err := define.GetVersion()
if err != nil {
return nil, err
}

report := types.SystemInfoReport{
Info: info,
Client: &clientVersion,
}
return &report, nil
}
2 changes: 1 addition & 1 deletion pkg/domain/entities/engine_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type ContainerEngine interface { //nolint:interfacebloat
GenerateKube(ctx context.Context, nameOrIDs []string, opts GenerateKubeOptions) (*GenerateKubeReport, error)
SystemPrune(ctx context.Context, options SystemPruneOptions) (*SystemPruneReport, error)
HealthCheckRun(ctx context.Context, nameOrID string, options HealthCheckOptions) (*define.HealthCheckResults, error)
Info(ctx context.Context) (*define.Info, error)
Info(ctx context.Context) (*SystemInfoReport, error)
KubeApply(ctx context.Context, body io.Reader, opts ApplyOptions) error
Locks(ctx context.Context) (*LocksReport, error)
Migrate(ctx context.Context, options SystemMigrateOptions) error
Expand Down
1 change: 1 addition & 0 deletions pkg/domain/entities/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type SystemVersionReport = types.SystemVersionReport
type SystemUnshareOptions = types.SystemUnshareOptions
type ComponentVersion = types.SystemComponentVersion
type ListRegistriesReport = types.ListRegistriesReport
type SystemInfoReport = types.SystemInfoReport

type AuthConfig = types.AuthConfig
type AuthReport = types.AuthReport
Expand Down
5 changes: 5 additions & 0 deletions pkg/domain/entities/types/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ type SystemPruneReport struct {
ReclaimedSpace uint64
}

type SystemInfoReport struct {
define.Info
Client *define.Version `json:",omitempty" yaml:",omitempty"`
}

// SystemMigrateOptions describes the options needed for the
// cli to migrate runtimes of containers
type SystemMigrateOptions struct {
Expand Down
15 changes: 12 additions & 3 deletions pkg/domain/infra/abi/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import (
"github.com/containers/podman/v5/libpod/define"
"github.com/containers/podman/v5/pkg/domain/entities"
"github.com/containers/podman/v5/pkg/domain/entities/reports"
"github.com/containers/podman/v5/pkg/domain/entities/types"
"github.com/containers/podman/v5/pkg/util"
"github.com/containers/storage"
"github.com/containers/storage/pkg/directory"
"github.com/containers/storage/pkg/fileutils"
"github.com/sirupsen/logrus"
)

func (ic *ContainerEngine) Info(ctx context.Context) (*define.Info, error) {
func (ic *ContainerEngine) Info(ctx context.Context) (*entities.SystemInfoReport, error) {
info, err := ic.Libpod.Info()
if err != nil {
return nil, err
Expand All @@ -36,7 +37,11 @@ func (ic *ContainerEngine) Info(ctx context.Context) (*define.Info, error) {
xdg := defaultRunPath
if path, err := util.GetRootlessRuntimeDir(); err != nil {
// Info is as good as we can guess...
return info, err
report := types.SystemInfoReport{
Info: *info,
}
return &report, err

} else if path != "" {
xdg = path
}
Expand All @@ -58,7 +63,11 @@ func (ic *ContainerEngine) Info(ctx context.Context) (*define.Info, error) {
info.Host.RemoteSocket.Exists = true
}

return info, nil
report := types.SystemInfoReport{
Info: *info,
}

return &report, nil
}

// SystemPrune removes unused data from the system. Pruning pods, containers, networks, volumes and images.
Expand Down
3 changes: 1 addition & 2 deletions pkg/domain/infra/tunnel/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import (
"context"
"errors"

"github.com/containers/podman/v5/libpod/define"
"github.com/containers/podman/v5/pkg/bindings/system"
"github.com/containers/podman/v5/pkg/domain/entities"
)

func (ic *ContainerEngine) Info(ctx context.Context) (*define.Info, error) {
func (ic *ContainerEngine) Info(ctx context.Context) (*entities.SystemInfoReport, error) {
return system.Info(ic.ClientCtx, nil)
}

Expand Down
13 changes: 13 additions & 0 deletions test/e2e/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,18 @@ var _ = Describe("Podman Info", func() {
Expect(free1).To(Equal(free2 + 1))
})

It("Podman info: check client information", func() {
info := podmanTest.Podman([]string{"info", "--format", "{{ .Client }}"})
info.WaitWithDefaultTimeout()
Expect(info).To(ExitCleanly())
// client info should only appear when using the remote client
if IsRemote() {
Expect(info.OutputToString()).ToNot(Equal("<nil>"))
} else {
Expect(info.OutputToString()).To(Equal("<nil>"))
}
})

It("Podman info: check for client information when no system service", func() {
// the output for this information is not really something we can marshall
want := runtime.GOOS + "/" + runtime.GOARCH
Expand All @@ -291,4 +303,5 @@ var _ = Describe("Podman Info", func() {
Expect(info).ToNot(ExitCleanly())
podmanTest.StartRemoteService() // Start service again so teardown runs clean
})

})

0 comments on commit 0abcdcf

Please sign in to comment.