diff --git a/cmd/werf/build/main.go b/cmd/werf/build/main.go index 070de6990b..1c815add5a 100644 --- a/cmd/werf/build/main.go +++ b/cmd/werf/build/main.go @@ -99,8 +99,10 @@ func NewCmd(ctx context.Context) *cobra.Command { common.SetupKubeConfigBase64(&commonCmdData, cmd) common.SetupKubeContext(&commonCmdData, cmd) - common.SetupReportPath(&commonCmdData, cmd) - common.SetupReportFormat(&commonCmdData, cmd) + common.SetupDeprecatedReportPath(&commonCmdData, cmd) + common.SetupDeprecatedReportFormat(&commonCmdData, cmd) + common.SetupBuildReportPath(&commonCmdData, cmd) + common.SetupBuildReportFormat(&commonCmdData, cmd) common.SetupAddCustomTag(&commonCmdData, cmd) common.SetupVirtualMerge(&commonCmdData, cmd) @@ -236,7 +238,7 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken storageManager := manager.NewStorageManager(projectName, stagesStorage, finalStagesStorage, secondaryStagesStorageList, cacheStagesStorageList, storageLockManager) - buildOptions, err := common.GetBuildOptions(&commonCmdData, giterminismManager, werfConfig) + buildOptions, err := common.GetBuildOptions(ctx, &commonCmdData, giterminismManager, werfConfig) if err != nil { return err } diff --git a/cmd/werf/bundle/apply/apply.go b/cmd/werf/bundle/apply/apply.go index 3b83f05cf3..089bd2a3bb 100644 --- a/cmd/werf/bundle/apply/apply.go +++ b/cmd/werf/bundle/apply/apply.go @@ -87,6 +87,8 @@ func NewCmd(ctx context.Context) *cobra.Command { common.SetupSecretValues(&commonCmdData, cmd) common.SetupIgnoreSecretKey(&commonCmdData, cmd) + common.SetupDeployReportPath(&commonCmdData, cmd) + common.SetupKubeConfig(&commonCmdData, cmd) common.SetupKubeConfigBase64(&commonCmdData, cmd) common.SetupKubeContext(&commonCmdData, cmd) @@ -227,13 +229,14 @@ func runApply(ctx context.Context) error { Values: common.GetSet(&commonCmdData), FileValues: common.GetSetFile(&commonCmdData), }, - CreateNamespace: common.NewBool(true), - Install: common.NewBool(true), - Wait: common.NewBool(true), - Atomic: common.NewBool(cmdData.AutoRollback), - Timeout: common.NewDuration(time.Duration(cmdData.Timeout) * time.Second), - IgnorePending: common.NewBool(true), - CleanupOnFail: common.NewBool(true), + CreateNamespace: common.NewBool(true), + Install: common.NewBool(true), + Wait: common.NewBool(true), + Atomic: common.NewBool(cmdData.AutoRollback), + Timeout: common.NewDuration(time.Duration(cmdData.Timeout) * time.Second), + IgnorePending: common.NewBool(true), + CleanupOnFail: common.NewBool(true), + DeployReportPath: commonCmdData.DeployReportPath, }) return command_helpers.LockReleaseWrapper(ctx, releaseName, lockManager, func() error { diff --git a/cmd/werf/bundle/export/export.go b/cmd/werf/bundle/export/export.go index a03920e659..752cca5d2e 100644 --- a/cmd/werf/bundle/export/export.go +++ b/cmd/werf/bundle/export/export.go @@ -126,8 +126,10 @@ func NewCmd(ctx context.Context) *cobra.Command { commonCmdData.SetupDisableDefaultValues(cmd) commonCmdData.SetupSkipDependenciesRepoRefresh(cmd) - common.SetupReportPath(&commonCmdData, cmd) - common.SetupReportFormat(&commonCmdData, cmd) + common.SetupDeprecatedReportPath(&commonCmdData, cmd) + common.SetupDeprecatedReportFormat(&commonCmdData, cmd) + common.SetupBuildReportPath(&commonCmdData, cmd) + common.SetupBuildReportFormat(&commonCmdData, cmd) common.SetupUseCustomTag(&commonCmdData, cmd) common.SetupVirtualMerge(&commonCmdData, cmd) @@ -239,7 +241,7 @@ func runExport(ctx context.Context, imagesToProcess build.ImagesToProcess) error return err } - buildOptions, err := common.GetBuildOptions(&commonCmdData, giterminismManager, werfConfig) + buildOptions, err := common.GetBuildOptions(ctx, &commonCmdData, giterminismManager, werfConfig) if err != nil { return err } diff --git a/cmd/werf/bundle/publish/publish.go b/cmd/werf/bundle/publish/publish.go index e726176398..4b7751b280 100644 --- a/cmd/werf/bundle/publish/publish.go +++ b/cmd/werf/bundle/publish/publish.go @@ -115,8 +115,10 @@ func NewCmd(ctx context.Context) *cobra.Command { commonCmdData.SetupDisableDefaultValues(cmd) commonCmdData.SetupSkipDependenciesRepoRefresh(cmd) - common.SetupReportPath(&commonCmdData, cmd) - common.SetupReportFormat(&commonCmdData, cmd) + common.SetupDeprecatedReportPath(&commonCmdData, cmd) + common.SetupDeprecatedReportFormat(&commonCmdData, cmd) + common.SetupBuildReportPath(&commonCmdData, cmd) + common.SetupBuildReportFormat(&commonCmdData, cmd) common.SetupUseCustomTag(&commonCmdData, cmd) common.SetupAddCustomTag(&commonCmdData, cmd) @@ -238,7 +240,7 @@ func runPublish(ctx context.Context, imagesToProcess build.ImagesToProcess) erro return err } - buildOptions, err := common.GetBuildOptions(&commonCmdData, giterminismManager, werfConfig) + buildOptions, err := common.GetBuildOptions(ctx, &commonCmdData, giterminismManager, werfConfig) if err != nil { return err } diff --git a/cmd/werf/common/cmd_data.go b/cmd/werf/common/cmd_data.go index f30557da4c..40525f3a46 100644 --- a/cmd/werf/common/cmd_data.go +++ b/cmd/werf/common/cmd_data.go @@ -91,8 +91,11 @@ type CmdData struct { LogProjectDir *bool LogTerminalWidth *int64 - ReportPath *string - ReportFormat *string + DeprecatedReportPath *string + DeprecatedReportFormat *string + BuildReportPath *string + BuildReportFormat *string + DeployReportPath *string VirtualMerge *bool diff --git a/cmd/werf/common/common.go b/cmd/werf/common/common.go index d8360f1d58..3f1afe3f8a 100644 --- a/cmd/werf/common/common.go +++ b/cmd/werf/common/common.go @@ -133,20 +133,57 @@ Can be specified with $WERF_SSH_KEY_* (e.g. $WERF_SSH_KEY_REPO=~/.ssh/repo_rsa, Defaults to $WERF_SSH_KEY_*, system ssh-agent or ~/.ssh/{id_rsa|id_dsa}, see https://werf.io/documentation/reference/toolbox/ssh.html`) } -func SetupReportPath(cmdData *CmdData, cmd *cobra.Command) { - cmdData.ReportPath = new(string) - cmd.Flags().StringVarP(cmdData.ReportPath, "report-path", "", os.Getenv("WERF_REPORT_PATH"), "Report save path ($WERF_REPORT_PATH by default)") +func SetupDeprecatedReportPath(cmdData *CmdData, cmd *cobra.Command) { + cmdData.DeprecatedReportPath = new(string) + cmd.Flags().StringVarP(cmdData.DeprecatedReportPath, "report-path", "", os.Getenv("WERF_REPORT_PATH"), "DEPRECATED: use --build-report-path.\nReport save path ($WERF_REPORT_PATH by default)") } -func SetupReportFormat(cmdData *CmdData, cmd *cobra.Command) { - cmdData.ReportFormat = new(string) +func SetupDeprecatedReportFormat(cmdData *CmdData, cmd *cobra.Command) { + cmdData.DeprecatedReportFormat = new(string) - defaultValue := os.Getenv("WERF_REPORT_FORMAT") - if defaultValue == "" { - defaultValue = string(build.ReportJSON) + cmd.Flags().StringVarP(cmdData.DeprecatedReportFormat, "report-format", "", os.Getenv("WERF_REPORT_FORMAT"), fmt.Sprintf(`DEPRECATED: use --build-report-format. +Report format: %[1]s or %[2]s (%[1]s or $WERF_REPORT_FORMAT by default) %[1]s: + { + "Images": { + "": { + "WerfImageName": "", + "DockerRepo": "", + "DockerTag": "" + "DockerImageName": ":", + "DockerImageID": "", + "DockerImageDigest": "", + }, + ... + } } +%[2]s: + WERF__DOCKER_IMAGE_NAME=: + ... + is werf image name from werf.yaml modified according to the following rules: +- all characters are uppercase (app -> APP); +- charset /- is replaced with _ (DEV/APP-FRONTEND -> DEV_APP_FRONTEND)`, string(build.ReportJSON), string(build.ReportEnvFile))) +} + +func GetDeprecatedReportFormat(cmdData *CmdData) (build.ReportFormat, error) { + switch format := build.ReportFormat(*cmdData.DeprecatedReportFormat); format { + case build.ReportJSON, build.ReportEnvFile: + return format, nil + case "": + return build.ReportJSON, nil + default: + return "", fmt.Errorf("bad --report-format given %q, expected: \"%s\"", format, strings.Join([]string{string(build.ReportJSON), string(build.ReportEnvFile)}, "\", \"")) + } +} + +func SetupBuildReportPath(cmdData *CmdData, cmd *cobra.Command) { + cmdData.BuildReportPath = new(string) + cmd.Flags().StringVarP(cmdData.BuildReportPath, "build-report-path", "", os.Getenv("WERF_BUILD_REPORT_PATH"), "Report save path ($WERF_BUILD_REPORT_PATH by default)") +} - cmd.Flags().StringVarP(cmdData.ReportFormat, "report-format", "", defaultValue, fmt.Sprintf(`Report format: %[1]s or %[2]s (%[1]s or $WERF_REPORT_FORMAT by default) +func SetupBuildReportFormat(cmdData *CmdData, cmd *cobra.Command) { + cmdData.BuildReportFormat = new(string) + + cmd.Flags().StringVarP(cmdData.BuildReportFormat, "build-report-format", "", os.Getenv("WERF_BUILD_REPORT_FORMAT"), fmt.Sprintf(`Report format: %[1]s or %[2]s (%[1]s or $WERF_BUILD_REPORT_FORMAT by default) %[1]s: { "Images": { @@ -169,15 +206,22 @@ func SetupReportFormat(cmdData *CmdData, cmd *cobra.Command) { - charset /- is replaced with _ (DEV/APP-FRONTEND -> DEV_APP_FRONTEND)`, string(build.ReportJSON), string(build.ReportEnvFile))) } -func GetReportFormat(cmdData *CmdData) (build.ReportFormat, error) { - switch format := build.ReportFormat(*cmdData.ReportFormat); format { +func GetBuildReportFormat(cmdData *CmdData) (build.ReportFormat, error) { + switch format := build.ReportFormat(*cmdData.BuildReportFormat); format { case build.ReportJSON, build.ReportEnvFile: return format, nil + case "": + return build.ReportJSON, nil default: - return "", fmt.Errorf("bad --report-format given %q, expected: \"%s\"", format, strings.Join([]string{string(build.ReportJSON), string(build.ReportEnvFile)}, "\", \"")) + return "", fmt.Errorf("bad --build-report-format given %q, expected: \"%s\"", format, strings.Join([]string{string(build.ReportJSON), string(build.ReportEnvFile)}, "\", \"")) } } +func SetupDeployReportPath(cmdData *CmdData, cmd *cobra.Command) { + cmdData.DeployReportPath = new(string) + cmd.Flags().StringVarP(cmdData.DeployReportPath, "deploy-report-path", "", os.Getenv("WERF_DEPLOY_REPORT_PATH"), "Deploy report save path ($WERF_DEPLOY_REPORT_PATH by default)") +} + func SetupWithoutKube(cmdData *CmdData, cmd *cobra.Command) { cmdData.WithoutKube = new(bool) cmd.Flags().BoolVarP(cmdData.WithoutKube, "without-kube", "", util.GetBoolEnvironmentDefaultFalse("WERF_WITHOUT_KUBE"), "Do not skip deployed Kubernetes images (default $WERF_WITHOUT_KUBE)") diff --git a/cmd/werf/common/conveyor_options.go b/cmd/werf/common/conveyor_options.go index 8040318b67..8e83a6bf3f 100644 --- a/cmd/werf/common/conveyor_options.go +++ b/cmd/werf/common/conveyor_options.go @@ -2,10 +2,12 @@ package common import ( "bytes" + "context" "fmt" "strings" "text/template" + "github.com/werf/logboek" "github.com/werf/werf/pkg/build" "github.com/werf/werf/pkg/build/stage" "github.com/werf/werf/pkg/config" @@ -49,15 +51,38 @@ func GetShouldBeBuiltOptions(commonCmdData *CmdData, giterminismManager gitermin return options, nil } -func GetBuildOptions(commonCmdData *CmdData, giterminismManager giterminism_manager.Interface, werfConfig *config.WerfConfig) (buildOptions build.BuildOptions, err error) { +func GetBuildOptions(ctx context.Context, commonCmdData *CmdData, giterminismManager giterminism_manager.Interface, werfConfig *config.WerfConfig) (buildOptions build.BuildOptions, err error) { introspectOptions, err := GetIntrospectOptions(commonCmdData, werfConfig) if err != nil { return buildOptions, err } - reportFormat, err := GetReportFormat(commonCmdData) - if err != nil { - return buildOptions, err + var buildReportPath string + if commonCmdData.BuildReportPath != nil && *commonCmdData.BuildReportPath != "" && commonCmdData.DeprecatedReportPath != nil && *commonCmdData.DeprecatedReportPath != "" { + return buildOptions, fmt.Errorf("you can't use both --report-path ($WERF_REPORT_PATH) and --build-report-path ($WERF_BUILD_REPORT_PATH), use only the latter instead") + } else if commonCmdData.BuildReportPath != nil && *commonCmdData.BuildReportPath != "" { + buildReportPath = *commonCmdData.BuildReportPath + } else if commonCmdData.DeprecatedReportPath != nil && *commonCmdData.DeprecatedReportPath != "" { + logboek.Context(ctx).Warn().LogF("DEPRECATED: use --build-report-path ($WERF_BUILD_REPORT_PATH) instead of --report-path ($WERF_REPORT_PATH)\n") + buildReportPath = *commonCmdData.DeprecatedReportPath + } + + var buildReportFormat build.ReportFormat + if commonCmdData.BuildReportFormat != nil && *commonCmdData.BuildReportFormat != "" && commonCmdData.DeprecatedReportFormat != nil && *commonCmdData.DeprecatedReportFormat != "" { + return buildOptions, fmt.Errorf("you can't use both --report-format ($WERF_REPORT_FORMAT) and --build-report-format ($WERF_BUILD_REPORT_FORMAT), use only the latter instead") + } else if commonCmdData.BuildReportFormat != nil && *commonCmdData.BuildReportFormat != "" { + buildReportFormat, err = GetBuildReportFormat(commonCmdData) + if err != nil { + return buildOptions, fmt.Errorf("error getting build report format: %w", err) + } + } else if commonCmdData.DeprecatedReportFormat != nil && *commonCmdData.DeprecatedReportFormat != "" { + logboek.Context(ctx).Warn().LogF("DEPRECATED: use --build-report-format ($WERF_BUILD_REPORT_FORMAT) instead of --report-format ($WERF_REPORT_FORMAT)\n") + buildReportFormat, err = GetDeprecatedReportFormat(commonCmdData) + if err != nil { + return buildOptions, fmt.Errorf("error getting report format: %w", err) + } + } else { + buildReportFormat = build.ReportJSON } customTagFuncList, err := getCustomTagFuncList(getCustomTagOptionValues(commonCmdData), commonCmdData, giterminismManager, werfConfig) @@ -73,8 +98,8 @@ func GetBuildOptions(commonCmdData *CmdData, giterminismManager giterminism_mana IntrospectBeforeError: *commonCmdData.IntrospectBeforeError, }, IntrospectOptions: introspectOptions, - ReportPath: *commonCmdData.ReportPath, - ReportFormat: reportFormat, + ReportPath: buildReportPath, + ReportFormat: buildReportFormat, } return buildOptions, nil diff --git a/cmd/werf/converge/converge.go b/cmd/werf/converge/converge.go index 28e0d1cac3..a392bf0aab 100644 --- a/cmd/werf/converge/converge.go +++ b/cmd/werf/converge/converge.go @@ -159,8 +159,11 @@ werf converge --repo registry.mydomain.com/web --env production`, commonCmdData.SetupDisableDefaultSecretValues(cmd) commonCmdData.SetupSkipDependenciesRepoRefresh(cmd) - common.SetupReportPath(&commonCmdData, cmd) - common.SetupReportFormat(&commonCmdData, cmd) + common.SetupDeprecatedReportPath(&commonCmdData, cmd) + common.SetupDeprecatedReportFormat(&commonCmdData, cmd) + common.SetupBuildReportPath(&commonCmdData, cmd) + common.SetupBuildReportFormat(&commonCmdData, cmd) + common.SetupDeployReportPath(&commonCmdData, cmd) common.SetupUseCustomTag(&commonCmdData, cmd) common.SetupAddCustomTag(&commonCmdData, cmd) @@ -287,7 +290,7 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken } defer tmp_manager.ReleaseProjectDir(projectTmpDir) - buildOptions, err := common.GetBuildOptions(&commonCmdData, giterminismManager, werfConfig) + buildOptions, err := common.GetBuildOptions(ctx, &commonCmdData, giterminismManager, werfConfig) if err != nil { return err } @@ -483,6 +486,7 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken Timeout: common.NewDuration(time.Duration(cmdData.Timeout) * time.Second), IgnorePending: common.NewBool(true), CleanupOnFail: common.NewBool(true), + DeployReportPath: commonCmdData.DeployReportPath, }) return command_helpers.LockReleaseWrapper(ctx, releaseName, lockManager, func() error { diff --git a/cmd/werf/render/render.go b/cmd/werf/render/render.go index 17583cd8f4..dd0bc85511 100644 --- a/cmd/werf/render/render.go +++ b/cmd/werf/render/render.go @@ -137,8 +137,10 @@ func NewCmd(ctx context.Context) *cobra.Command { commonCmdData.SetupDisableDefaultSecretValues(cmd) commonCmdData.SetupSkipDependenciesRepoRefresh(cmd) - common.SetupReportPath(&commonCmdData, cmd) - common.SetupReportFormat(&commonCmdData, cmd) + common.SetupDeprecatedReportPath(&commonCmdData, cmd) + common.SetupDeprecatedReportFormat(&commonCmdData, cmd) + common.SetupBuildReportPath(&commonCmdData, cmd) + common.SetupBuildReportFormat(&commonCmdData, cmd) common.SetupUseCustomTag(&commonCmdData, cmd) common.SetupVirtualMerge(&commonCmdData, cmd) @@ -253,7 +255,7 @@ func runRender(ctx context.Context, imagesToProcess build.ImagesToProcess) error return err } - buildOptions, err := common.GetBuildOptions(&commonCmdData, giterminismManager, werfConfig) + buildOptions, err := common.GetBuildOptions(ctx, &commonCmdData, giterminismManager, werfConfig) if err != nil { return err } diff --git a/go.mod b/go.mod index b082baeb4e..863876e262 100644 --- a/go.mod +++ b/go.mod @@ -317,4 +317,4 @@ replace github.com/deislabs/oras => github.com/werf/third-party-oras v0.9.1-0.20 replace github.com/go-git/go-git/v5 => github.com/ZauberNerd/go-git/v5 v5.4.3-0.20220315170230-29ec1bc1e5db -replace helm.sh/helm/v3 => github.com/werf/3p-helm/v3 v3.0.0-20221017175338-b2224bd154a3 +replace helm.sh/helm/v3 => github.com/werf/3p-helm/v3 v3.0.0-20230210095639-edbba2a383bc diff --git a/go.sum b/go.sum index 23078186dd..05a7502cb8 100644 --- a/go.sum +++ b/go.sum @@ -2050,8 +2050,8 @@ github.com/vmware/govmomi v0.20.3/go.mod h1:URlwyTFZX72RmxtxuaFL2Uj3fD1JTvZdx59b github.com/weppos/publicsuffix-go v0.4.0/go.mod h1:z3LCPQ38eedDQSwmsSRW4Y7t2L8Ln16JPQ02lHAdn5k= github.com/weppos/publicsuffix-go v0.5.0 h1:rutRtjBJViU/YjcI5d80t4JAVvDltS6bciJg2K1HrLU= github.com/weppos/publicsuffix-go v0.5.0/go.mod h1:z3LCPQ38eedDQSwmsSRW4Y7t2L8Ln16JPQ02lHAdn5k= -github.com/werf/3p-helm/v3 v3.0.0-20221017175338-b2224bd154a3 h1:ZfkmCgZQip5Uj2h2e2T1625EjSJe/coSf+okdmT9dnI= -github.com/werf/3p-helm/v3 v3.0.0-20221017175338-b2224bd154a3/go.mod h1:NxtE2KObf2PrzDl6SIamPFPKyAqWi10iWuvKlQn/Yao= +github.com/werf/3p-helm/v3 v3.0.0-20230210095639-edbba2a383bc h1:+ZZ1eJGVQ73Xm2Msuz6/XQdcIP+Cdi0Tui4W3/ATPYY= +github.com/werf/3p-helm/v3 v3.0.0-20230210095639-edbba2a383bc/go.mod h1:NxtE2KObf2PrzDl6SIamPFPKyAqWi10iWuvKlQn/Yao= github.com/werf/copy-recurse v0.2.4 h1:kEyGUKhgS8WdEOjInNQKgk4lqPWzP2AgR27F3dcGsVc= github.com/werf/copy-recurse v0.2.4/go.mod h1:KVHSQ90p19xflWW0B7BJhLBwmSbEtuxIaBnjlUYRPhk= github.com/werf/helm v0.0.0-20210202111118-81e74d46da0f h1:81YscYTF9mmTf0ULOsCmm42YWQp+qWDzWi1HjWniZrg=