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

Add feature to pull-policy for pulling images according to user specified pulling interval (e.g., hourly, daily, weekly, interval=5d4h30m ) #2075

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
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
25 changes: 14 additions & 11 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
imagewriter "github.com/buildpacks/pack/internal/inspectimage/writer"
"github.com/buildpacks/pack/internal/term"
"github.com/buildpacks/pack/pkg/client"
"github.com/buildpacks/pack/pkg/image"
"github.com/buildpacks/pack/pkg/logging"
)

Expand All @@ -33,7 +34,9 @@ func NewPackCommand(logger ConfigurableLogger) (*cobra.Command, error) {
return nil, err
}

packClient, err := initClient(logger, cfg)
imagePullPolicyHandler := image.NewPullPolicyManager(logger)

packClient, err := initClient(logger, cfg, imagePullPolicyHandler)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -75,14 +78,14 @@ func NewPackCommand(logger ConfigurableLogger) (*cobra.Command, error) {

commands.AddHelpFlag(rootCmd, "pack")

rootCmd.AddCommand(commands.Build(logger, cfg, packClient))
rootCmd.AddCommand(commands.NewBuilderCommand(logger, cfg, packClient))
rootCmd.AddCommand(commands.NewBuildpackCommand(logger, cfg, packClient, buildpackage.NewConfigReader()))
rootCmd.AddCommand(commands.NewExtensionCommand(logger, cfg, packClient, buildpackage.NewConfigReader()))
rootCmd.AddCommand(commands.NewConfigCommand(logger, cfg, cfgPath, packClient))
rootCmd.AddCommand(commands.Build(logger, cfg, packClient, imagePullPolicyHandler))
rootCmd.AddCommand(commands.NewBuilderCommand(logger, cfg, packClient, imagePullPolicyHandler))
rootCmd.AddCommand(commands.NewBuildpackCommand(logger, cfg, packClient, buildpackage.NewConfigReader(), imagePullPolicyHandler))
rootCmd.AddCommand(commands.NewExtensionCommand(logger, cfg, packClient, buildpackage.NewConfigReader(), imagePullPolicyHandler))
rootCmd.AddCommand(commands.NewConfigCommand(logger, cfg, cfgPath, packClient, imagePullPolicyHandler))
rootCmd.AddCommand(commands.InspectImage(logger, imagewriter.NewFactory(), cfg, packClient))
rootCmd.AddCommand(commands.NewStackCommand(logger))
rootCmd.AddCommand(commands.Rebase(logger, cfg, packClient))
rootCmd.AddCommand(commands.Rebase(logger, cfg, packClient, imagePullPolicyHandler))
rootCmd.AddCommand(commands.NewSBOMCommand(logger, cfg, packClient))

rootCmd.AddCommand(commands.InspectBuildpack(logger, cfg, packClient))
Expand All @@ -94,8 +97,8 @@ func NewPackCommand(logger ConfigurableLogger) (*cobra.Command, error) {
rootCmd.AddCommand(commands.TrustBuilder(logger, cfg, cfgPath))
rootCmd.AddCommand(commands.UntrustBuilder(logger, cfg, cfgPath))
rootCmd.AddCommand(commands.ListTrustedBuilders(logger, cfg))
rootCmd.AddCommand(commands.CreateBuilder(logger, cfg, packClient))
rootCmd.AddCommand(commands.PackageBuildpack(logger, cfg, packClient, buildpackage.NewConfigReader()))
rootCmd.AddCommand(commands.CreateBuilder(logger, cfg, packClient, imagePullPolicyHandler))
rootCmd.AddCommand(commands.PackageBuildpack(logger, cfg, packClient, buildpackage.NewConfigReader(), imagePullPolicyHandler))

if cfg.Experimental {
rootCmd.AddCommand(commands.AddBuildpackRegistry(logger, cfg, cfgPath))
Expand Down Expand Up @@ -136,7 +139,7 @@ func initConfig() (config.Config, string, error) {
return cfg, path, nil
}

func initClient(logger logging.Logger, cfg config.Config) (*client.Client, error) {
func initClient(logger logging.Logger, cfg config.Config, imagePullPolicyHandler image.ImagePullPolicyHandler) (*client.Client, error) {
if err := client.ProcessDockerContext(logger); err != nil {
return nil, err
}
Expand All @@ -145,5 +148,5 @@ func initClient(logger logging.Logger, cfg config.Config) (*client.Client, error
if err != nil {
return nil, err
}
return client.NewClient(client.WithLogger(logger), client.WithExperimental(cfg.Experimental), client.WithRegistryMirrors(cfg.RegistryMirrors), client.WithDockerClient(dc))
return client.NewClient(client.WithLogger(logger), client.WithExperimental(cfg.Experimental), client.WithRegistryMirrors(cfg.RegistryMirrors), client.WithDockerClient(dc), client.WithImagePullChecker(imagePullPolicyHandler))
}
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/docker/docker v25.0.5+incompatible
github.com/docker/go-connections v0.5.0
github.com/dustin/go-humanize v1.0.1
github.com/gdamore/tcell/v2 v2.7.4
github.com/gdamore/tcell/v2 v2.7.1
github.com/go-git/go-git/v5 v5.11.0
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.6.0
Expand All @@ -29,9 +29,9 @@ require (
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
github.com/sclevine/spec v1.4.0
github.com/spf13/cobra v1.8.0
golang.org/x/crypto v0.21.0
golang.org/x/mod v0.16.0
golang.org/x/oauth2 v0.18.0
golang.org/x/crypto v0.20.0
golang.org/x/mod v0.15.0
golang.org/x/oauth2 v0.17.0
golang.org/x/sync v0.6.0
golang.org/x/sys v0.18.0
golang.org/x/term v0.18.0
Expand Down Expand Up @@ -132,8 +132,8 @@ require (
go.opentelemetry.io/otel v1.23.0 // indirect
go.opentelemetry.io/otel/metric v1.23.0 // indirect
go.opentelemetry.io/otel/trace v1.23.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/tools v0.17.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/tools v0.18.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
Expand Down
24 changes: 12 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1/go.mod h1:Az6Jt+M5idSED2YPGtwnfJV0kXohgdCBPmHGSYc1r04=
github.com/gdamore/tcell/v2 v2.7.4 h1:sg6/UnTM9jGpZU+oFYAsDahfchWAFW8Xx2yFinNSAYU=
github.com/gdamore/tcell/v2 v2.7.4/go.mod h1:dSXtXTSK0VsW1biw65DZLZ2NKr7j0qP/0J7ONmsraWg=
github.com/gdamore/tcell/v2 v2.7.1 h1:TiCcmpWHiAU7F0rA2I3S2Y4mmLmO9KHxJ7E1QhYzQbc=
github.com/gdamore/tcell/v2 v2.7.1/go.mod h1:dSXtXTSK0VsW1biw65DZLZ2NKr7j0qP/0J7ONmsraWg=
github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY=
github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4=
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
Expand Down Expand Up @@ -417,15 +417,15 @@ golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0
golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/crypto v0.20.0 h1:jmAMJJZXr5KiCw05dfYK9QnqaqKLYXijU23lsEdcQqg=
golang.org/x/crypto v0.20.0/go.mod h1:Xwo95rrVNIoSMx9wa1JroENMToLWn3RNVrTBpLHgZPQ=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic=
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand All @@ -441,11 +441,11 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.18.0 h1:09qnuIAgzdx1XplqJvW6CQqMCtGZykZWcXzPMPUusvI=
golang.org/x/oauth2 v0.18.0/go.mod h1:Wf7knwG0MPoWIMMBgFlEaSUDaKskp0dCfrlJRJXbBi8=
golang.org/x/oauth2 v0.17.0 h1:6m3ZPmLEFdVxKKWnKq4VqZ60gutO35zm+zrAHVmHyDQ=
golang.org/x/oauth2 v0.17.0/go.mod h1:OzPDGQiuQMguemayvdylqddI7qcD9lnSDb+1FiwQ5HA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -516,8 +516,8 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ=
golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
4 changes: 2 additions & 2 deletions internal/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type BuildFlags struct {
}

// Build an image from source code
func Build(logger logging.Logger, cfg config.Config, packClient PackClient) *cobra.Command {
func Build(logger logging.Logger, cfg config.Config, packClient PackClient, imagePullPolicyHandler image.ImagePullPolicyHandler) *cobra.Command {
var flags BuildFlags

cmd := &cobra.Command{
Expand Down Expand Up @@ -128,7 +128,7 @@ func Build(logger logging.Logger, cfg config.Config, packClient PackClient) *cob
if stringPolicy == "" {
stringPolicy = cfg.PullPolicy
}
pullPolicy, err := image.ParsePullPolicy(stringPolicy)
pullPolicy, err := imagePullPolicyHandler.ParsePullPolicy(stringPolicy)
if err != nil {
return errors.Wrapf(err, "parsing pull policy %s", flags.Policy)
}
Expand Down
27 changes: 15 additions & 12 deletions internal/commands/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/buildpacks/pack/pkg/image"
"github.com/buildpacks/pack/pkg/logging"
projectTypes "github.com/buildpacks/pack/pkg/project/types"
fetcher_mock "github.com/buildpacks/pack/pkg/testmocks"
h "github.com/buildpacks/pack/testhelpers"
)

Expand All @@ -38,21 +39,23 @@ func TestBuildCommand(t *testing.T) {

func testBuildCommand(t *testing.T, when spec.G, it spec.S) {
var (
command *cobra.Command
logger *logging.LogWithWriters
outBuf bytes.Buffer
mockController *gomock.Controller
mockClient *testmocks.MockPackClient
cfg config.Config
command *cobra.Command
logger *logging.LogWithWriters
outBuf bytes.Buffer
mockController *gomock.Controller
mockClient *testmocks.MockPackClient
cfg config.Config
imagePullPolicyHandler image.ImagePullPolicyHandler
)

it.Before(func() {
logger = logging.NewLogWithWriters(&outBuf, &outBuf)
cfg = config.Config{}
mockController = gomock.NewController(t)
mockClient = testmocks.NewMockPackClient(mockController)
imagePullPolicyHandler = fetcher_mock.NewMockPullPolicyManager(logger)

command = commands.Build(logger, cfg, mockClient)
command = commands.Build(logger, cfg, mockClient, imagePullPolicyHandler)
})

when("#BuildCommand", func() {
Expand Down Expand Up @@ -97,7 +100,7 @@ func testBuildCommand(t *testing.T, when spec.G, it spec.S) {
Return(nil)

cfg := config.Config{TrustedBuilders: []config.TrustedBuilder{{Name: "my-builder"}}}
command = commands.Build(logger, cfg, mockClient)
command = commands.Build(logger, cfg, mockClient, imagePullPolicyHandler)
})
it("sets the trust builder option", func() {
logger.WantVerbose(true)
Expand Down Expand Up @@ -167,7 +170,7 @@ func testBuildCommand(t *testing.T, when spec.G, it spec.S) {
Return(nil)

cfg := config.Config{PullPolicy: "if-not-present"}
command := commands.Build(logger, cfg, mockClient)
command := commands.Build(logger, cfg, mockClient, imagePullPolicyHandler)

logger.WantVerbose(true)
command.SetArgs([]string{"image", "--builder", "my-builder", "--pull-policy", "never"})
Expand All @@ -193,7 +196,7 @@ func testBuildCommand(t *testing.T, when spec.G, it spec.S) {
Return(nil)

cfg := config.Config{PullPolicy: "never"}
command := commands.Build(logger, cfg, mockClient)
command := commands.Build(logger, cfg, mockClient, imagePullPolicyHandler)

logger.WantVerbose(true)
command.SetArgs([]string{"image", "--builder", "my-builder"})
Expand Down Expand Up @@ -455,7 +458,7 @@ func testBuildCommand(t *testing.T, when spec.G, it spec.S) {
Return(nil)

cfg := config.Config{LifecycleImage: "some-lifecycle-image"}
command := commands.Build(logger, cfg, mockClient)
command := commands.Build(logger, cfg, mockClient, imagePullPolicyHandler)

logger.WantVerbose(true)
command.SetArgs([]string{"image", "--builder", "my-builder"})
Expand Down Expand Up @@ -895,7 +898,7 @@ builder = "my-builder"
Experimental: true,
LayoutRepositoryDir: layoutDir,
}
command = commands.Build(logger, cfg, mockClient)
command = commands.Build(logger, cfg, mockClient, imagePullPolicyHandler)
})

when("path to save the image is provided", func() {
Expand Down
5 changes: 3 additions & 2 deletions internal/commands/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ import (

builderwriter "github.com/buildpacks/pack/internal/builder/writer"
"github.com/buildpacks/pack/internal/config"
"github.com/buildpacks/pack/pkg/image"
"github.com/buildpacks/pack/pkg/logging"
)

func NewBuilderCommand(logger logging.Logger, cfg config.Config, client PackClient) *cobra.Command {
func NewBuilderCommand(logger logging.Logger, cfg config.Config, client PackClient, imagePullPolicyHandler image.ImagePullPolicyHandler) *cobra.Command {
cmd := &cobra.Command{
Use: "builder",
Aliases: []string{"builders"},
Short: "Interact with builders",
RunE: nil,
}

cmd.AddCommand(BuilderCreate(logger, cfg, client))
cmd.AddCommand(BuilderCreate(logger, cfg, client, imagePullPolicyHandler))
cmd.AddCommand(BuilderInspect(logger, cfg, client, builderwriter.NewFactory()))
cmd.AddCommand(BuilderSuggest(logger, client))
AddHelpFlag(cmd, "builder")
Expand Down
4 changes: 2 additions & 2 deletions internal/commands/builder_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type BuilderCreateFlags struct {
}

// CreateBuilder creates a builder image, based on a builder config
func BuilderCreate(logger logging.Logger, cfg config.Config, pack PackClient) *cobra.Command {
func BuilderCreate(logger logging.Logger, cfg config.Config, pack PackClient, imagePullPolicyHandler image.ImagePullPolicyHandler) *cobra.Command {
var flags BuilderCreateFlags

cmd := &cobra.Command{
Expand All @@ -50,7 +50,7 @@ Creating a custom builder allows you to control what buildpacks are used and wha
if stringPolicy == "" {
stringPolicy = cfg.PullPolicy
}
pullPolicy, err := image.ParsePullPolicy(stringPolicy)
pullPolicy, err := imagePullPolicyHandler.ParsePullPolicy(stringPolicy)
if err != nil {
return errors.Wrapf(err, "parsing pull policy %s", flags.Policy)
}
Expand Down
24 changes: 14 additions & 10 deletions internal/commands/builder_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import (
"github.com/buildpacks/pack/internal/commands"
"github.com/buildpacks/pack/internal/commands/testmocks"
"github.com/buildpacks/pack/internal/config"
"github.com/buildpacks/pack/pkg/image"
"github.com/buildpacks/pack/pkg/logging"
fetcher_mock "github.com/buildpacks/pack/pkg/testmocks"
h "github.com/buildpacks/pack/testhelpers"
)

Expand Down Expand Up @@ -160,14 +162,15 @@ func TestCreateCommand(t *testing.T) {

func testCreateCommand(t *testing.T, when spec.G, it spec.S) {
var (
command *cobra.Command
logger logging.Logger
outBuf bytes.Buffer
mockController *gomock.Controller
mockClient *testmocks.MockPackClient
tmpDir string
builderConfigPath string
cfg config.Config
command *cobra.Command
logger logging.Logger
outBuf bytes.Buffer
mockController *gomock.Controller
mockClient *testmocks.MockPackClient
tmpDir string
builderConfigPath string
cfg config.Config
imagePullPolicyHandler image.ImagePullPolicyHandler
)

it.Before(func() {
Expand All @@ -180,7 +183,8 @@ func testCreateCommand(t *testing.T, when spec.G, it spec.S) {
mockController = gomock.NewController(t)
mockClient = testmocks.NewMockPackClient(mockController)
logger = logging.NewLogWithWriters(&outBuf, &outBuf)
command = commands.BuilderCreate(logger, cfg, mockClient)
imagePullPolicyHandler = fetcher_mock.NewMockPullPolicyManager(logger)
command = commands.BuilderCreate(logger, cfg, mockClient, imagePullPolicyHandler)
})

it.After(func() {
Expand Down Expand Up @@ -218,7 +222,7 @@ func testCreateCommand(t *testing.T, when spec.G, it spec.S) {
when("configured pull policy is invalid", func() {
it("errors when config set with unknown policy", func() {
cfg = config.Config{PullPolicy: "unknown-policy"}
command = commands.BuilderCreate(logger, cfg, mockClient)
command = commands.BuilderCreate(logger, cfg, mockClient, imagePullPolicyHandler)
command.SetArgs([]string{
"some/builder",
"--config", builderConfigPath,
Expand Down
12 changes: 8 additions & 4 deletions internal/commands/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
"github.com/buildpacks/pack/internal/commands"
"github.com/buildpacks/pack/internal/commands/testmocks"
"github.com/buildpacks/pack/internal/config"
"github.com/buildpacks/pack/pkg/image"
"github.com/buildpacks/pack/pkg/logging"
fetcher_mock "github.com/buildpacks/pack/pkg/testmocks"
h "github.com/buildpacks/pack/testhelpers"
)

Expand All @@ -22,16 +24,18 @@ func TestBuilderCommand(t *testing.T) {

func testBuilderCommand(t *testing.T, when spec.G, it spec.S) {
var (
cmd *cobra.Command
logger logging.Logger
outBuf bytes.Buffer
cmd *cobra.Command
logger logging.Logger
outBuf bytes.Buffer
imagePullPolicyHandler image.ImagePullPolicyHandler
)

it.Before(func() {
logger = logging.NewLogWithWriters(&outBuf, &outBuf)
imagePullPolicyHandler = fetcher_mock.NewMockPullPolicyManager(logger)
mockController := gomock.NewController(t)
mockClient := testmocks.NewMockPackClient(mockController)
cmd = commands.NewBuilderCommand(logger, config.Config{}, mockClient)
cmd = commands.NewBuilderCommand(logger, config.Config{}, mockClient, imagePullPolicyHandler)
cmd.SetOut(logging.GetWriterForLevel(logger, logging.InfoLevel))
})

Expand Down
Loading
Loading