Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the interface rather than the concrete type #471

Merged
merged 2 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const (
)

var (
dockerCli *client.Client
dockerCli client.CommonAPIClient
registryConfig *h.TestRegistryConfig
suiteManager *SuiteManager
)
Expand Down Expand Up @@ -1481,7 +1481,7 @@ func createPackage(t *testing.T, configDir, tmpDir, packPath string) string {
return packageImageName
}

func createStack(t *testing.T, dockerCli *client.Client, runImageMirror string) error {
func createStack(t *testing.T, dockerCli client.CommonAPIClient, runImageMirror string) error {
t.Helper()
t.Log("creating stack images...")

Expand All @@ -1503,7 +1503,7 @@ func createStack(t *testing.T, dockerCli *client.Client, runImageMirror string)
return nil
}

func createStackImage(dockerCli *client.Client, repoName string, dir string) error {
func createStackImage(dockerCli client.CommonAPIClient, repoName string, dir string) error {
ctx := context.Background()
buildContext := archive.ReadDirAsTar(dir, "/", 0, 0, -1)

Expand Down Expand Up @@ -1661,7 +1661,7 @@ func terminateAtStep(t *testing.T, cmd *exec.Cmd, buf *bytes.Buffer, pattern str
}
}

func imageLabel(t *testing.T, dockerCli *client.Client, repoName, labelName string) string {
func imageLabel(t *testing.T, dockerCli client.CommonAPIClient, repoName, labelName string) string {
t.Helper()
inspect, _, err := dockerCli.ImageInspectWithRaw(context.Background(), repoName)
h.AssertNil(t, err)
Expand Down
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Client struct {
imageFetcher ImageFetcher
downloader Downloader
lifecycle Lifecycle
docker *dockerClient.Client
docker dockerClient.CommonAPIClient
imageFactory ImageFactory
}

Expand Down Expand Up @@ -84,7 +84,7 @@ func WithCacheDir(path string) ClientOption {
}

// WithDockerClient supply your own docker client.
func WithDockerClient(docker *dockerClient.Client) ClientOption {
func WithDockerClient(docker dockerClient.CommonAPIClient) ClientOption {
return func(c *Client) {
c.docker = docker
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require (
github.com/BurntSushi/toml v0.3.1
github.com/Masterminds/semver v1.4.2
github.com/apex/log v1.1.2-0.20190827100214-baa5455d1012
github.com/buildpacks/imgutil v0.0.0-20191212154113-dc184e0d403b
github.com/buildpacks/imgutil v0.0.0-20200127205531-eec2000815b1
github.com/buildpacks/lifecycle v0.5.1-0.20191217221752-3b74c943b7b3
github.com/dgodd/dockerdial v1.0.1
github.com/docker/docker v1.4.2-0.20190924003213-a8608b5b67c7
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ github.com/aws/aws-sdk-go v1.20.6/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN
github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59/go.mod h1:q/89r3U2H7sSsE2t6Kca0lfwTK8JdoNGS/yzM/4iH5I=
github.com/buildpacks/imgutil v0.0.0-20191212154113-dc184e0d403b h1:SDsB0hJtURA+5i5vIjLntzRNPEqdoz6q+0MShCWdctw=
github.com/buildpacks/imgutil v0.0.0-20191212154113-dc184e0d403b/go.mod h1:E3lXJcNXcRefJQAHW5rqboonet+jtOml4qImbJhYGAo=
github.com/buildpacks/imgutil v0.0.0-20200127205531-eec2000815b1 h1:1+v3XHezNuXCf7YWW77U8go0gYBmr4BbnSZyV0PYa80=
github.com/buildpacks/imgutil v0.0.0-20200127205531-eec2000815b1/go.mod h1:E3lXJcNXcRefJQAHW5rqboonet+jtOml4qImbJhYGAo=
github.com/buildpacks/lifecycle v0.5.1-0.20191217221752-3b74c943b7b3 h1:15zYyFmNbrtx5MmyVEKVgY2/eearqEqGJXLCjmvUo58=
github.com/buildpacks/lifecycle v0.5.1-0.20191217221752-3b74c943b7b3/go.mod h1:ZIuIs9B6tjAW4dthhltKVyEUlhRfFWWix9eqoInMGX4=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
Expand Down
4 changes: 2 additions & 2 deletions internal/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (
type Lifecycle struct {
builder *builder.Builder
logger logging.Logger
docker *client.Client
docker client.CommonAPIClient
appPath string
appOnce *sync.Once
httpProxy string
Expand All @@ -46,7 +46,7 @@ func init() {
rand.Seed(time.Now().UTC().UnixNano())
}

func NewLifecycle(docker *client.Client, logger logging.Logger) *Lifecycle {
func NewLifecycle(docker client.CommonAPIClient, logger logging.Logger) *Lifecycle {
return &Lifecycle{logger: logger, docker: docker}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/build/phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
type Phase struct {
name string
logger logging.Logger
docker *client.Client
docker client.CommonAPIClient
ctrConf *dcontainer.Config
hostConf *dcontainer.HostConfig
ctr dcontainer.ContainerCreateCreatedBody
Expand Down
6 changes: 3 additions & 3 deletions internal/build/phase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

var (
repoName string
dockerCli *client.Client
dockerCli client.CommonAPIClient
)

func TestPhase(t *testing.T) {
Expand Down Expand Up @@ -56,7 +56,7 @@ func testPhase(t *testing.T, when spec.G, it spec.S) {
var (
subject *build.Lifecycle
outBuf, errBuf bytes.Buffer
docker *client.Client
docker client.CommonAPIClient
)

it.Before(func() {
Expand Down Expand Up @@ -333,7 +333,7 @@ func assertRunSucceeds(t *testing.T, phase *build.Phase, outBuf *bytes.Buffer, e
phase.Cleanup()
}

func CreateFakeLifecycle(appDir string, docker *client.Client, logger logging.Logger) (*build.Lifecycle, error) {
func CreateFakeLifecycle(appDir string, docker client.CommonAPIClient, logger logging.Logger) (*build.Lifecycle, error) {
subject := build.NewLifecycle(docker, logger)
builderImage, err := local.NewImage(repoName, docker, local.FromBaseImage(repoName))
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/cache/image_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
)

type ImageCache struct {
docker *client.Client
docker client.CommonAPIClient
image string
}

func NewImageCache(imageRef name.Reference, dockerClient *client.Client) *ImageCache {
func NewImageCache(imageRef name.Reference, dockerClient client.CommonAPIClient) *ImageCache {
sum := sha256.Sum256([]byte(imageRef.Name()))
return &ImageCache{
image: fmt.Sprintf("pack-cache-%x", sum[:6]),
Expand Down
4 changes: 2 additions & 2 deletions internal/cache/image_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestImageCache(t *testing.T) {

func testImageCache(t *testing.T, when spec.G, it spec.S) {
when("#NewImageCache", func() {
var dockerClient *client.Client
var dockerClient client.CommonAPIClient

it.Before(func() {
var err error
Expand Down Expand Up @@ -100,7 +100,7 @@ func testImageCache(t *testing.T, when spec.G, it spec.S) {
when("#Clear", func() {
var (
imageName string
dockerClient *client.Client
dockerClient client.CommonAPIClient
subject *cache.ImageCache
ctx context.Context
)
Expand Down
4 changes: 2 additions & 2 deletions internal/cache/volume_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
)

type VolumeCache struct {
docker *client.Client
docker client.CommonAPIClient
volume string
}

func NewVolumeCache(imageRef name.Reference, suffix string, dockerClient *client.Client) *VolumeCache {
func NewVolumeCache(imageRef name.Reference, suffix string, dockerClient client.CommonAPIClient) *VolumeCache {
sum := sha256.Sum256([]byte(imageRef.Name()))
return &VolumeCache{
volume: fmt.Sprintf("pack-cache-%x.%s", sum[:6], suffix),
Expand Down
4 changes: 2 additions & 2 deletions internal/cache/volume_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestVolumeCache(t *testing.T) {

func testCache(t *testing.T, when spec.G, it spec.S) {
when("#NewVolumeCache", func() {
var dockerClient *client.Client
var dockerClient client.CommonAPIClient

it.Before(func() {
var err error
Expand Down Expand Up @@ -108,7 +108,7 @@ func testCache(t *testing.T, when spec.G, it spec.S) {
when("#Clear", func() {
var (
volumeName string
dockerClient *client.Client
dockerClient client.CommonAPIClient
subject *cache.VolumeCache
ctx context.Context
)
Expand Down
2 changes: 1 addition & 1 deletion internal/container/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/pkg/errors"
)

func Run(ctx context.Context, docker *client.Client, ctrID string, out, errOut io.Writer) error {
func Run(ctx context.Context, docker client.CommonAPIClient, ctrID string, out, errOut io.Writer) error {
bodyChan, errChan := docker.ContainerWait(ctx, ctrID, dcontainer.WaitConditionNextExit)

if err := docker.ContainerStart(ctx, ctrID, types.ContainerStartOptions{}); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/image/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
)

type DefaultImageFactory struct {
dockerClient *client.Client
dockerClient client.CommonAPIClient
keychain authn.Keychain
}

func NewFactory(dockerClient *client.Client, keychain authn.Keychain) *DefaultImageFactory {
func NewFactory(dockerClient client.CommonAPIClient, keychain authn.Keychain) *DefaultImageFactory {
return &DefaultImageFactory{
dockerClient: dockerClient,
keychain: keychain,
Expand Down
4 changes: 2 additions & 2 deletions internal/image/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
)

type Fetcher struct {
docker *client.Client
docker client.CommonAPIClient
logger logging.Logger
}

func NewFetcher(logger logging.Logger, docker *client.Client) *Fetcher {
func NewFetcher(logger logging.Logger, docker client.CommonAPIClient) *Fetcher {
return &Fetcher{
logger: logger,
docker: docker,
Expand Down
2 changes: 1 addition & 1 deletion internal/image/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
h "github.com/buildpacks/pack/testhelpers"
)

var docker *client.Client
var docker client.CommonAPIClient
var registryConfig *h.TestRegistryConfig

func TestFetcher(t *testing.T) {
Expand Down
18 changes: 9 additions & 9 deletions testhelpers/testhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ func hasMatches(actual, exp string) bool {
return len(matches) > 0
}

var dockerCliVal *client.Client
var dockerCliVal client.CommonAPIClient
var dockerCliOnce sync.Once
var dockerCliErr error

func dockerCli(t *testing.T) *client.Client {
func dockerCli(t *testing.T) client.CommonAPIClient {
dockerCliOnce.Do(func() {
dockerCliVal, dockerCliErr = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
})
Expand Down Expand Up @@ -236,7 +236,7 @@ func Eventually(t *testing.T, test func() bool, every time.Duration, timeout tim
}
}

func CreateImage(t *testing.T, dockerCli *client.Client, repoName, dockerFile string) {
func CreateImage(t *testing.T, dockerCli client.CommonAPIClient, repoName, dockerFile string) {
t.Helper()

buildContext, err := archive.CreateSingleFileTarReader("Dockerfile", dockerFile)
Expand All @@ -254,7 +254,7 @@ func CreateImage(t *testing.T, dockerCli *client.Client, repoName, dockerFile st
AssertNil(t, errors.Wrapf(err, "building image %s", style.Symbol(repoName)))
}

func CreateImageFromDir(t *testing.T, dockerCli *client.Client, repoName string, dir string) {
func CreateImageFromDir(t *testing.T, dockerCli client.CommonAPIClient, repoName string, dir string) {
t.Helper()

buildContext := archive.ReadDirAsTar(dir, "/", 0, 0, -1)
Expand Down Expand Up @@ -301,7 +301,7 @@ func checkResponse(response dockertypes.ImageBuildResponse) error {
return nil
}

func CreateImageOnRemote(t *testing.T, dockerCli *client.Client, registryConfig *TestRegistryConfig, repoName, dockerFile string) string {
func CreateImageOnRemote(t *testing.T, dockerCli client.CommonAPIClient, registryConfig *TestRegistryConfig, repoName, dockerFile string) string {
t.Helper()
imageName := registryConfig.RepoName(repoName)

Expand All @@ -311,7 +311,7 @@ func CreateImageOnRemote(t *testing.T, dockerCli *client.Client, registryConfig
return imageName
}

func DockerRmi(dockerCli *client.Client, repoNames ...string) error {
func DockerRmi(dockerCli client.CommonAPIClient, repoNames ...string) error {
var err error
ctx := context.Background()
for _, name := range repoNames {
Expand All @@ -327,7 +327,7 @@ func DockerRmi(dockerCli *client.Client, repoNames ...string) error {
return err
}

func PushImage(dockerCli *client.Client, ref string, registryConfig *TestRegistryConfig) error {
func PushImage(dockerCli client.CommonAPIClient, ref string, registryConfig *TestRegistryConfig) error {
rc, err := dockerCli.ImagePush(context.Background(), ref, dockertypes.ImagePushOptions{RegistryAuth: registryConfig.RegistryAuth()})
if err != nil {
return err
Expand Down Expand Up @@ -418,7 +418,7 @@ func RunE(cmd *exec.Cmd) (string, error) {
return string(output), nil
}

func PullImageWithAuth(dockerCli *client.Client, ref, registryAuth string) error {
func PullImageWithAuth(dockerCli client.CommonAPIClient, ref, registryAuth string) error {
rc, err := dockerCli.ImagePull(context.Background(), ref, dockertypes.ImagePullOptions{RegistryAuth: registryAuth})
if err != nil {
return nil
Expand Down Expand Up @@ -482,7 +482,7 @@ func SkipIf(t *testing.T, expression bool, reason string) {
}
}

func RunContainer(ctx context.Context, dockerCli *client.Client, id string, stdout io.Writer, stderr io.Writer) error {
func RunContainer(ctx context.Context, dockerCli client.CommonAPIClient, id string, stdout io.Writer, stderr io.Writer) error {
bodyChan, errChan := dockerCli.ContainerWait(ctx, id, container.WaitConditionNextExit)

if err := dockerCli.ContainerStart(ctx, id, dockertypes.ContainerStartOptions{}); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions vendor/github.com/buildpacks/imgutil/image.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading