2
0
Эх сурвалжийг харах

pull image before build by default (#4524)

ianedwards 2 жил өмнө
parent
commit
a77adaa8ea

+ 12 - 0
cli/cmd/commands/app.go

@@ -151,6 +151,11 @@ buildpacks using the --builder and --attach-buildpacks flags:
 		"",
 		"set the image tag to use for the build",
 	)
+	appBuildCommand.PersistentFlags().Bool(
+		flags.App_NoPull,
+		false,
+		"do not pull the previous image before building",
+	)
 	appCmd.AddCommand(appBuildCommand)
 
 	appPushCommand := &cobra.Command{
@@ -423,6 +428,12 @@ func appBuild(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client
 		return fmt.Errorf("error getting tag: %w", err)
 	}
 
+	noPull, err := cmd.Flags().GetBool(flags.App_NoPull)
+	if err != nil {
+		return fmt.Errorf("could not retrieve no-pull flag from command")
+	}
+	pullBeforeBuild := !noPull
+
 	err = v2.AppBuild(ctx, v2.AppBuildInput{
 		CLIConfig:            cliConfig,
 		Client:               client,
@@ -435,6 +446,7 @@ func appBuild(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client
 		BuildContext:         buildValues.BuildContext,
 		ImageTag:             tag,
 		PatchOperations:      patchOperations,
+		PullImageBeforeBuild: pullBeforeBuild,
 	})
 	if err != nil {
 		return fmt.Errorf("failed to build app: %w", err)

+ 9 - 1
cli/cmd/commands/apply.go

@@ -124,6 +124,8 @@ applying a configuration:
 		"set this to wait and be notified when an apply is successful, otherwise time out",
 	)
 	applyCmd.PersistentFlags().Bool(flags.App_NoBuild, false, "apply configuration without building a new image")
+	applyCmd.PersistentFlags().Bool(flags.App_NoPull, false, "do not pull the previous image before building")
+	applyCmd.PersistentFlags().MarkDeprecated("pull-before-build", "previous image is pulled by default, use --no-pull to disable") //nolint:errcheck,gosec
 
 	flags.UseAppBuildFlags(applyCmd)
 	flags.UseAppImageFlags(applyCmd)
@@ -172,6 +174,12 @@ func apply(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client ap
 		return fmt.Errorf("could not retrieve no-build flag from command")
 	}
 
+	noPull, err := cmd.Flags().GetBool(flags.App_NoPull)
+	if err != nil {
+		return fmt.Errorf("could not retrieve no-pull flag from command")
+	}
+	pullBeforeBuild := !noPull
+
 	if project.ValidateApplyV2 {
 		if previewApply && !project.PreviewEnvsEnabled {
 			return fmt.Errorf("preview environments are not enabled for this project. Please contact support@porter.run")
@@ -196,7 +204,7 @@ func apply(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client ap
 			ImageTagOverride:            imageValues.Tag,
 			PreviewApply:                previewApply,
 			WaitForSuccessfulDeployment: appWait,
-			PullImageBeforeBuild:        pullImageBeforeBuild,
+			PullImageBeforeBuild:        pullBeforeBuild,
 			WithPredeploy:               predeploy,
 			Exact:                       exact,
 			PatchOperations:             patchOperations,

+ 2 - 0
cli/cmd/commands/flags/app_build.go

@@ -19,6 +19,8 @@ const (
 	App_BuildContext = "build-context"
 	// App_NoBuild is the key for the no build flag
 	App_NoBuild = "no-build"
+	// App_NoPull is the key for the no pull flag
+	App_NoPull = "no-pull"
 )
 
 // UseAppBuildFlags adds build flags to the given command

+ 9 - 6
cli/cmd/v2/app_build.go

@@ -37,6 +37,8 @@ type AppBuildInput struct {
 	ImageTag string
 	// PatchOperations is the set of patch operations to apply to the app build
 	PatchOperations []v2.PatchOperation
+	// PullImageBeforeBuild is a flag indicating whether to pull the previous image before building
+	PullImageBeforeBuild bool
 }
 
 // AppBuild builds an app using a combination of the provided flag values and build settings from the latest app revision
@@ -95,12 +97,13 @@ func AppBuild(ctx context.Context, inp AppBuildInput) error {
 	}
 
 	buildInput, err := buildInputFromBuildSettings(buildInputFromBuildSettingsInput{
-		projectID: cliConf.Project,
-		appName:   inp.AppName,
-		commitSHA: tagForBuild,
-		image:     buildSettings.Image,
-		build:     buildSettings.Build,
-		buildEnv:  buildEnvVariables,
+		projectID:            cliConf.Project,
+		appName:              inp.AppName,
+		commitSHA:            tagForBuild,
+		image:                buildSettings.Image,
+		build:                buildSettings.Build,
+		buildEnv:             buildEnvVariables,
+		pullImageBeforeBuild: inp.PullImageBeforeBuild,
 	})
 	if err != nil {
 		return fmt.Errorf("error creating build input from build settings: %w", err)