Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: add --deploy-report-path, --build-report-path
--build-report-path does the same as --report-path and deprecates it

Signed-off-by: Ilya Lesikov <ilya@lesikov.com>
  • Loading branch information
ilya-lesikov committed Feb 10, 2023
1 parent 8cc0501 commit 7fa1d81
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 45 deletions.
8 changes: 5 additions & 3 deletions cmd/werf/build/main.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
17 changes: 10 additions & 7 deletions cmd/werf/bundle/apply/apply.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions cmd/werf/bundle/export/export.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 5 additions & 3 deletions cmd/werf/bundle/publish/publish.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 5 additions & 2 deletions cmd/werf/common/cmd_data.go
Expand Up @@ -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

Expand Down
68 changes: 56 additions & 12 deletions cmd/werf/common/common.go
Expand Up @@ -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": {
"<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 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": {
Expand All @@ -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)")
Expand Down
37 changes: 31 additions & 6 deletions cmd/werf/common/conveyor_options.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
10 changes: 7 additions & 3 deletions cmd/werf/converge/converge.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions cmd/werf/render/render.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -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
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -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=
Expand Down

0 comments on commit 7fa1d81

Please sign in to comment.