diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/api/handlers/compat/version.go | 3 | ||||
-rw-r--r-- | pkg/api/handlers/types.go | 4 | ||||
-rw-r--r-- | pkg/api/server/register_version.go | 21 | ||||
-rw-r--r-- | pkg/api/server/swagger.go | 9 | ||||
-rw-r--r-- | pkg/bindings/system/system.go | 38 | ||||
-rw-r--r-- | pkg/domain/entities/engine_container.go | 2 | ||||
-rw-r--r-- | pkg/domain/entities/system.go | 14 | ||||
-rw-r--r-- | pkg/domain/infra/abi/system.go | 26 | ||||
-rw-r--r-- | pkg/domain/infra/tunnel/system.go | 8 | ||||
-rw-r--r-- | pkg/specgen/generate/oci.go | 18 |
10 files changed, 125 insertions, 18 deletions
diff --git a/pkg/api/handlers/compat/version.go b/pkg/api/handlers/compat/version.go index 35a95b562..8786f1d5b 100644 --- a/pkg/api/handlers/compat/version.go +++ b/pkg/api/handlers/compat/version.go @@ -10,6 +10,7 @@ import ( "github.com/containers/libpod/libpod/define" "github.com/containers/libpod/pkg/api/handlers" "github.com/containers/libpod/pkg/api/handlers/utils" + "github.com/containers/libpod/pkg/domain/entities" docker "github.com/docker/docker/api/types" "github.com/pkg/errors" ) @@ -46,7 +47,7 @@ func VersionHandler(w http.ResponseWriter, r *http.Request) { }, }} - utils.WriteResponse(w, http.StatusOK, handlers.Version{Version: docker.Version{ + utils.WriteResponse(w, http.StatusOK, entities.ComponentVersion{Version: docker.Version{ Platform: struct { Name string }{ diff --git a/pkg/api/handlers/types.go b/pkg/api/handlers/types.go index a7abf59c0..2075d29df 100644 --- a/pkg/api/handlers/types.go +++ b/pkg/api/handlers/types.go @@ -71,10 +71,6 @@ type Container struct { docker.ContainerCreateConfig } -type Version struct { - docker.Version -} - type DiskUsage struct { docker.DiskUsage } diff --git a/pkg/api/server/register_version.go b/pkg/api/server/register_version.go index 25cacbc61..30289ffe3 100644 --- a/pkg/api/server/register_version.go +++ b/pkg/api/server/register_version.go @@ -8,7 +8,28 @@ import ( ) func (s *APIServer) registerVersionHandlers(r *mux.Router) error { + // swagger:operation GET /version compat CompatSystemVersion + // --- + // summary: Component Version information + // tags: + // - system (compat) + // produces: + // - application/json + // responses: + // 200: + // $ref: "#/responses/Version" r.Handle("/version", s.APIHandler(compat.VersionHandler)).Methods(http.MethodGet) r.Handle(VersionedPath("/version"), s.APIHandler(compat.VersionHandler)).Methods(http.MethodGet) + // swagger:operation GET /libpod/version libpod SystemVersion + // --- + // summary: Component Version information + // tags: + // - system + // produces: + // - application/json + // responses: + // 200: + // $ref: "#/responses/Version" + r.Handle(VersionedPath("/libpod/version"), s.APIHandler(compat.VersionHandler)).Methods(http.MethodGet) return nil } diff --git a/pkg/api/server/swagger.go b/pkg/api/server/swagger.go index 75dcc71a6..e47f2cc2f 100644 --- a/pkg/api/server/swagger.go +++ b/pkg/api/server/swagger.go @@ -181,3 +181,12 @@ type swagHealthCheckRunResponse struct { define.HealthCheckResults } } + +// Version +// swagger:response Version +type swagVersion struct { + // in:body + Body struct { + entities.SystemVersionReport + } +} diff --git a/pkg/bindings/system/system.go b/pkg/bindings/system/system.go index df6b529de..caef6af6f 100644 --- a/pkg/bindings/system/system.go +++ b/pkg/bindings/system/system.go @@ -3,11 +3,14 @@ package system import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" "strconv" + "time" + "github.com/containers/libpod/libpod/define" "github.com/containers/libpod/pkg/bindings" "github.com/containers/libpod/pkg/domain/entities" "github.com/pkg/errors" @@ -83,3 +86,38 @@ func Prune(ctx context.Context, all, volumes *bool) (*entities.SystemPruneReport } return &report, response.Process(&report) } + +func Version(ctx context.Context) (*entities.SystemVersionReport, error) { + var report entities.SystemVersionReport + var component entities.ComponentVersion + + version, err := define.GetVersion() + if err != nil { + return nil, err + } + report.Client = &version + + conn, err := bindings.GetClient(ctx) + if err != nil { + return nil, err + } + response, err := conn.DoRequest(nil, http.MethodGet, "/version", nil) + if err != nil { + return nil, err + } + + if err = response.Process(&component); err != nil { + return nil, err + } + f, _ := strconv.ParseFloat(component.APIVersion, 64) + b, _ := time.Parse(time.RFC3339, component.BuildTime) + report.Server = &define.Version{ + RemoteAPIVersion: int64(f), + Version: component.Version.Version, + GoVersion: component.GoVersion, + GitCommit: component.GitCommit, + Built: b.Unix(), + OsArch: fmt.Sprintf("%s/%s", component.Os, component.Arch), + } + return &report, err +} diff --git a/pkg/domain/entities/engine_container.go b/pkg/domain/entities/engine_container.go index 7c93e6802..719ac3f9e 100644 --- a/pkg/domain/entities/engine_container.go +++ b/pkg/domain/entities/engine_container.go @@ -71,7 +71,9 @@ type ContainerEngine interface { SetupRootless(ctx context.Context, cmd *cobra.Command) error Shutdown(ctx context.Context) SystemDf(ctx context.Context, options SystemDfOptions) (*SystemDfReport, error) + Unshare(ctx context.Context, args []string) error VarlinkService(ctx context.Context, opts ServiceOptions) error + Version(ctx context.Context) (*SystemVersionReport, error) VolumeCreate(ctx context.Context, opts VolumeCreateOptions) (*IdOrNameResponse, error) VolumeInspect(ctx context.Context, namesOrIds []string, opts VolumeInspectOptions) ([]*VolumeInspectReport, error) VolumeList(ctx context.Context, opts VolumeListOptions) ([]*VolumeListReport, error) diff --git a/pkg/domain/entities/system.go b/pkg/domain/entities/system.go index c62f40025..5e4760d12 100644 --- a/pkg/domain/entities/system.go +++ b/pkg/domain/entities/system.go @@ -3,6 +3,8 @@ package entities import ( "time" + "github.com/containers/libpod/libpod/define" + "github.com/docker/docker/api/types" "github.com/spf13/cobra" ) @@ -83,3 +85,15 @@ type SystemDfVolumeReport struct { type SystemResetOptions struct { Force bool } + +// SystemVersionReport describes version information about the running Podman service +type SystemVersionReport struct { + // Always populated + Client *define.Version `json:",omitempty"` + // May be populated, when in tunnel mode + Server *define.Version `json:",omitempty"` +} + +type ComponentVersion struct { + types.Version +} diff --git a/pkg/domain/infra/abi/system.go b/pkg/domain/infra/abi/system.go index 24c62465f..d701d65de 100644 --- a/pkg/domain/infra/abi/system.go +++ b/pkg/domain/infra/abi/system.go @@ -5,6 +5,7 @@ import ( "fmt" "io/ioutil" "os" + "os/exec" "path/filepath" "strconv" "syscall" @@ -391,3 +392,28 @@ func (s SystemEngine) Shutdown(ctx context.Context) { logrus.Error(err) } } + +func unshareEnv(graphroot, runroot string) []string { + return append(os.Environ(), "_CONTAINERS_USERNS_CONFIGURED=done", + fmt.Sprintf("CONTAINERS_GRAPHROOT=%s", graphroot), + fmt.Sprintf("CONTAINERS_RUNROOT=%s", runroot)) +} + +func (ic *ContainerEngine) Unshare(ctx context.Context, args []string) error { + cmd := exec.Command(args[0], args[1:]...) + cmd.Env = unshareEnv(ic.Libpod.StorageConfig().GraphRoot, ic.Libpod.StorageConfig().RunRoot) + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + return cmd.Run() +} + +func (ic ContainerEngine) Version(ctx context.Context) (*entities.SystemVersionReport, error) { + var report entities.SystemVersionReport + v, err := define.GetVersion() + if err != nil { + return nil, err + } + report.Client = &v + return &report, err +} diff --git a/pkg/domain/infra/tunnel/system.go b/pkg/domain/infra/tunnel/system.go index 448fbed1f..dafada805 100644 --- a/pkg/domain/infra/tunnel/system.go +++ b/pkg/domain/infra/tunnel/system.go @@ -30,3 +30,11 @@ func (ic *ContainerEngine) SystemPrune(ctx context.Context, options entities.Sys func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.SystemDfOptions) (*entities.SystemDfReport, error) { panic(errors.New("system df is not supported on remote clients")) } + +func (ic *ContainerEngine) Unshare(ctx context.Context, args []string) error { + return errors.New("unshare is not supported on remote clients") +} + +func (ic ContainerEngine) Version(ctx context.Context) (*entities.SystemVersionReport, error) { + return system.Version(ic.ClientCxt) +} diff --git a/pkg/specgen/generate/oci.go b/pkg/specgen/generate/oci.go index a2bb66a44..11b18e2d0 100644 --- a/pkg/specgen/generate/oci.go +++ b/pkg/specgen/generate/oci.go @@ -321,12 +321,6 @@ func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runt configSpec.Annotations = make(map[string]string) } - // TODO cidfile is not in specgen; when wiring up cli, we will need to move this out of here - // leaving as a reminder - //if config.CidFile != "" { - // configSpec.Annotations[libpod.InspectAnnotationCIDFile] = config.CidFile - //} - if s.Remove { configSpec.Annotations[define.InspectAnnotationAutoremove] = define.InspectResponseTrue } else { @@ -343,13 +337,11 @@ func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runt configSpec.Annotations[define.InspectAnnotationPrivileged] = define.InspectResponseFalse } - // TODO Init might not make it into the specgen and therefore is not available here. We should deal - // with this when we wire up the CLI; leaving as a reminder - //if s.Init { - // configSpec.Annotations[libpod.InspectAnnotationInit] = libpod.InspectResponseTrue - //} else { - // configSpec.Annotations[libpod.InspectAnnotationInit] = libpod.InspectResponseFalse - //} + if s.Init { + configSpec.Annotations[define.InspectAnnotationInit] = define.InspectResponseTrue + } else { + configSpec.Annotations[define.InspectAnnotationInit] = define.InspectResponseFalse + } return configSpec, nil } |