Skip to content

Commit 39becc2

Browse files
Merge pull request #24781 from ashley-cui/builtfor
Add BuildOrigin field to podman info
2 parents dc6fc24 + d3706bc commit 39becc2

File tree

7 files changed

+64
-27
lines changed

7 files changed

+64
-27
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ GOFLAGS ?= -trimpath
119119
LDFLAGS_PODMAN ?= \
120120
$(if $(GIT_COMMIT),-X $(LIBPOD)/define.gitCommit=$(GIT_COMMIT),) \
121121
$(if $(BUILD_INFO),-X $(LIBPOD)/define.buildInfo=$(BUILD_INFO),) \
122+
$(if $(BUILD_ORIGIN),-X $(LIBPOD)/define.buildOrigin=$(BUILD_ORIGIN),) \
122123
-X $(LIBPOD)/config._installPrefix=$(PREFIX) \
123124
-X $(LIBPOD)/config._etcDir=$(ETCDIR) \
124125
-X $(PROJECT)/v5/pkg/systemd/quadlet._binDir=$(BINDIR) \

cmd/podman/client.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package main
33
import "github.com/containers/podman/v5/libpod/define"
44

55
type clientInfo struct {
6-
OSArch string `json:"OS"`
7-
Provider string `json:"provider"`
8-
Version string `json:"version"`
6+
OSArch string `json:"OS"`
7+
Provider string `json:"provider"`
8+
Version string `json:"version"`
9+
BuildOrigin string `json:"buildOrigin,omitempty" yaml:",omitempty"`
910
}
1011

1112
func getClientInfo() (*clientInfo, error) {
@@ -18,8 +19,9 @@ func getClientInfo() (*clientInfo, error) {
1819
return nil, err
1920
}
2021
return &clientInfo{
21-
OSArch: vinfo.OsArch,
22-
Provider: p,
23-
Version: vinfo.Version,
22+
OSArch: vinfo.OsArch,
23+
Provider: p,
24+
Version: vinfo.Version,
25+
BuildOrigin: vinfo.BuildOrigin,
2426
}, nil
2527
}

cmd/podman/system/info.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ var (
4545
debug bool
4646
)
4747

48+
type infoReport struct {
49+
define.Info
50+
Client *define.Version `json:",omitempty" yaml:",omitempty"`
51+
}
52+
4853
func init() {
4954
registry.Commands = append(registry.Commands, registry.CliCommand{
5055
Command: infoCommand,
@@ -74,12 +79,21 @@ func info(cmd *cobra.Command, args []string) error {
7479
if err != nil {
7580
return err
7681
}
82+
remote := registry.IsRemote()
83+
info.Host.ServiceIsRemote = remote
7784

78-
info.Host.ServiceIsRemote = registry.IsRemote()
85+
infoReport := infoReport{
86+
Info: *info,
87+
}
88+
89+
if remote {
90+
clientVers, _ := define.GetVersion()
91+
infoReport.Client = &clientVers
92+
}
7993

8094
switch {
8195
case report.IsJSON(inFormat):
82-
b, err := json.MarshalIndent(info, "", " ")
96+
b, err := json.MarshalIndent(infoReport, "", " ")
8397
if err != nil {
8498
return err
8599
}
@@ -94,9 +108,9 @@ func info(cmd *cobra.Command, args []string) error {
94108
if err != nil {
95109
return err
96110
}
97-
return rpt.Execute(info)
111+
return rpt.Execute(infoReport)
98112
default:
99-
b, err := yaml.Marshal(info)
113+
b, err := yaml.Marshal(infoReport)
100114
if err != nil {
101115
return err
102116
}

cmd/podman/system/version.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ API Version:\t{{.APIVersion}}
9797
Go Version:\t{{.GoVersion}}
9898
{{if .GitCommit -}}Git Commit:\t{{.GitCommit}}\n{{end -}}
9999
Built:\t{{.BuiltTime}}
100+
{{if .BuildOrigin -}}Build Origin:\t{{.BuildOrigin}}\n{{end -}}
100101
OS/Arch:\t{{.OsArch}}
101102
{{- end}}
102103
@@ -108,6 +109,7 @@ API Version:\t{{.APIVersion}}
108109
Go Version:\t{{.GoVersion}}
109110
{{if .GitCommit -}}Git Commit:\t{{.GitCommit}}\n{{end -}}
110111
Built:\t{{.BuiltTime}}
112+
{{if .BuildOrigin -}}Build Origin:\t{{.BuildOrigin}}\n{{end -}}
111113
OS/Arch:\t{{.OsArch}}
112114
{{- end}}{{- end}}
113115
`

contrib/pkginstaller/package.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ PRODUCTSIGN_IDENTITY=${PRODUCTSIGN_IDENTITY:-mock}
99
NO_CODESIGN=${NO_CODESIGN:-0}
1010
HELPER_BINARIES_DIR="/opt/podman/bin"
1111
MACHINE_POLICY_JSON_DIR="/opt/podman/config"
12+
BUILD_ORIGIN="pkginstaller"
1213

1314
tmpBin="contrib/pkginstaller/tmp-bin"
1415

@@ -47,7 +48,7 @@ function build_podman() {
4748
}
4849

4950
function build_podman_arch(){
50-
make -B GOARCH="$1" podman-remote HELPER_BINARIES_DIR="${HELPER_BINARIES_DIR}"
51+
make -B GOARCH="$1" podman-remote HELPER_BINARIES_DIR="${HELPER_BINARIES_DIR}" BUILD_ORIGIN="${BUILD_ORIGIN}"
5152
make -B GOARCH="$1" podman-mac-helper
5253
mkdir -p "${tmpBin}"
5354
cp bin/darwin/podman "${tmpBin}/podman-$1"

libpod/define/version.go

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,22 @@ var (
1616
// BuildInfo is the time at which the binary was built
1717
// It will be populated by the Makefile.
1818
buildInfo string
19+
// BuildOrigin is the packager of the binary.
20+
// It will be populated at build-time.
21+
buildOrigin string
1922
)
2023

2124
// Version is an output struct for API
2225
type Version struct {
23-
APIVersion string
24-
Version string
25-
GoVersion string
26-
GitCommit string
27-
BuiltTime string
28-
Built int64
29-
OsArch string
30-
Os string
26+
APIVersion string
27+
Version string
28+
GoVersion string
29+
GitCommit string
30+
BuiltTime string
31+
Built int64
32+
BuildOrigin string `json:",omitempty" yaml:",omitempty"`
33+
OsArch string
34+
Os string
3135
}
3236

3337
// GetVersion returns a VersionOutput struct for API and podman
@@ -43,13 +47,14 @@ func GetVersion() (Version, error) {
4347
}
4448
}
4549
return Version{
46-
APIVersion: version.APIVersion[version.Libpod][version.CurrentAPI].String(),
47-
Version: version.Version.String(),
48-
GoVersion: runtime.Version(),
49-
GitCommit: gitCommit,
50-
BuiltTime: time.Unix(buildTime, 0).Format(time.ANSIC),
51-
Built: buildTime,
52-
OsArch: runtime.GOOS + "/" + runtime.GOARCH,
53-
Os: runtime.GOOS,
50+
APIVersion: version.APIVersion[version.Libpod][version.CurrentAPI].String(),
51+
Version: version.Version.String(),
52+
GoVersion: runtime.Version(),
53+
GitCommit: gitCommit,
54+
BuiltTime: time.Unix(buildTime, 0).Format(time.ANSIC),
55+
Built: buildTime,
56+
BuildOrigin: buildOrigin,
57+
OsArch: runtime.GOOS + "/" + runtime.GOARCH,
58+
Os: runtime.GOOS,
5459
}, nil
5560
}

test/e2e/info_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,16 @@ var _ = Describe("Podman Info", func() {
291291
Expect(info).ToNot(ExitCleanly())
292292
podmanTest.StartRemoteService() // Start service again so teardown runs clean
293293
})
294+
295+
It("Podman info: check client information", func() {
296+
info := podmanTest.Podman([]string{"info", "--format", "{{ .Client }}"})
297+
info.WaitWithDefaultTimeout()
298+
Expect(info).To(ExitCleanly())
299+
// client info should only appear when using the remote client
300+
if IsRemote() {
301+
Expect(info.OutputToString()).ToNot(Equal("<nil>"))
302+
} else {
303+
Expect(info.OutputToString()).To(Equal("<nil>"))
304+
}
305+
})
294306
})

0 commit comments

Comments
 (0)