diff --git a/cmd/imagePushToRegistry.go b/cmd/imagePushToRegistry.go index 58e474b0c8..75940b043b 100644 --- a/cmd/imagePushToRegistry.go +++ b/cmd/imagePushToRegistry.go @@ -80,13 +80,14 @@ func imagePushToRegistry(config imagePushToRegistryOptions, telemetryData *telem } func runImagePushToRegistry(config *imagePushToRegistryOptions, telemetryData *telemetry.CustomData, utils imagePushToRegistryUtils) error { - if len(config.TargetImages) == 0 { - config.TargetImages = config.SourceImages - } - - if len(config.TargetImages) != len(config.SourceImages) { - log.SetErrorCategory(log.ErrorConfiguration) - return errors.New("configuration error: please configure targetImage and sourceImage properly") + if !config.PushLocalDockerImage { + if len(config.TargetImages) == 0 { + config.TargetImages = mapSourceTargetImages(config.SourceImages) + } + if len(config.TargetImages) != len(config.SourceImages) { + log.SetErrorCategory(log.ErrorConfiguration) + return errors.New("configuration error: please configure targetImage and sourceImage properly") + } } re := regexp.MustCompile(`^https?://`) @@ -98,7 +99,7 @@ func runImagePushToRegistry(config *imagePushToRegistryOptions, telemetryData *t return errors.Wrap(err, "failed to handle credentials for target registry") } - if len(config.LocalDockerImagePath) > 0 { + if config.PushLocalDockerImage { if err := pushLocalImageToTargetRegistry(config, utils); err != nil { return errors.Wrapf(err, "failed to push local image to %q", config.TargetRegistryURL) } @@ -145,28 +146,35 @@ func copyImages(config *imagePushToRegistryOptions, utils imagePushToRegistryUti g.SetLimit(10) platform := config.TargetArchitecture - for i := 0; i < len(config.SourceImages); i++ { - src := fmt.Sprintf("%s/%s", config.SourceRegistryURL, config.SourceImages[i]) - dst := fmt.Sprintf("%s/%s", config.TargetRegistryURL, config.TargetImages[i]) + for _, sourceImage := range config.SourceImages { + sourceImage := sourceImage + src := fmt.Sprintf("%s/%s:%s", config.SourceRegistryURL, sourceImage, config.SourceImageTag) - g.Go(func() error { - log.Entry().Infof("Copying %s to %s...", src, dst) - if err := utils.CopyImage(ctx, src, dst, platform); err != nil { - return err - } - log.Entry().Infof("Copying %s to %s... Done", src, dst) - return nil - }) + targetImage, ok := config.TargetImages[sourceImage].(string) + if !ok { + return fmt.Errorf("incorrect name of target image: %v", config.TargetImages[sourceImage]) + } + + if config.TargetImageTag != "" { + g.Go(func() error { + dst := fmt.Sprintf("%s/%s:%s", config.TargetRegistryURL, targetImage, config.TargetImageTag) + log.Entry().Infof("Copying %s to %s...", src, dst) + if err := utils.CopyImage(ctx, src, dst, platform); err != nil { + return err + } + log.Entry().Infof("Copying %s to %s... Done", src, dst) + return nil + }) + } if config.TagLatest { g.Go(func() error { - // imageName is repository + image, e.g test.registry/testImage - imageName := parseDockerImageName(dst) - log.Entry().Infof("Copying %s to %s...", src, imageName) - if err := utils.CopyImage(ctx, src, imageName, platform); err != nil { + dst := fmt.Sprintf("%s/%s", config.TargetRegistryURL, config.TargetImages[sourceImage]) + log.Entry().Infof("Copying %s to %s...", src, dst) + if err := utils.CopyImage(ctx, src, dst, platform); err != nil { return err } - log.Entry().Infof("Copying %s to %s... Done", src, imageName) + log.Entry().Infof("Copying %s to %s... Done", src, dst) return nil }) } @@ -191,27 +199,33 @@ func pushLocalImageToTargetRegistry(config *imagePushToRegistryOptions, utils im } log.Entry().Infof("Loading local image... Done") - for i := 0; i < len(config.TargetImages); i++ { - dst := fmt.Sprintf("%s/%s", config.TargetRegistryURL, config.TargetImages[i]) + for _, trgImage := range config.TargetImages { + trgImage := trgImage + targetImage, ok := trgImage.(string) + if !ok { + return fmt.Errorf("incorrect name of target image: %v", trgImage) + } - g.Go(func() error { - log.Entry().Infof("Pushing %s...", dst) - if err := utils.PushImage(ctx, img, dst, platform); err != nil { - return err - } - log.Entry().Infof("Pushing %s... Done", dst) - return nil - }) + if config.TargetImageTag != "" { + g.Go(func() error { + dst := fmt.Sprintf("%s/%s:%s", config.TargetRegistryURL, targetImage, config.TargetImageTag) + log.Entry().Infof("Pushing %s...", dst) + if err := utils.PushImage(ctx, img, dst, platform); err != nil { + return err + } + log.Entry().Infof("Pushing %s... Done", dst) + return nil + }) + } if config.TagLatest { g.Go(func() error { - // imageName is repository + image, e.g test.registry/testImage - imageName := parseDockerImageName(dst) - log.Entry().Infof("Pushing %s...", imageName) - if err := utils.PushImage(ctx, img, imageName, platform); err != nil { + dst := fmt.Sprintf("%s/%s", config.TargetRegistryURL, targetImage) + log.Entry().Infof("Pushing %s...", dst) + if err := utils.PushImage(ctx, img, dst, platform); err != nil { return err } - log.Entry().Infof("Pushing %s... Done", imageName) + log.Entry().Infof("Pushing %s... Done", dst) return nil }) } @@ -224,12 +238,11 @@ func pushLocalImageToTargetRegistry(config *imagePushToRegistryOptions, utils im return nil } -func parseDockerImageName(image string) string { - re := regexp.MustCompile(`^(.*?)(?::([^:/]+))?$`) - matches := re.FindStringSubmatch(image) - if len(matches) > 1 { - return matches[1] +func mapSourceTargetImages(sourceImages []string) map[string]any { + targetImages := make(map[string]any, len(sourceImages)) + for _, sourceImage := range sourceImages { + targetImages[sourceImage] = sourceImage } - return image + return targetImages } diff --git a/cmd/imagePushToRegistry_generated.go b/cmd/imagePushToRegistry_generated.go index f488fc08b9..fd50801225 100644 --- a/cmd/imagePushToRegistry_generated.go +++ b/cmd/imagePushToRegistry_generated.go @@ -16,19 +16,21 @@ import ( ) type imagePushToRegistryOptions struct { - TargetImages []string `json:"targetImages,omitempty"` - SourceImages []string `json:"sourceImages,omitempty"` - SourceRegistryURL string `json:"sourceRegistryUrl,omitempty"` - SourceRegistryUser string `json:"sourceRegistryUser,omitempty"` - SourceRegistryPassword string `json:"sourceRegistryPassword,omitempty"` - TargetRegistryURL string `json:"targetRegistryUrl,omitempty"` - TargetRegistryUser string `json:"targetRegistryUser,omitempty"` - TargetRegistryPassword string `json:"targetRegistryPassword,omitempty"` - TagLatest bool `json:"tagLatest,omitempty"` - TagArtifactVersion bool `json:"tagArtifactVersion,omitempty"` - DockerConfigJSON string `json:"dockerConfigJSON,omitempty"` - LocalDockerImagePath string `json:"localDockerImagePath,omitempty"` - TargetArchitecture string `json:"targetArchitecture,omitempty"` + TargetImages map[string]interface{} `json:"targetImages,omitempty"` + SourceImages []string `json:"sourceImages,omitempty" validate:"required_if=PushLocalDockerImage false"` + SourceImageTag string `json:"sourceImageTag,omitempty" validate:"required_if=PushLocalDockerImage false"` + SourceRegistryURL string `json:"sourceRegistryUrl,omitempty" validate:"required_if=PushLocalDockerImage false"` + SourceRegistryUser string `json:"sourceRegistryUser,omitempty" validate:"required_if=PushLocalDockerImage false"` + SourceRegistryPassword string `json:"sourceRegistryPassword,omitempty" validate:"required_if=PushLocalDockerImage false"` + TargetRegistryURL string `json:"targetRegistryUrl,omitempty"` + TargetRegistryUser string `json:"targetRegistryUser,omitempty"` + TargetRegistryPassword string `json:"targetRegistryPassword,omitempty"` + TargetImageTag string `json:"targetImageTag,omitempty" validate:"required_if=TagLatest false"` + TagLatest bool `json:"tagLatest,omitempty"` + DockerConfigJSON string `json:"dockerConfigJSON,omitempty"` + PushLocalDockerImage bool `json:"pushLocalDockerImage,omitempty"` + LocalDockerImagePath string `json:"localDockerImagePath,omitempty" validate:"required_if=PushLocalDockerImage true"` + TargetArchitecture string `json:"targetArchitecture,omitempty"` } // ImagePushToRegistryCommand Allows you to copy a Docker image from a source container registry to a destination container registry. @@ -139,22 +141,22 @@ Currently the imagePushToRegistry only supports copying a local image or image f } func addImagePushToRegistryFlags(cmd *cobra.Command, stepConfig *imagePushToRegistryOptions) { - cmd.Flags().StringSliceVar(&stepConfig.TargetImages, "targetImages", []string{}, "Defines the names (incl. tag) of the images that will be pushed to the target registry. If empty, sourceImages will be used.\nPlease ensure that targetImages and sourceImages correspond to each other: the first image in sourceImages will be mapped to the first image in the targetImages parameter.\n") - cmd.Flags().StringSliceVar(&stepConfig.SourceImages, "sourceImages", []string{}, "Defines the names (incl. tag) of the images that will be pulled from source registry. This is helpful for moving images from one location to another.\nPlease ensure that targetImages and sourceImages correspond to each other: the first image in sourceImages will be mapped to the first image in the targetImages parameter.\n") + + cmd.Flags().StringSliceVar(&stepConfig.SourceImages, "sourceImages", []string{}, "Defines the names of the images that will be pulled from source registry. This is helpful for moving images from one location to another.\nPlease ensure that targetImages and sourceImages correspond to each other: the first image in sourceImages should be mapped to the first image in the targetImages parameter.\n\n```yaml\n sourceImages:\n - image-1\n - image-2\n targetImages:\n image-1: target-image-1\n image-2: target-image-2\n```\n") + cmd.Flags().StringVar(&stepConfig.SourceImageTag, "sourceImageTag", os.Getenv("PIPER_sourceImageTag"), "Tag of the sourceImages") cmd.Flags().StringVar(&stepConfig.SourceRegistryURL, "sourceRegistryUrl", os.Getenv("PIPER_sourceRegistryUrl"), "Defines a registry url from where the image should optionally be pulled from, incl. the protocol like `https://my.registry.com`*\"") - cmd.Flags().StringVar(&stepConfig.SourceRegistryUser, "sourceRegistryUser", os.Getenv("PIPER_sourceRegistryUser"), "Username of the source registry where the image should be pushed pulled from.") - cmd.Flags().StringVar(&stepConfig.SourceRegistryPassword, "sourceRegistryPassword", os.Getenv("PIPER_sourceRegistryPassword"), "Password of the source registry where the image should be pushed pulled from.") + cmd.Flags().StringVar(&stepConfig.SourceRegistryUser, "sourceRegistryUser", os.Getenv("PIPER_sourceRegistryUser"), "Username of the source registry where the image should be pulled from.") + cmd.Flags().StringVar(&stepConfig.SourceRegistryPassword, "sourceRegistryPassword", os.Getenv("PIPER_sourceRegistryPassword"), "Password of the source registry where the image should be pulled from.") cmd.Flags().StringVar(&stepConfig.TargetRegistryURL, "targetRegistryUrl", os.Getenv("PIPER_targetRegistryUrl"), "Defines a registry url from where the image should optionally be pushed to, incl. the protocol like `https://my.registry.com`*\"") cmd.Flags().StringVar(&stepConfig.TargetRegistryUser, "targetRegistryUser", os.Getenv("PIPER_targetRegistryUser"), "Username of the target registry where the image should be pushed to.") cmd.Flags().StringVar(&stepConfig.TargetRegistryPassword, "targetRegistryPassword", os.Getenv("PIPER_targetRegistryPassword"), "Password of the target registry where the image should be pushed to.") - cmd.Flags().BoolVar(&stepConfig.TagLatest, "tagLatest", false, "Defines if the image should be tagged as `latest`") - cmd.Flags().BoolVar(&stepConfig.TagArtifactVersion, "tagArtifactVersion", false, "The parameter is not supported yet. Defines if the image should be tagged with the artifact version") + cmd.Flags().StringVar(&stepConfig.TargetImageTag, "targetImageTag", os.Getenv("PIPER_targetImageTag"), "Tag of the targetImages") + cmd.Flags().BoolVar(&stepConfig.TagLatest, "tagLatest", false, "Defines if the image should be tagged as `latest`. The parameter is true if targetImageTag is not specified.") cmd.Flags().StringVar(&stepConfig.DockerConfigJSON, "dockerConfigJSON", os.Getenv("PIPER_dockerConfigJSON"), "Path to the file `.docker/config.json` - this is typically provided by your CI/CD system. You can find more details about the Docker credentials in the [Docker documentation](https://docs.docker.com/engine/reference/commandline/login/).") + cmd.Flags().BoolVar(&stepConfig.PushLocalDockerImage, "pushLocalDockerImage", false, "Defines if the local image should be pushed to registry") cmd.Flags().StringVar(&stepConfig.LocalDockerImagePath, "localDockerImagePath", os.Getenv("PIPER_localDockerImagePath"), "If the `localDockerImagePath` is a directory, it will be read as an OCI image layout. Otherwise, `localDockerImagePath` is assumed to be a docker-style tarball.") cmd.Flags().StringVar(&stepConfig.TargetArchitecture, "targetArchitecture", os.Getenv("PIPER_targetArchitecture"), "Specifies the targetArchitecture in the form os/arch[/variant][:osversion] (e.g. linux/amd64). All OS and architectures of the specified image will be copied if it is a multi-platform image. To only push a single platform to the target registry use this parameter") - cmd.MarkFlagRequired("sourceImages") - cmd.MarkFlagRequired("sourceRegistryUrl") cmd.MarkFlagRequired("targetRegistryUrl") cmd.MarkFlagRequired("targetRegistryUser") cmd.MarkFlagRequired("targetRegistryPassword") @@ -178,25 +180,38 @@ func imagePushToRegistryMetadata() config.StepData { Name: "targetImages", ResourceRef: []config.ResourceReference{}, Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, - Type: "[]string", + Type: "map[string]interface{}", Mandatory: false, Aliases: []config.Alias{}, - Default: []string{}, }, { Name: "sourceImages", ResourceRef: []config.ResourceReference{ { Name: "commonPipelineEnvironment", - Param: "container/imageNameTags", + Param: "container/imageNames", }, }, Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, Type: "[]string", - Mandatory: true, + Mandatory: false, Aliases: []config.Alias{}, Default: []string{}, }, + { + Name: "sourceImageTag", + ResourceRef: []config.ResourceReference{ + { + Name: "commonPipelineEnvironment", + Param: "artifactVersion", + }, + }, + Scope: []string{"GENERAL", "PARAMETERS", "STAGES", "STEPS"}, + Type: "string", + Mandatory: false, + Aliases: []config.Alias{{Name: "artifactVersion"}, {Name: "containerImageTag"}}, + Default: os.Getenv("PIPER_sourceImageTag"), + }, { Name: "sourceRegistryUrl", ResourceRef: []config.ResourceReference{ @@ -207,7 +222,7 @@ func imagePushToRegistryMetadata() config.StepData { }, Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, Type: "string", - Mandatory: true, + Mandatory: false, Aliases: []config.Alias{}, Default: os.Getenv("PIPER_sourceRegistryUrl"), }, @@ -291,16 +306,21 @@ func imagePushToRegistryMetadata() config.StepData { Default: os.Getenv("PIPER_targetRegistryPassword"), }, { - Name: "tagLatest", - ResourceRef: []config.ResourceReference{}, - Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, - Type: "bool", - Mandatory: false, - Aliases: []config.Alias{}, - Default: false, + Name: "targetImageTag", + ResourceRef: []config.ResourceReference{ + { + Name: "commonPipelineEnvironment", + Param: "artifactVersion", + }, + }, + Scope: []string{"GENERAL", "PARAMETERS", "STAGES", "STEPS"}, + Type: "string", + Mandatory: false, + Aliases: []config.Alias{{Name: "artifactVersion"}, {Name: "containerImageTag"}}, + Default: os.Getenv("PIPER_targetImageTag"), }, { - Name: "tagArtifactVersion", + Name: "tagLatest", ResourceRef: []config.ResourceReference{}, Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, Type: "bool", @@ -323,6 +343,15 @@ func imagePushToRegistryMetadata() config.StepData { Aliases: []config.Alias{}, Default: os.Getenv("PIPER_dockerConfigJSON"), }, + { + Name: "pushLocalDockerImage", + ResourceRef: []config.ResourceReference{}, + Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, + Type: "bool", + Mandatory: false, + Aliases: []config.Alias{}, + Default: false, + }, { Name: "localDockerImagePath", ResourceRef: []config.ResourceReference{}, diff --git a/cmd/imagePushToRegistry_test.go b/cmd/imagePushToRegistry_test.go index 4451f0474c..db26057e4f 100644 --- a/cmd/imagePushToRegistry_test.go +++ b/cmd/imagePushToRegistry_test.go @@ -50,11 +50,11 @@ func TestRunImagePushToRegistry(t *testing.T) { config := imagePushToRegistryOptions{ SourceRegistryURL: "https://source.registry", - SourceImages: []string{"source-image:latest"}, + SourceImages: []string{"source-image"}, SourceRegistryUser: "sourceuser", SourceRegistryPassword: "sourcepassword", TargetRegistryURL: "https://target.registry", - TargetImages: []string{"target-image:latest"}, + TargetImages: map[string]any{"source-image": "target-image"}, TargetRegistryUser: "targetuser", TargetRegistryPassword: "targetpassword", } @@ -74,10 +74,11 @@ func TestRunImagePushToRegistry(t *testing.T) { SourceRegistryURL: "https://source.registry", SourceRegistryUser: "sourceuser", SourceRegistryPassword: "sourcepassword", - SourceImages: []string{"source-image:latest"}, + SourceImages: []string{"source-image"}, TargetRegistryURL: "https://target.registry", TargetRegistryUser: "targetuser", TargetRegistryPassword: "targetpassword", + TargetImageTag: "0.0.1", } craneMockUtils := &dockermock.CraneMockUtils{ ErrCopyImage: dockermock.ErrCopyImage, @@ -91,14 +92,13 @@ func TestRunImagePushToRegistry(t *testing.T) { t.Parallel() config := imagePushToRegistryOptions{ - SourceRegistryURL: "https://source.registry", - SourceRegistryUser: "sourceuser", - SourceRegistryPassword: "sourcepassword", - SourceImages: []string{"source-image:latest"}, + TargetImages: map[string]any{"img": "source-image"}, + TargetImageTag: "0.0.1", TargetRegistryURL: "https://target.registry", TargetRegistryUser: "targetuser", TargetRegistryPassword: "targetpassword", LocalDockerImagePath: "/local/path", + PushLocalDockerImage: true, } craneMockUtils := &dockermock.CraneMockUtils{ ErrLoadImage: dockermock.ErrLoadImage, @@ -154,6 +154,7 @@ func TestPushLocalImageToTargetRegistry(t *testing.T) { craneMockUtils := &dockermock.CraneMockUtils{} config := &imagePushToRegistryOptions{ + PushLocalDockerImage: true, LocalDockerImagePath: "/image/path", TargetRegistryURL: "https://target.registry", TagLatest: false, @@ -170,6 +171,7 @@ func TestPushLocalImageToTargetRegistry(t *testing.T) { ErrLoadImage: dockermock.ErrLoadImage, } config := &imagePushToRegistryOptions{ + PushLocalDockerImage: true, LocalDockerImagePath: "/image/path", TargetRegistryURL: "https://target.registry", TagLatest: false, @@ -186,10 +188,11 @@ func TestPushLocalImageToTargetRegistry(t *testing.T) { ErrPushImage: dockermock.ErrPushImage, } config := &imagePushToRegistryOptions{ + PushLocalDockerImage: true, LocalDockerImagePath: "/image/path", TargetRegistryURL: "https://target.registry", - TargetImages: []string{"my-image:1.0.0"}, - TagLatest: false, + TargetImages: map[string]any{"image1": "my-image"}, + TagLatest: true, } utils := newImagePushToRegistryMockUtils(craneMockUtils) err := pushLocalImageToTargetRegistry(config, utils) @@ -197,44 +200,11 @@ func TestPushLocalImageToTargetRegistry(t *testing.T) { }) } -func TestParseDockerImageName(t *testing.T) { - t.Parallel() - tests := []struct { - name, image, expected string - }{ - { - name: "registry + imagename + tag", - image: "test.io/repo/test-image:1.0.0-12345", - expected: "test.io/repo/test-image", - }, - { - name: "registry + imagename + tag (registry with port)", - image: "test.io:50000/repo/test-image:1.0.0-12345", - expected: "test.io:50000/repo/test-image", - }, - { - name: "registry + imagename", - image: "test-test.io/repo/testimage", - expected: "test-test.io/repo/testimage", - }, - { - name: "imagename + tag", - image: "testImage:1.0.0", - expected: "testImage", - }, - { - name: "imagename", - image: "test-image", - expected: "test-image", - }, - } - - for _, test := range tests { - test := test - t.Run(test.name, func(t *testing.T) { - t.Parallel() - actual := parseDockerImageName(test.image) - assert.Equal(t, test.expected, actual) - }) +func TestMapSourceTargetImages(t *testing.T) { + expected := map[string]any{ + "img1": "img1", "img2": "img2", } + sourceImages := []string{"img1", "img2"} + got := mapSourceTargetImages(sourceImages) + assert.Equal(t, got, expected) } diff --git a/resources/metadata/imagePushToRegistry.yaml b/resources/metadata/imagePushToRegistry.yaml index 80d2c54ec8..dd944afcf3 100644 --- a/resources/metadata/imagePushToRegistry.yaml +++ b/resources/metadata/imagePushToRegistry.yaml @@ -15,31 +15,70 @@ spec: type: stash params: - name: targetImages - type: "[]string" + type: "map[string]interface{}" description: | - Defines the names (incl. tag) of the images that will be pushed to the target registry. If empty, sourceImages will be used. - Please ensure that targetImages and sourceImages correspond to each other: the first image in sourceImages will be mapped to the first image in the targetImages parameter. + Defines the names of the images that will be pushed to the target registry. If empty, names of sourceImages will be used. + Please ensure that targetImages and sourceImages correspond to each other: the first image in sourceImages should be mapped to the first image in the targetImages parameter. + + ```yaml + sourceImages: + - image-1 + - image-2 + targetImages: + image-1: target-image-1 + image-2: target-image-2 + ``` scope: - PARAMETERS - STAGES - STEPS - name: sourceImages type: "[]string" + mandatoryIf: + - name: pushLocalDockerImage + value: false description: | - Defines the names (incl. tag) of the images that will be pulled from source registry. This is helpful for moving images from one location to another. - Please ensure that targetImages and sourceImages correspond to each other: the first image in sourceImages will be mapped to the first image in the targetImages parameter. - mandatory: true + Defines the names of the images that will be pulled from source registry. This is helpful for moving images from one location to another. + Please ensure that targetImages and sourceImages correspond to each other: the first image in sourceImages should be mapped to the first image in the targetImages parameter. + + ```yaml + sourceImages: + - image-1 + - image-2 + targetImages: + image-1: target-image-1 + image-2: target-image-2 + ``` + scope: + - PARAMETERS + - STAGES + - STEPS + resourceRef: + - name: commonPipelineEnvironment + param: container/imageNames + - name: sourceImageTag + aliases: + - name: artifactVersion + - name: containerImageTag + description: Tag of the sourceImages + type: string + mandatoryIf: + - name: pushLocalDockerImage + value: false scope: + - GENERAL - PARAMETERS - STAGES - STEPS resourceRef: - name: commonPipelineEnvironment - param: container/imageNameTags + param: artifactVersion - name: sourceRegistryUrl description: Defines a registry url from where the image should optionally be pulled from, incl. the protocol like `https://my.registry.com`*" type: string - mandatory: true + mandatoryIf: + - name: pushLocalDockerImage + value: false scope: - PARAMETERS - STAGES @@ -49,8 +88,11 @@ spec: param: container/registryUrl - name: sourceRegistryUser type: string + mandatoryIf: + - name: pushLocalDockerImage + value: false secret: true - description: Username of the source registry where the image should be pushed pulled from. + description: Username of the source registry where the image should be pulled from. scope: - PARAMETERS - STAGES @@ -63,8 +105,11 @@ spec: default: docker-registry - name: sourceRegistryPassword type: string + mandatoryIf: + - name: pushLocalDockerImage + value: false secret: true - description: Password of the source registry where the image should be pushed pulled from. + description: Password of the source registry where the image should be pulled from. scope: - PARAMETERS - STAGES @@ -109,15 +154,25 @@ spec: - type: vaultSecret name: registryCredentialsVaultSecretName default: docker-registry - - name: tagLatest - description: "Defines if the image should be tagged as `latest`" - type: bool + - name: targetImageTag + aliases: + - name: artifactVersion + - name: containerImageTag + type: string + mandatoryIf: + - name: tagLatest + value: false + description: Tag of the targetImages scope: + - GENERAL - PARAMETERS - STAGES - STEPS - - name: tagArtifactVersion - description: "The parameter is not supported yet. Defines if the image should be tagged with the artifact version" + resourceRef: + - name: commonPipelineEnvironment + param: artifactVersion + - name: tagLatest + description: "Defines if the image should be tagged as `latest`. The parameter is true if targetImageTag is not specified." type: bool scope: - PARAMETERS @@ -135,9 +190,19 @@ spec: - type: vaultSecretFile name: dockerConfigFileVaultSecretName default: docker-config + - name: pushLocalDockerImage + description: "Defines if the local image should be pushed to registry" + type: bool + scope: + - PARAMETERS + - STAGES + - STEPS - name: localDockerImagePath description: "If the `localDockerImagePath` is a directory, it will be read as an OCI image layout. Otherwise, `localDockerImagePath` is assumed to be a docker-style tarball." type: string + mandatoryIf: + - name: pushLocalDockerImage + value: true scope: - PARAMETERS - STAGES