Skip to content

Commit

Permalink
Extract shared interfaces to their own file
Browse files Browse the repository at this point in the history
  • Loading branch information
dgodd committed Nov 24, 2018
1 parent eba23ce commit 38221d4
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 41 deletions.
32 changes: 0 additions & 32 deletions create_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,6 @@ type Buildpack struct {
Latest bool
}

//go:generate mockgen -package mocks -destination mocks/docker.go github.com/buildpack/pack Docker
type Docker interface {
PullImage(ref string) error
RunContainer(ctx context.Context, id string, stdout io.Writer, stderr io.Writer) error
VolumeRemove(ctx context.Context, volumeID string, force bool) error
ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (container.ContainerCreateCreatedBody, error)
ContainerRemove(ctx context.Context, containerID string, options types.ContainerRemoveOptions) error
CopyToContainer(ctx context.Context, containerID, dstPath string, content io.Reader, options types.CopyToContainerOptions) error
CopyFromContainer(ctx context.Context, containerID, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
ImageBuild(ctx context.Context, buildContext io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error)
ImageInspectWithRaw(ctx context.Context, imageID string) (types.ImageInspect, []byte, error)
}

//go:generate mockgen -package mocks -destination mocks/images.go github.com/buildpack/pack Images
type Images interface {
ReadImage(repoName string, useDaemon bool) (v1.Image, error)
RepoStore(repoName string, useDaemon bool) (img.Store, error)
}

//go:generate mockgen -package mocks -destination mocks/task.go github.com/buildpack/pack Task
type Task interface {
Run() error
}

type BuilderFactory struct {
Log *log.Logger
Docker Docker
Expand All @@ -80,14 +56,6 @@ type BuilderFactory struct {
Images Images
}

//go:generate mockgen -package mocks -destination mocks/fs.go github.com/buildpack/pack FS
type FS interface {
CreateTGZFile(tarFile, srcDir, tarDir string, uid, gid int) error
CreateTarReader(srcDir, tarDir string, uid, gid int) (io.Reader, chan error)
Untar(r io.Reader, dest string) error
CreateSingleFileTar(path, txt string) (io.Reader, error)
}

type CreateBuilderFlags struct {
RepoName string
BuilderTomlPath string
Expand Down
67 changes: 67 additions & 0 deletions interfaces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package pack

import (
"compress/gzip"
"context"
"crypto/sha256"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
"path/filepath"

"github.com/BurntSushi/toml"
"github.com/buildpack/lifecycle"
"github.com/buildpack/lifecycle/img"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
"github.com/google/go-containerregistry/pkg/v1"
"github.com/pkg/errors"

"github.com/buildpack/pack/config"
)

//go:generate mockgen -package mocks -destination mocks/docker.go github.com/buildpack/pack Docker
type Docker interface {
PullImage(ref string) error
RunContainer(ctx context.Context, id string, stdout io.Writer, stderr io.Writer) error
VolumeRemove(ctx context.Context, volumeID string, force bool) error
ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (container.ContainerCreateCreatedBody, error)
ContainerRemove(ctx context.Context, containerID string, options types.ContainerRemoveOptions) error
CopyToContainer(ctx context.Context, containerID, dstPath string, content io.Reader, options types.CopyToContainerOptions) error
CopyFromContainer(ctx context.Context, containerID, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
ImageBuild(ctx context.Context, buildContext io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error)
ImageInspectWithRaw(ctx context.Context, imageID string) (types.ImageInspect, []byte, error)
}

//go:generate mockgen -package mocks -destination mocks/images.go github.com/buildpack/pack Images
type Images interface {
ReadImage(repoName string, useDaemon bool) (v1.Image, error)
RepoStore(repoName string, useDaemon bool) (img.Store, error)
}

//go:generate mockgen -package mocks -destination mocks/task.go github.com/buildpack/pack Task
type Task interface {
Run() error
}

//go:generate mockgen -package mocks -destination mocks/fs.go github.com/buildpack/pack FS
type FS interface {
CreateTGZFile(tarFile, srcDir, tarDir string, uid, gid int) error
CreateTarReader(srcDir, tarDir string, uid, gid int) (io.Reader, chan error)
Untar(r io.Reader, dest string) error
CreateSingleFileTar(path, txt string) (io.Reader, error)
}

type WritableStore interface {
Write(image v1.Image) error
}

type ImageFactory interface {
NewLocal(string, bool) (image.Image, error)
NewRemote(string) (image.Image, error)
}
9 changes: 0 additions & 9 deletions rebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ type RebaseConfig struct {
NewBaseImage image.Image
}

type WritableStore interface {
Write(image v1.Image) error
}

type RebaseFactory struct {
Log *log.Logger
Config *config.Config
Expand All @@ -32,11 +28,6 @@ type RebaseFlags struct {
NoPull bool
}

type ImageFactory interface {
NewLocal(string, bool) (image.Image, error)
NewRemote(string) (image.Image, error)
}

func (f *RebaseFactory) RebaseConfigFromFlags(flags RebaseFlags) (RebaseConfig, error) {
var newImage func(string) (image.Image, error)
if flags.Publish {
Expand Down

0 comments on commit 38221d4

Please sign in to comment.