mirror of https://github.com/containers/podman.git
Merge pull request #24781 from ashley-cui/builtfor
Add BuildOrigin field to podman info
This commit is contained in:
commit
39becc2f05
1
Makefile
1
Makefile
|
|
@ -119,6 +119,7 @@ GOFLAGS ?= -trimpath
|
||||||
LDFLAGS_PODMAN ?= \
|
LDFLAGS_PODMAN ?= \
|
||||||
$(if $(GIT_COMMIT),-X $(LIBPOD)/define.gitCommit=$(GIT_COMMIT),) \
|
$(if $(GIT_COMMIT),-X $(LIBPOD)/define.gitCommit=$(GIT_COMMIT),) \
|
||||||
$(if $(BUILD_INFO),-X $(LIBPOD)/define.buildInfo=$(BUILD_INFO),) \
|
$(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._installPrefix=$(PREFIX) \
|
||||||
-X $(LIBPOD)/config._etcDir=$(ETCDIR) \
|
-X $(LIBPOD)/config._etcDir=$(ETCDIR) \
|
||||||
-X $(PROJECT)/v5/pkg/systemd/quadlet._binDir=$(BINDIR) \
|
-X $(PROJECT)/v5/pkg/systemd/quadlet._binDir=$(BINDIR) \
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,10 @@ package main
|
||||||
import "github.com/containers/podman/v5/libpod/define"
|
import "github.com/containers/podman/v5/libpod/define"
|
||||||
|
|
||||||
type clientInfo struct {
|
type clientInfo struct {
|
||||||
OSArch string `json:"OS"`
|
OSArch string `json:"OS"`
|
||||||
Provider string `json:"provider"`
|
Provider string `json:"provider"`
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
|
BuildOrigin string `json:"buildOrigin,omitempty" yaml:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func getClientInfo() (*clientInfo, error) {
|
func getClientInfo() (*clientInfo, error) {
|
||||||
|
|
@ -18,8 +19,9 @@ func getClientInfo() (*clientInfo, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &clientInfo{
|
return &clientInfo{
|
||||||
OSArch: vinfo.OsArch,
|
OSArch: vinfo.OsArch,
|
||||||
Provider: p,
|
Provider: p,
|
||||||
Version: vinfo.Version,
|
Version: vinfo.Version,
|
||||||
|
BuildOrigin: vinfo.BuildOrigin,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,11 @@ var (
|
||||||
debug bool
|
debug bool
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type infoReport struct {
|
||||||
|
define.Info
|
||||||
|
Client *define.Version `json:",omitempty" yaml:",omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.Commands = append(registry.Commands, registry.CliCommand{
|
registry.Commands = append(registry.Commands, registry.CliCommand{
|
||||||
Command: infoCommand,
|
Command: infoCommand,
|
||||||
|
|
@ -74,12 +79,21 @@ func info(cmd *cobra.Command, args []string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
remote := registry.IsRemote()
|
||||||
|
info.Host.ServiceIsRemote = remote
|
||||||
|
|
||||||
info.Host.ServiceIsRemote = registry.IsRemote()
|
infoReport := infoReport{
|
||||||
|
Info: *info,
|
||||||
|
}
|
||||||
|
|
||||||
|
if remote {
|
||||||
|
clientVers, _ := define.GetVersion()
|
||||||
|
infoReport.Client = &clientVers
|
||||||
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case report.IsJSON(inFormat):
|
case report.IsJSON(inFormat):
|
||||||
b, err := json.MarshalIndent(info, "", " ")
|
b, err := json.MarshalIndent(infoReport, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -94,9 +108,9 @@ func info(cmd *cobra.Command, args []string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return rpt.Execute(info)
|
return rpt.Execute(infoReport)
|
||||||
default:
|
default:
|
||||||
b, err := yaml.Marshal(info)
|
b, err := yaml.Marshal(infoReport)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,7 @@ API Version:\t{{.APIVersion}}
|
||||||
Go Version:\t{{.GoVersion}}
|
Go Version:\t{{.GoVersion}}
|
||||||
{{if .GitCommit -}}Git Commit:\t{{.GitCommit}}\n{{end -}}
|
{{if .GitCommit -}}Git Commit:\t{{.GitCommit}}\n{{end -}}
|
||||||
Built:\t{{.BuiltTime}}
|
Built:\t{{.BuiltTime}}
|
||||||
|
{{if .BuildOrigin -}}Build Origin:\t{{.BuildOrigin}}\n{{end -}}
|
||||||
OS/Arch:\t{{.OsArch}}
|
OS/Arch:\t{{.OsArch}}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
|
|
||||||
|
|
@ -108,6 +109,7 @@ API Version:\t{{.APIVersion}}
|
||||||
Go Version:\t{{.GoVersion}}
|
Go Version:\t{{.GoVersion}}
|
||||||
{{if .GitCommit -}}Git Commit:\t{{.GitCommit}}\n{{end -}}
|
{{if .GitCommit -}}Git Commit:\t{{.GitCommit}}\n{{end -}}
|
||||||
Built:\t{{.BuiltTime}}
|
Built:\t{{.BuiltTime}}
|
||||||
|
{{if .BuildOrigin -}}Build Origin:\t{{.BuildOrigin}}\n{{end -}}
|
||||||
OS/Arch:\t{{.OsArch}}
|
OS/Arch:\t{{.OsArch}}
|
||||||
{{- end}}{{- end}}
|
{{- end}}{{- end}}
|
||||||
`
|
`
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ PRODUCTSIGN_IDENTITY=${PRODUCTSIGN_IDENTITY:-mock}
|
||||||
NO_CODESIGN=${NO_CODESIGN:-0}
|
NO_CODESIGN=${NO_CODESIGN:-0}
|
||||||
HELPER_BINARIES_DIR="/opt/podman/bin"
|
HELPER_BINARIES_DIR="/opt/podman/bin"
|
||||||
MACHINE_POLICY_JSON_DIR="/opt/podman/config"
|
MACHINE_POLICY_JSON_DIR="/opt/podman/config"
|
||||||
|
BUILD_ORIGIN="pkginstaller"
|
||||||
|
|
||||||
tmpBin="contrib/pkginstaller/tmp-bin"
|
tmpBin="contrib/pkginstaller/tmp-bin"
|
||||||
|
|
||||||
|
|
@ -47,7 +48,7 @@ function build_podman() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function build_podman_arch(){
|
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
|
make -B GOARCH="$1" podman-mac-helper
|
||||||
mkdir -p "${tmpBin}"
|
mkdir -p "${tmpBin}"
|
||||||
cp bin/darwin/podman "${tmpBin}/podman-$1"
|
cp bin/darwin/podman "${tmpBin}/podman-$1"
|
||||||
|
|
|
||||||
|
|
@ -16,18 +16,22 @@ var (
|
||||||
// BuildInfo is the time at which the binary was built
|
// BuildInfo is the time at which the binary was built
|
||||||
// It will be populated by the Makefile.
|
// It will be populated by the Makefile.
|
||||||
buildInfo string
|
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
|
// Version is an output struct for API
|
||||||
type Version struct {
|
type Version struct {
|
||||||
APIVersion string
|
APIVersion string
|
||||||
Version string
|
Version string
|
||||||
GoVersion string
|
GoVersion string
|
||||||
GitCommit string
|
GitCommit string
|
||||||
BuiltTime string
|
BuiltTime string
|
||||||
Built int64
|
Built int64
|
||||||
OsArch string
|
BuildOrigin string `json:",omitempty" yaml:",omitempty"`
|
||||||
Os string
|
OsArch string
|
||||||
|
Os string
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVersion returns a VersionOutput struct for API and podman
|
// GetVersion returns a VersionOutput struct for API and podman
|
||||||
|
|
@ -43,13 +47,14 @@ func GetVersion() (Version, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Version{
|
return Version{
|
||||||
APIVersion: version.APIVersion[version.Libpod][version.CurrentAPI].String(),
|
APIVersion: version.APIVersion[version.Libpod][version.CurrentAPI].String(),
|
||||||
Version: version.Version.String(),
|
Version: version.Version.String(),
|
||||||
GoVersion: runtime.Version(),
|
GoVersion: runtime.Version(),
|
||||||
GitCommit: gitCommit,
|
GitCommit: gitCommit,
|
||||||
BuiltTime: time.Unix(buildTime, 0).Format(time.ANSIC),
|
BuiltTime: time.Unix(buildTime, 0).Format(time.ANSIC),
|
||||||
Built: buildTime,
|
Built: buildTime,
|
||||||
OsArch: runtime.GOOS + "/" + runtime.GOARCH,
|
BuildOrigin: buildOrigin,
|
||||||
Os: runtime.GOOS,
|
OsArch: runtime.GOOS + "/" + runtime.GOARCH,
|
||||||
|
Os: runtime.GOOS,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -291,4 +291,16 @@ var _ = Describe("Podman Info", func() {
|
||||||
Expect(info).ToNot(ExitCleanly())
|
Expect(info).ToNot(ExitCleanly())
|
||||||
podmanTest.StartRemoteService() // Start service again so teardown runs clean
|
podmanTest.StartRemoteService() // Start service again so teardown runs clean
|
||||||
})
|
})
|
||||||
|
|
||||||
|
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>"))
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue