Skip to content

Commit

Permalink
[NO TESTS NEEDED] Shrink the size of podman-remote
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan authored and mheon committed Apr 16, 2021
1 parent c8130be commit 32f61db
Show file tree
Hide file tree
Showing 23 changed files with 245 additions and 92 deletions.
34 changes: 17 additions & 17 deletions cmd/podman/images/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"time"

"github.com/containers/buildah/define"
buildahDefine "github.com/containers/buildah/define"
buildahCLI "github.com/containers/buildah/pkg/cli"
"github.com/containers/buildah/pkg/parse"
"github.com/containers/common/pkg/auth"
Expand Down Expand Up @@ -159,11 +159,11 @@ func buildFlags(cmd *cobra.Command) {
flags.SetNormalizeFunc(buildahCLI.AliasFlags)
if registry.IsRemote() {
flag = flags.Lookup("isolation")
buildOpts.Isolation = define.OCI
if err := flag.Value.Set(define.OCI); err != nil {
logrus.Errorf("unable to set --isolation to %v: %v", define.OCI, err)
buildOpts.Isolation = buildahDefine.OCI
if err := flag.Value.Set(buildahDefine.OCI); err != nil {
logrus.Errorf("unable to set --isolation to %v: %v", buildahDefine.OCI, err)
}
flag.DefValue = define.OCI
flag.DefValue = buildahDefine.OCI
_ = flags.MarkHidden("disable-content-trust")
_ = flags.MarkHidden("cache-from")
_ = flags.MarkHidden("sign-by")
Expand Down Expand Up @@ -196,7 +196,7 @@ func build(cmd *cobra.Command, args []string) error {
var contextDir string
if len(args) > 0 {
// The context directory could be a URL. Try to handle that.
tempDir, subDir, err := define.TempDirForURL("", "buildah", args[0])
tempDir, subDir, err := buildahDefine.TempDirForURL("", "buildah", args[0])
if err != nil {
return errors.Wrapf(err, "error prepping temporary context directory")
}
Expand Down Expand Up @@ -319,16 +319,16 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *buil
return nil, errors.Errorf("can only set one of 'pull' or 'pull-always' or 'pull-never'")
}

pullPolicy := define.PullIfMissing
pullPolicy := buildahDefine.PullIfMissing
if c.Flags().Changed("pull") && flags.Pull {
pullPolicy = define.PullAlways
pullPolicy = buildahDefine.PullAlways
}
if flags.PullAlways {
pullPolicy = define.PullAlways
pullPolicy = buildahDefine.PullAlways
}

if flags.PullNever {
pullPolicy = define.PullNever
pullPolicy = buildahDefine.PullNever
}

if c.Flag("authfile").Changed {
Expand Down Expand Up @@ -409,9 +409,9 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *buil
flags.Layers = false
}

compression := define.Gzip
compression := buildahDefine.Gzip
if flags.DisableCompression {
compression = define.Uncompressed
compression = buildahDefine.Uncompressed
}

isolation, err := parse.IsolationOption(flags.Isolation)
Expand All @@ -433,10 +433,10 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *buil
format := ""
flags.Format = strings.ToLower(flags.Format)
switch {
case strings.HasPrefix(flags.Format, define.OCI):
format = define.OCIv1ImageManifest
case strings.HasPrefix(flags.Format, define.DOCKER):
format = define.Dockerv2ImageManifest
case strings.HasPrefix(flags.Format, buildahDefine.OCI):
format = buildahDefine.OCIv1ImageManifest
case strings.HasPrefix(flags.Format, buildahDefine.DOCKER):
format = buildahDefine.Dockerv2ImageManifest
default:
return nil, errors.Errorf("unrecognized image type %q", flags.Format)
}
Expand Down Expand Up @@ -464,7 +464,7 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *buil
return nil, errors.Wrapf(err, "unable to obtain decrypt config")
}

opts := define.BuildOptions{
opts := buildahDefine.BuildOptions{
AddCapabilities: flags.CapAdd,
AdditionalTags: tags,
Annotations: flags.Annotation,
Expand Down
4 changes: 2 additions & 2 deletions libpod/events/logfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/containers/podman/v3/pkg/util"
"github.com/containers/storage"
"github.com/containers/storage/pkg/lockfile"
"github.com/pkg/errors"
)

Expand All @@ -20,7 +20,7 @@ type EventLogFile struct {
// Writes to the log file
func (e EventLogFile) Write(ee Event) error {
// We need to lock events file
lock, err := storage.GetLockfile(e.options.LogFilePath + ".lock")
lock, err := lockfile.GetLockfile(e.options.LogFilePath + ".lock")
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion libpod/runtime_img.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/url"
"os"

buildahDefine "github.com/containers/buildah/define"
"github.com/containers/buildah/imagebuildah"
"github.com/containers/image/v5/directory"
"github.com/containers/image/v5/docker/reference"
Expand Down Expand Up @@ -165,7 +166,7 @@ func (r *Runtime) newImageBuildCompleteEvent(idOrName string) {
}

// Build adds the runtime to the imagebuildah call
func (r *Runtime) Build(ctx context.Context, options imagebuildah.BuildOptions, dockerfiles ...string) (string, reference.Canonical, error) {
func (r *Runtime) Build(ctx context.Context, options buildahDefine.BuildOptions, dockerfiles ...string) (string, reference.Canonical, error) {
if options.Runtime == "" {
options.Runtime = r.GetOCIRuntimePath()
}
Expand Down
11 changes: 5 additions & 6 deletions pkg/api/handlers/compat/images_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import (
"time"

"github.com/containers/buildah"
"github.com/containers/buildah/define"
"github.com/containers/buildah/imagebuildah"
buildahDefine "github.com/containers/buildah/define"
"github.com/containers/buildah/util"
"github.com/containers/image/v5/types"
"github.com/containers/podman/v3/libpod"
Expand Down Expand Up @@ -277,13 +276,13 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
jobs = query.Jobs
}

pullPolicy := define.PullIfMissing
pullPolicy := buildahDefine.PullIfMissing
if utils.IsLibpodRequest(r) {
pullPolicy = define.PolicyMap[query.PullPolicy]
pullPolicy = buildahDefine.PolicyMap[query.PullPolicy]
} else {
if _, found := r.URL.Query()["pull"]; found {
if query.Pull {
pullPolicy = define.PullAlways
pullPolicy = buildahDefine.PullAlways
}
}
}
Expand Down Expand Up @@ -315,7 +314,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Decode()"))
return
}
buildOptions := imagebuildah.BuildOptions{
buildOptions := buildahDefine.BuildOptions{
AddCapabilities: addCaps,
AdditionalTags: additionalTags,
Annotations: annotations,
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/handlers/compat/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/containers/podman/v3/libpod/define"
"github.com/containers/podman/v3/pkg/api/handlers/utils"
"github.com/containers/podman/v3/pkg/domain/entities"
"github.com/containers/podman/v3/pkg/domain/entities/types"
"github.com/containers/podman/v3/version"
docker "github.com/docker/docker/api/types"
"github.com/pkg/errors"
)

Expand All @@ -32,7 +32,7 @@ func VersionHandler(w http.ResponseWriter, r *http.Request) {
return
}

components := []docker.ComponentVersion{{
components := []types.ComponentVersion{{
Name: "Podman Engine",
Version: versionInfo.Version,
Details: map[string]string{
Expand All @@ -52,7 +52,7 @@ func VersionHandler(w http.ResponseWriter, r *http.Request) {
minVersion := version.APIVersion[version.Compat][version.MinimalAPI]

utils.WriteResponse(w, http.StatusOK, entities.ComponentVersion{
Version: docker.Version{
Version: types.Version{
Platform: struct {
Name string
}{
Expand Down
4 changes: 0 additions & 4 deletions pkg/api/handlers/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ type ContainerConfig struct {
dockerContainer.Config
}

type LibpodImagesLoadReport struct {
ID string `json:"id"`
}

type LibpodImagesPullReport struct {
entities.ImagePullReport
}
Expand Down
23 changes: 23 additions & 0 deletions pkg/api/handlers/types/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package types

import (
"github.com/containers/podman/v3/pkg/domain/entities"
)

// LibpodImagesRemoveReport is the return type for image removal via the rest
// api.
type LibpodImagesRemoveReport struct {
entities.ImageRemoveReport
// Image removal requires is to return data and an error.
Errors []string
}

// HistoryResponse provides details on image layers
type HistoryResponse struct {
ID string `json:"Id"`
Created int64
CreatedBy string
Tags []string
Size int64
Comment string
}
1 change: 0 additions & 1 deletion pkg/bindings/images/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO
if len(platform) > 0 {
params.Set("platform", platform)
}

params.Set("pullpolicy", options.PullPolicy.String())

if options.Quiet {
Expand Down
6 changes: 3 additions & 3 deletions pkg/bindings/images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/url"
"strconv"

"github.com/containers/podman/v3/pkg/api/handlers"
"github.com/containers/podman/v3/pkg/api/handlers/types"
"github.com/containers/podman/v3/pkg/auth"
"github.com/containers/podman/v3/pkg/bindings"
"github.com/containers/podman/v3/pkg/domain/entities"
Expand Down Expand Up @@ -96,12 +96,12 @@ func Tree(ctx context.Context, nameOrID string, options *TreeOptions) (*entities
}

// History returns the parent layers of an image.
func History(ctx context.Context, nameOrID string, options *HistoryOptions) ([]*handlers.HistoryResponse, error) {
func History(ctx context.Context, nameOrID string, options *HistoryOptions) ([]*types.HistoryResponse, error) {
if options == nil {
options = new(HistoryOptions)
}
_ = options
var history []*handlers.HistoryResponse
var history []*types.HistoryResponse
conn, err := bindings.GetClient(ctx)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions pkg/bindings/images/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"net/http"

"github.com/containers/podman/v3/pkg/api/handlers"
"github.com/containers/podman/v3/pkg/api/handlers/types"
"github.com/containers/podman/v3/pkg/bindings"
"github.com/containers/podman/v3/pkg/domain/entities"
"github.com/containers/podman/v3/pkg/errorhandling"
Expand All @@ -19,7 +19,7 @@ func Remove(ctx context.Context, images []string, options *RemoveOptions) (*enti
// FIXME - bindings tests are missing for this endpoint. Once the CI is
// re-enabled for bindings, we need to add them. At the time of writing,
// the tests don't compile.
var report handlers.LibpodImagesRemoveReport
var report types.LibpodImagesRemoveReport
conn, err := bindings.GetClient(ctx)
if err != nil {
return nil, []error{err}
Expand Down
4 changes: 2 additions & 2 deletions pkg/bindings/images/types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package images

import (
"github.com/containers/buildah/imagebuildah"
buildahDefine "github.com/containers/buildah/define"
)

//go:generate go run ../generator/generator.go RemoveOptions
Expand Down Expand Up @@ -162,7 +162,7 @@ type PullOptions struct {

//BuildOptions are optional options for building images
type BuildOptions struct {
imagebuildah.BuildOptions
buildahDefine.BuildOptions
}

//go:generate go run ../generator/generator.go ExistsOptions
Expand Down
41 changes: 20 additions & 21 deletions pkg/domain/entities/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,32 @@ import (
"github.com/containers/image/v5/types"
"github.com/containers/podman/v3/pkg/inspect"
"github.com/containers/podman/v3/pkg/trust"
docker "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/opencontainers/go-digest"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
)

type Image struct {
ID string `json:"Id"`
RepoTags []string `json:",omitempty"`
RepoDigests []string `json:",omitempty"`
Parent string `json:",omitempty"`
Comment string `json:",omitempty"`
Created string `json:",omitempty"`
Container string `json:",omitempty"`
ContainerConfig *container.Config `json:",omitempty"`
DockerVersion string `json:",omitempty"`
Author string `json:",omitempty"`
Config *container.Config `json:",omitempty"`
Architecture string `json:",omitempty"`
Variant string `json:",omitempty"`
Os string `json:",omitempty"`
OsVersion string `json:",omitempty"`
Size int64 `json:",omitempty"`
VirtualSize int64 `json:",omitempty"`
GraphDriver docker.GraphDriverData `json:",omitempty"`
RootFS docker.RootFS `json:",omitempty"`
Metadata docker.ImageMetadata `json:",omitempty"`
ID string `json:"Id"`
RepoTags []string `json:",omitempty"`
RepoDigests []string `json:",omitempty"`
Parent string `json:",omitempty"`
Comment string `json:",omitempty"`
Created string `json:",omitempty"`
Container string `json:",omitempty"`
ContainerConfig *container.Config `json:",omitempty"`
DockerVersion string `json:",omitempty"`
Author string `json:",omitempty"`
Config *container.Config `json:",omitempty"`
Architecture string `json:",omitempty"`
Variant string `json:",omitempty"`
Os string `json:",omitempty"`
OsVersion string `json:",omitempty"`
Size int64 `json:",omitempty"`
VirtualSize int64 `json:",omitempty"`
GraphDriver string `json:",omitempty"`
RootFS string `json:",omitempty"`
Metadata string `json:",omitempty"`

// Podman extensions
Digest digest.Digest `json:",omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/domain/entities/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/containers/podman/v3/libpod/define"
"github.com/containers/podman/v3/pkg/domain/entities/reports"
"github.com/docker/docker/api/types"
"github.com/containers/podman/v3/pkg/domain/entities/types"
"github.com/spf13/cobra"
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/domain/entities/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package entities
import (
"net"

"github.com/containers/buildah/imagebuildah"
buildahDefine "github.com/containers/buildah/define"
"github.com/containers/podman/v3/libpod/events"
"github.com/containers/podman/v3/pkg/specgen"
"github.com/containers/storage/pkg/archive"
Expand Down Expand Up @@ -91,7 +91,7 @@ type ContainerCreateResponse struct {

// BuildOptions describe the options for building container images.
type BuildOptions struct {
imagebuildah.BuildOptions
buildahDefine.BuildOptions
}

// BuildReport is the image-build report.
Expand Down
22 changes: 22 additions & 0 deletions pkg/domain/entities/types/auth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package types // import "github.com/docker/docker/api/types"

// AuthConfig contains authorization information for connecting to a Registry
type AuthConfig struct {
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
Auth string `json:"auth,omitempty"`

// Email is an optional value associated with the username.
// This field is deprecated and will be removed in a later
// version of docker.
Email string `json:"email,omitempty"`

ServerAddress string `json:"serveraddress,omitempty"`

// IdentityToken is used to authenticate the user and get
// an access token for the registry.
IdentityToken string `json:"identitytoken,omitempty"`

// RegistryToken is a bearer token to be sent to a registry
RegistryToken string `json:"registrytoken,omitempty"`
}
Loading

0 comments on commit 32f61db

Please sign in to comment.