Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(custom-tags): no way to tag only certain images
Signed-off-by: Aleksei Igrychev <aleksei.igrychev@palark.com>
  • Loading branch information
alexey-igrychev committed Jun 6, 2023
1 parent 2952ea9 commit 54ad8a5
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 37 deletions.
3 changes: 2 additions & 1 deletion cmd/werf/build/main.go
Expand Up @@ -238,7 +238,8 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken

storageManager := manager.NewStorageManager(projectName, stagesStorage, finalStagesStorage, secondaryStagesStorageList, cacheStagesStorageList, storageLockManager)

buildOptions, err := common.GetBuildOptions(ctx, &commonCmdData, giterminismManager, werfConfig)
imageNameList := common.GetImageNameList(imagesToProcess, werfConfig)
buildOptions, err := common.GetBuildOptions(ctx, &commonCmdData, werfConfig, imageNameList)
if err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/werf/bundle/export/export.go
Expand Up @@ -244,7 +244,8 @@ func runExport(ctx context.Context, imagesToProcess build.ImagesToProcess) error
return err
}

buildOptions, err := common.GetBuildOptions(ctx, &commonCmdData, giterminismManager, werfConfig)
imageNameList := common.GetImageNameList(imagesToProcess, werfConfig)
buildOptions, err := common.GetBuildOptions(ctx, &commonCmdData, werfConfig, imageNameList)
if err != nil {
return err
}
Expand Down Expand Up @@ -279,7 +280,7 @@ func runExport(ctx context.Context, imagesToProcess build.ImagesToProcess) error
if err != nil {
return err
}
useCustomTagFunc, err := common.GetUseCustomTagFunc(&commonCmdData, giterminismManager, werfConfig)
useCustomTagFunc, err := common.GetUseCustomTagFunc(&commonCmdData, giterminismManager, imageNameList)
if err != nil {
return err
}
Expand All @@ -298,7 +299,7 @@ func runExport(ctx context.Context, imagesToProcess build.ImagesToProcess) error

if err := conveyorWithRetry.WithRetryBlock(ctx, func(c *build.Conveyor) error {
if common.GetRequireBuiltImages(ctx, &commonCmdData) {
shouldBeBuiltOptions, err := common.GetShouldBeBuiltOptions(&commonCmdData, giterminismManager, werfConfig)
shouldBeBuiltOptions, err := common.GetShouldBeBuiltOptions(&commonCmdData, imageNameList)
if err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/werf/bundle/publish/publish.go
Expand Up @@ -244,7 +244,8 @@ func runPublish(ctx context.Context, imagesToProcess build.ImagesToProcess) erro
return err
}

buildOptions, err := common.GetBuildOptions(ctx, &commonCmdData, giterminismManager, werfConfig)
imageNameList := common.GetImageNameList(imagesToProcess, werfConfig)
buildOptions, err := common.GetBuildOptions(ctx, &commonCmdData, werfConfig, imageNameList)
if err != nil {
return err
}
Expand Down Expand Up @@ -285,7 +286,7 @@ func runPublish(ctx context.Context, imagesToProcess build.ImagesToProcess) erro
if err != nil {
return err
}
useCustomTagFunc, err := common.GetUseCustomTagFunc(&commonCmdData, giterminismManager, werfConfig)
useCustomTagFunc, err := common.GetUseCustomTagFunc(&commonCmdData, giterminismManager, imageNameList)
if err != nil {
return err
}
Expand All @@ -304,7 +305,7 @@ func runPublish(ctx context.Context, imagesToProcess build.ImagesToProcess) erro

if err := conveyorWithRetry.WithRetryBlock(ctx, func(c *build.Conveyor) error {
if common.GetRequireBuiltImages(ctx, &commonCmdData) {
shouldBeBuiltOptions, err := common.GetShouldBeBuiltOptions(&commonCmdData, giterminismManager, werfConfig)
shouldBeBuiltOptions, err := common.GetShouldBeBuiltOptions(&commonCmdData, imageNameList)
if err != nil {
return err
}
Expand Down
18 changes: 9 additions & 9 deletions cmd/werf/common/conveyor_options.go
Expand Up @@ -69,8 +69,8 @@ func GetConveyorOptionsWithParallel(ctx context.Context, commonCmdData *CmdData,
return conveyorOptions, nil
}

func GetShouldBeBuiltOptions(commonCmdData *CmdData, giterminismManager giterminism_manager.Interface, werfConfig *config.WerfConfig) (options build.ShouldBeBuiltOptions, err error) {
customTagFuncList, err := getCustomTagFuncList(getCustomTagOptionValues(commonCmdData), commonCmdData, giterminismManager, werfConfig)
func GetShouldBeBuiltOptions(commonCmdData *CmdData, imageNameList []string) (options build.ShouldBeBuiltOptions, err error) {
customTagFuncList, err := getCustomTagFuncList(getCustomTagOptionValues(commonCmdData), commonCmdData, imageNameList)
if err != nil {
return options, err
}
Expand All @@ -79,13 +79,13 @@ func GetShouldBeBuiltOptions(commonCmdData *CmdData, giterminismManager gitermin
return options, nil
}

func GetBuildOptions(ctx context.Context, commonCmdData *CmdData, giterminismManager giterminism_manager.Interface, werfConfig *config.WerfConfig) (buildOptions build.BuildOptions, err error) {
func GetBuildOptions(ctx context.Context, commonCmdData *CmdData, werfConfig *config.WerfConfig, imageNameList []string) (buildOptions build.BuildOptions, err error) {
introspectOptions, err := GetIntrospectOptions(commonCmdData, werfConfig)
if err != nil {
return buildOptions, err
}

customTagFuncList, err := getCustomTagFuncList(getCustomTagOptionValues(commonCmdData), commonCmdData, giterminismManager, werfConfig)
customTagFuncList, err := getCustomTagFuncList(getCustomTagOptionValues(commonCmdData), commonCmdData, imageNameList)
if err != nil {
return buildOptions, err
}
Expand Down Expand Up @@ -125,7 +125,7 @@ func GetBuildOptions(ctx context.Context, commonCmdData *CmdData, giterminismMan
return buildOptions, nil
}

func getCustomTagFuncList(tagOptionValues []string, commonCmdData *CmdData, giterminismManager giterminism_manager.Interface, werfConfig *config.WerfConfig) ([]image.CustomTagFunc, error) {
func getCustomTagFuncList(tagOptionValues []string, commonCmdData *CmdData, imageNameList []string) ([]image.CustomTagFunc, error) {
if len(tagOptionValues) == 0 {
return nil, nil
}
Expand Down Expand Up @@ -166,8 +166,8 @@ func getCustomTagFuncList(tagOptionValues []string, commonCmdData *CmdData, gite

contentBasedTagStub := strings.Repeat("x", 70) // 1b77754d35b0a3e603731828ee6f2400c4f937382874db2566c616bb-1624991915332
var prevImageTag string
for _, img := range werfConfig.GetAllImages() {
imageTag := tagFunc(img.GetName(), contentBasedTagStub)
for _, imageName := range imageNameList {
imageTag := tagFunc(imageName, contentBasedTagStub)

if err := slug.ValidateDockerTag(imageTag); err != nil {
return nil, fmt.Errorf("invalid custom tag %q: %w", optionValue, err)
Expand All @@ -187,13 +187,13 @@ func getCustomTagFuncList(tagOptionValues []string, commonCmdData *CmdData, gite
return tagFuncList, nil
}

func GetUseCustomTagFunc(commonCmdData *CmdData, giterminismManager giterminism_manager.Interface, werfConfig *config.WerfConfig) (image.CustomTagFunc, error) {
func GetUseCustomTagFunc(commonCmdData *CmdData, giterminismManager giterminism_manager.Interface, imageNameList []string) (image.CustomTagFunc, error) {
var tagOptionValues []string
if *commonCmdData.UseCustomTag != "" {
tagOptionValues = []string{*commonCmdData.UseCustomTag}
}

customTagFuncList, err := getCustomTagFuncList(tagOptionValues, commonCmdData, giterminismManager, werfConfig)
customTagFuncList, err := getCustomTagFuncList(tagOptionValues, commonCmdData, imageNameList)
if err != nil {
return nil, err
}
Expand Down
17 changes: 16 additions & 1 deletion cmd/werf/common/process_images.go
@@ -1,6 +1,9 @@
package common

import "github.com/werf/werf/pkg/build"
import (
"github.com/werf/werf/pkg/build"
"github.com/werf/werf/pkg/config"
)

func GetImagesToProcess(onlyImages []string, withoutImages bool) build.ImagesToProcess {
if withoutImages {
Expand All @@ -10,3 +13,15 @@ func GetImagesToProcess(onlyImages []string, withoutImages bool) build.ImagesToP
}
return build.NewImagesToProcess(nil, false)
}

func GetImageNameList(imagesToProcess build.ImagesToProcess, werfConfig *config.WerfConfig) []string {
if imagesToProcess.WithoutImages {
return []string{}
}

if len(imagesToProcess.OnlyImages) != 0 {
return imagesToProcess.OnlyImages
}

return werfConfig.GetImageNameList()
}
7 changes: 4 additions & 3 deletions cmd/werf/converge/converge.go
Expand Up @@ -294,7 +294,8 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
}
defer tmp_manager.ReleaseProjectDir(projectTmpDir)

buildOptions, err := common.GetBuildOptions(ctx, &commonCmdData, giterminismManager, werfConfig)
imageNameList := common.GetImageNameList(imagesToProcess, werfConfig)
buildOptions, err := common.GetBuildOptions(ctx, &commonCmdData, werfConfig, imageNameList)
if err != nil {
return err
}
Expand Down Expand Up @@ -328,7 +329,7 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
if err != nil {
return err
}
useCustomTagFunc, err := common.GetUseCustomTagFunc(&commonCmdData, giterminismManager, werfConfig)
useCustomTagFunc, err := common.GetUseCustomTagFunc(&commonCmdData, giterminismManager, imageNameList)
if err != nil {
return err
}
Expand All @@ -347,7 +348,7 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken

if err := conveyorWithRetry.WithRetryBlock(ctx, func(c *build.Conveyor) error {
if common.GetRequireBuiltImages(ctx, &commonCmdData) {
shouldBeBuiltOptions, err := common.GetShouldBeBuiltOptions(&commonCmdData, giterminismManager, werfConfig)
shouldBeBuiltOptions, err := common.GetShouldBeBuiltOptions(&commonCmdData, imageNameList)
if err != nil {
return err
}
Expand Down
12 changes: 1 addition & 11 deletions cmd/werf/export/export.go
Expand Up @@ -246,17 +246,7 @@ func run(ctx context.Context, imagesToProcess build.ImagesToProcess, tagTemplate
defer conveyorWithRetry.Terminate()

return conveyorWithRetry.WithRetryBlock(ctx, func(c *build.Conveyor) error {
var imageNameList []string

if !imagesToProcess.WithoutImages {
if imagesToProcess.OnlyImages == nil {
for _, img := range werfConfig.GetAllImages() {
imageNameList = append(imageNameList, img.GetName())
}
} else {
imageNameList = append(imageNameList, imagesToProcess.OnlyImages...)
}
}
imageNameList := common.GetImageNameList(imagesToProcess, werfConfig)

tagFuncList, err := getTagFuncList(imageNameList, tagTemplateList)
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions cmd/werf/helm/get_autogenerated_values.go
Expand Up @@ -162,11 +162,12 @@ func runGetServiceValues(ctx context.Context, imagesToProcess build.ImagesToProc

var imagesRepository string
var imagesInfoGetters []*image.InfoGetter
imageNameList := common.GetImageNameList(imagesToProcess, werfConfig)

if *getAutogeneratedValuedCmdData.StubTags {
imagesInfoGetters = common.StubImageInfoGetters(werfConfig)
imagesRepository = common.StubRepoAddress
} else if !imagesToProcess.WithoutImages && (len(werfConfig.StapelImages)+len(werfConfig.ImagesFromDockerfile) > 0) {
} else if len(imageNameList) > 0 {
projectTmpDir, err := tmp_manager.CreateProjectDir(ctx)
if err != nil {
return fmt.Errorf("getting project tmp dir failed: %w", err)
Expand Down Expand Up @@ -201,7 +202,7 @@ func runGetServiceValues(ctx context.Context, imagesToProcess build.ImagesToProc
if err != nil {
return err
}
useCustomTagFunc, err := common.GetUseCustomTagFunc(&getAutogeneratedValuedCmdData, giterminismManager, werfConfig)
useCustomTagFunc, err := common.GetUseCustomTagFunc(&getAutogeneratedValuedCmdData, giterminismManager, imageNameList)
if err != nil {
return err
}
Expand All @@ -217,7 +218,7 @@ func runGetServiceValues(ctx context.Context, imagesToProcess build.ImagesToProc
defer conveyorWithRetry.Terminate()

if err := conveyorWithRetry.WithRetryBlock(ctx, func(c *build.Conveyor) error {
shouldBeBuiltOptions, err := common.GetShouldBeBuiltOptions(&getAutogeneratedValuedCmdData, giterminismManager, werfConfig)
shouldBeBuiltOptions, err := common.GetShouldBeBuiltOptions(&getAutogeneratedValuedCmdData, imageNameList)
if err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/werf/render/render.go
Expand Up @@ -255,7 +255,8 @@ func runRender(ctx context.Context, imagesToProcess build.ImagesToProcess) error
return err
}

buildOptions, err := common.GetBuildOptions(ctx, &commonCmdData, giterminismManager, werfConfig)
imageNameList := common.GetImageNameList(imagesToProcess, werfConfig)
buildOptions, err := common.GetBuildOptions(ctx, &commonCmdData, werfConfig, imageNameList)
if err != nil {
return err
}
Expand Down Expand Up @@ -302,7 +303,7 @@ func runRender(ctx context.Context, imagesToProcess build.ImagesToProcess) error
if err != nil {
return err
}
useCustomTagFunc, err := common.GetUseCustomTagFunc(&commonCmdData, giterminismManager, werfConfig)
useCustomTagFunc, err := common.GetUseCustomTagFunc(&commonCmdData, giterminismManager, imageNameList)
if err != nil {
return err
}
Expand All @@ -327,7 +328,7 @@ func runRender(ctx context.Context, imagesToProcess build.ImagesToProcess) error

if err := conveyorWithRetry.WithRetryBlock(ctx, func(c *build.Conveyor) error {
if common.GetRequireBuiltImages(ctx, &commonCmdData) {
shouldBeBuiltOptions, err := common.GetShouldBeBuiltOptions(&commonCmdData, giterminismManager, werfConfig)
shouldBeBuiltOptions, err := common.GetShouldBeBuiltOptions(&commonCmdData, imageNameList)
if err != nil {
return err
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/config/werf.go
Expand Up @@ -78,6 +78,15 @@ func (c *WerfConfig) GetAllImages() []ImageInterface {
return images
}

func (c *WerfConfig) GetImageNameList() []string {
var list []string
for _, image := range c.GetAllImages() {
list = append(list, image.GetName())
}

return list
}

func (c *WerfConfig) GetImage(imageName string) ImageInterface {
if i := c.GetStapelImage(imageName); i != nil {
return i
Expand Down

0 comments on commit 54ad8a5

Please sign in to comment.