Skip to content

Commit

Permalink
Merge pull request #5301 from werf/feat-add-deploy-report-path-option
Browse files Browse the repository at this point in the history
feat: add --deploy-report-path, --build-report-path
  • Loading branch information
ilya-lesikov committed Feb 10, 2023
2 parents 8cc0501 + 048f6c7 commit 98ac7f9
Show file tree
Hide file tree
Showing 22 changed files with 290 additions and 61 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
32 changes: 29 additions & 3 deletions docs/_includes/reference/cli/werf_build.md
Expand Up @@ -67,6 +67,31 @@ werf build [IMAGE_NAME...] [options]
until volume usage becomes below "allowed-docker-storage-volume-usage -
allowed-docker-storage-volume-usage-margin" level (default 5% or
$WERF_ALLOWED_LOCAL_CACHE_VOLUME_USAGE_MARGIN)
--build-report-format=''
Report format: json or envfile (json or $WERF_BUILD_REPORT_FORMAT by default)
json:
{
"Images": {
"<WERF_IMAGE_NAME>": {
"WerfImageName": "<WERF_IMAGE_NAME>",
"DockerRepo": "<REPO>",
"DockerTag": "<TAG>"
"DockerImageName": "<REPO>:<TAG>",
"DockerImageID": "<SHA256>",
"DockerImageDigest": "<SHA256>",
},
...
}
}
envfile:
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)
--build-report-path=''
Report save path ($WERF_BUILD_REPORT_PATH by default)
--cache-repo=[]
Specify one or multiple cache repos with images that will be used as a cache. Cache
will be populated when pushing newly built images into the primary repo and when
Expand Down Expand Up @@ -248,9 +273,9 @@ werf build [IMAGE_NAME...] [options]
repo Selectel VPC (default $WERF_REPO_SELECTEL_VPC)
--repo-selectel-vpc-id=''
repo Selectel VPC ID (default $WERF_REPO_SELECTEL_VPC_ID)
--report-format='json'
Report format: json or envfile (json or $WERF_REPORT_FORMAT by default)
json:
--report-format=''
DEPRECATED: use --build-report-format.
Report format: json or envfile (json or $WERF_REPORT_FORMAT by default) json:
{
"Images": {
"<WERF_IMAGE_NAME>": {
Expand All @@ -272,6 +297,7 @@ werf build [IMAGE_NAME...] [options]
- all characters are uppercase (app -> APP);
- charset /- is replaced with _ (DEV/APP-FRONTEND -> DEV_APP_FRONTEND)
--report-path=''
DEPRECATED: use --build-report-path.
Report save path ($WERF_REPORT_PATH by default)
--secondary-repo=[]
Specify one or multiple secondary read-only repos with images that will be used as a
Expand Down
2 changes: 2 additions & 0 deletions docs/_includes/reference/cli/werf_bundle_apply.md
Expand Up @@ -26,6 +26,8 @@ werf bundle apply [options]
Format: labelName=labelValue.
Also, can be specified with $WERF_ADD_LABEL_* (e.g.
$WERF_ADD_LABEL_1=labelName1=labelValue1, $WERF_ADD_LABEL_2=labelName2=labelValue2)
--deploy-report-path=''
Deploy report save path ($WERF_DEPLOY_REPORT_PATH by default)
--docker-config=''
Specify docker config directory path. Default $WERF_DOCKER_CONFIG or $DOCKER_CONFIG or
~/.docker (in the order of priority)
Expand Down

0 comments on commit 98ac7f9

Please sign in to comment.