diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index 600c1e74f5..df92b0e9b2 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -54,7 +54,7 @@ const ( ) var ( - dockerCli *client.Client + dockerCli client.CommonAPIClient registryConfig *h.TestRegistryConfig suiteManager *SuiteManager ) @@ -1479,7 +1479,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...") @@ -1501,7 +1501,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) @@ -1659,7 +1659,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) diff --git a/client.go b/client.go index ad5ee068d4..53e6c47d4d 100644 --- a/client.go +++ b/client.go @@ -40,7 +40,7 @@ type Client struct { imageFetcher ImageFetcher downloader Downloader lifecycle Lifecycle - docker *dockerClient.Client + docker dockerClient.CommonAPIClient imageFactory ImageFactory } @@ -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 } diff --git a/internal/build/build.go b/internal/build/build.go index 713b0c8f55..a9d7df9b8e 100644 --- a/internal/build/build.go +++ b/internal/build/build.go @@ -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 @@ -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} } diff --git a/internal/build/phase.go b/internal/build/phase.go index 0e8c3cd44c..0a038eb88d 100644 --- a/internal/build/phase.go +++ b/internal/build/phase.go @@ -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 diff --git a/internal/build/phase_test.go b/internal/build/phase_test.go index 8cb7aee6aa..d2828d538d 100644 --- a/internal/build/phase_test.go +++ b/internal/build/phase_test.go @@ -28,7 +28,7 @@ import ( var ( repoName string - dockerCli *client.Client + dockerCli client.CommonAPIClient ) func TestPhase(t *testing.T) { @@ -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() { @@ -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 { diff --git a/internal/cache/image_cache.go b/internal/cache/image_cache.go index ec85baab3a..187ad4858a 100644 --- a/internal/cache/image_cache.go +++ b/internal/cache/image_cache.go @@ -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]), diff --git a/internal/cache/image_cache_test.go b/internal/cache/image_cache_test.go index 292e919f8d..13f24cf1ac 100644 --- a/internal/cache/image_cache_test.go +++ b/internal/cache/image_cache_test.go @@ -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 @@ -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 ) diff --git a/internal/cache/volume_cache.go b/internal/cache/volume_cache.go index f12391f708..9cc1893cc7 100644 --- a/internal/cache/volume_cache.go +++ b/internal/cache/volume_cache.go @@ -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), diff --git a/internal/cache/volume_cache_test.go b/internal/cache/volume_cache_test.go index 94534bbe44..2238133e52 100644 --- a/internal/cache/volume_cache_test.go +++ b/internal/cache/volume_cache_test.go @@ -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 @@ -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 ) diff --git a/internal/container/run.go b/internal/container/run.go index e615f04bab..218776a4cd 100644 --- a/internal/container/run.go +++ b/internal/container/run.go @@ -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 { diff --git a/internal/image/factory.go b/internal/image/factory.go index dbf3b377c5..e31892a46d 100644 --- a/internal/image/factory.go +++ b/internal/image/factory.go @@ -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, diff --git a/internal/image/fetcher.go b/internal/image/fetcher.go index 3ec4b667c3..2538c2889b 100644 --- a/internal/image/fetcher.go +++ b/internal/image/fetcher.go @@ -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, diff --git a/internal/image/fetcher_test.go b/internal/image/fetcher_test.go index 1f888b3244..cdf855d1ff 100644 --- a/internal/image/fetcher_test.go +++ b/internal/image/fetcher_test.go @@ -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) { diff --git a/testhelpers/testhelpers.go b/testhelpers/testhelpers.go index 930140ab63..8708e64485 100644 --- a/testhelpers/testhelpers.go +++ b/testhelpers/testhelpers.go @@ -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")) }) @@ -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) @@ -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) @@ -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) @@ -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 { @@ -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 @@ -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 @@ -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 {