Skip to content

Commit

Permalink
feat(v2): remove deprecated --report-path and --report-format
Browse files Browse the repository at this point in the history
Signed-off-by: Ilya Lesikov <ilya@lesikov.com>
  • Loading branch information
ilya-lesikov committed Apr 24, 2024
1 parent bf9d221 commit 4f26904
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 90 deletions.
2 changes: 0 additions & 2 deletions cmd/werf/build/main.go
Expand Up @@ -102,8 +102,6 @@ func NewCmd(ctx context.Context) *cobra.Command {

common.SetupSaveBuildReport(&commonCmdData, cmd)
common.SetupBuildReportPath(&commonCmdData, cmd)
common.SetupDeprecatedReportPath(&commonCmdData, cmd)
common.SetupDeprecatedReportFormat(&commonCmdData, cmd)

common.SetupAddCustomTag(&commonCmdData, cmd)
common.SetupVirtualMerge(&commonCmdData, cmd)
Expand Down
2 changes: 0 additions & 2 deletions cmd/werf/bundle/publish/publish.go
Expand Up @@ -121,8 +121,6 @@ func NewCmd(ctx context.Context) *cobra.Command {

common.SetupSaveBuildReport(&commonCmdData, cmd)
common.SetupBuildReportPath(&commonCmdData, cmd)
common.SetupDeprecatedReportPath(&commonCmdData, cmd)
common.SetupDeprecatedReportFormat(&commonCmdData, cmd)

common.SetupUseCustomTag(&commonCmdData, cmd)
common.SetupAddCustomTag(&commonCmdData, cmd)
Expand Down
3 changes: 0 additions & 3 deletions cmd/werf/common/cmd_data.go
Expand Up @@ -97,9 +97,6 @@ type CmdData struct {
LogProjectDir *bool
LogTerminalWidth *int64

DeprecatedReportPath *string
DeprecatedReportFormat *string

SaveBuildReport *bool
BuildReportPath *string

Expand Down
61 changes: 0 additions & 61 deletions cmd/werf/common/common.go
Expand Up @@ -151,67 +151,6 @@ 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}`)
}

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 --save-build-report with optional --build-report-path.\nReport save path ($WERF_REPORT_PATH by default)")
}

func SetupDeprecatedReportFormat(cmdData *CmdData, cmd *cobra.Command) {
cmdData.DeprecatedReportFormat = new(string)

cmd.Flags().StringVarP(cmdData.DeprecatedReportFormat, "report-format", "", os.Getenv("WERF_REPORT_FORMAT"), fmt.Sprintf(`DEPRECATED: use --save-build-report with optional --build-report-path.
Report format: %[1]s or %[2]s (%[1]s or $WERF_REPORT_FORMAT by default) %[1]s:
{
"Images": {
"<WERF_IMAGE_NAME>": {
"WerfImageName": "<WERF_IMAGE_NAME>",
"DockerRepo": "<REPO>",
"DockerTag": "<TAG>"
"DockerImageName": "<REPO>:<TAG>",
"DockerImageID": "<SHA256>",
"DockerImageDigest": "<SHA256>",
},
...
}
}
%[2]s:
WERF_<FORMATTED_WERF_IMAGE_NAME>_DOCKER_IMAGE_NAME=<REPO>:<TAG>
...
<FORMATTED_WERF_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 GetDeprecatedReportPath(ctx context.Context, cmdData *CmdData) string {
if cmdData.DeprecatedReportPath == nil {
return ""
}

logboek.Context(ctx).Warn().LogF("DEPRECATED: use --save-build-report ($WERF_SAVE_BUILD_REPORT) with optional --build-report-path ($WERF_BUILD_REPORT_PATH) instead of --report-path ($WERF_REPORT_PATH)\n")

return *cmdData.DeprecatedReportPath
}

func GetDeprecatedReportFormat(ctx context.Context, cmdData *CmdData) (build.ReportFormat, error) {
if cmdData.DeprecatedReportFormat == nil {
return build.ReportJSON, nil
}

var reportFormat build.ReportFormat
switch reportFormat = build.ReportFormat(*cmdData.DeprecatedReportFormat); reportFormat {
case build.ReportJSON, build.ReportEnvFile:
case "":
defaultFormat := build.ReportJSON
reportFormat = defaultFormat
default:
return "", fmt.Errorf("bad --report-format given %q, expected: \"%s\"", reportFormat, strings.Join([]string{string(build.ReportJSON), string(build.ReportEnvFile)}, "\", \""))
}

logboek.Context(ctx).Warn().LogF("DEPRECATED: use --save-build-report ($WERF_SAVE_BUILD_REPORT) with optional --build-report-path ($WERF_BUILD_REPORT_PATH) instead of --report-format ($WERF_REPORT_FORMAT)\n")

return reportFormat, nil
}

func SetupSaveBuildReport(cmdData *CmdData, cmd *cobra.Command) {
cmdData.SaveBuildReport = new(bool)
cmd.Flags().BoolVarP(cmdData.SaveBuildReport, "save-build-report", "", util.GetBoolEnvironmentDefaultFalse("WERF_SAVE_BUILD_REPORT"), fmt.Sprintf("Save build report (by default $WERF_SAVE_BUILD_REPORT or %t). Its path and format configured with --build-report-path", DefaultSaveBuildReport))
Expand Down
17 changes: 1 addition & 16 deletions cmd/werf/common/conveyor_options.go
Expand Up @@ -100,26 +100,11 @@ func GetBuildOptions(ctx context.Context, commonCmdData *CmdData, werfConfig *co
IntrospectOptions: introspectOptions,
}

usedNewBuildReportOption := (commonCmdData.SaveBuildReport != nil && *commonCmdData.SaveBuildReport == true) || (commonCmdData.BuildReportPath != nil && *commonCmdData.BuildReportPath != "")

usedOldBuildReportOption := (commonCmdData.DeprecatedReportPath != nil && *commonCmdData.DeprecatedReportPath != "") || (commonCmdData.DeprecatedReportFormat != nil && *commonCmdData.DeprecatedReportFormat != "")

if usedNewBuildReportOption && usedOldBuildReportOption {
return buildOptions, fmt.Errorf("you can't use deprecated options --report-path and --report-format along with new options --save-build-report and --build-report-path, use only the latter instead")
}

if usedNewBuildReportOption && GetSaveBuildReport(commonCmdData) {
if GetSaveBuildReport(commonCmdData) {
buildOptions.ReportPath, buildOptions.ReportFormat, err = GetBuildReportPathAndFormat(commonCmdData)
if err != nil {
return buildOptions, fmt.Errorf("getting build report path failed: %w", err)
}
} else if usedOldBuildReportOption {
buildOptions.ReportFormat, err = GetDeprecatedReportFormat(ctx, commonCmdData)
if err != nil {
return buildOptions, fmt.Errorf("getting deprecated build report format failed: %w", err)
}

buildOptions.ReportPath = GetDeprecatedReportPath(ctx, commonCmdData)
}

return buildOptions, nil
Expand Down
2 changes: 0 additions & 2 deletions cmd/werf/converge/converge.go
Expand Up @@ -181,8 +181,6 @@ werf converge --repo registry.mydomain.com/web --env production`,

common.SetupSaveBuildReport(&commonCmdData, cmd)
common.SetupBuildReportPath(&commonCmdData, cmd)
common.SetupDeprecatedReportPath(&commonCmdData, cmd)
common.SetupDeprecatedReportFormat(&commonCmdData, cmd)

common.SetupSaveDeployReport(&commonCmdData, cmd)
common.SetupDeployReportPath(&commonCmdData, cmd)
Expand Down
2 changes: 0 additions & 2 deletions cmd/werf/plan/plan.go
Expand Up @@ -171,8 +171,6 @@ werf plan --repo registry.mydomain.com/web --env production`,

common.SetupSaveBuildReport(&commonCmdData, cmd)
common.SetupBuildReportPath(&commonCmdData, cmd)
common.SetupDeprecatedReportPath(&commonCmdData, cmd)
common.SetupDeprecatedReportFormat(&commonCmdData, cmd)

common.SetupUseCustomTag(&commonCmdData, cmd)
common.SetupAddCustomTag(&commonCmdData, cmd)
Expand Down
2 changes: 0 additions & 2 deletions cmd/werf/render/render.go
Expand Up @@ -156,8 +156,6 @@ func NewCmd(ctx context.Context) *cobra.Command {

common.SetupSaveBuildReport(&commonCmdData, cmd)
common.SetupBuildReportPath(&commonCmdData, cmd)
common.SetupDeprecatedReportPath(&commonCmdData, cmd)
common.SetupDeprecatedReportFormat(&commonCmdData, cmd)

common.SetupUseCustomTag(&commonCmdData, cmd)
common.SetupVirtualMerge(&commonCmdData, cmd)
Expand Down

0 comments on commit 4f26904

Please sign in to comment.