Skip to content

Commit 6dcad6b

Browse files
committed
Add --validate-sha flag for Docker push command
1 parent 1c0e2ed commit 6dcad6b

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

buildtools/cli.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ package buildtools
33
import (
44
"errors"
55
"fmt"
6+
"os"
7+
"strconv"
8+
"strings"
9+
610
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/python"
711
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/setup"
812
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
913
"github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
1014
"github.com/jfrog/jfrog-cli-security/utils/techutils"
1115
setupdocs "github.com/jfrog/jfrog-cli/docs/buildtools/setup"
12-
"os"
13-
"strconv"
14-
"strings"
1516

1617
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/container"
1718
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/dotnet"
@@ -768,7 +769,7 @@ func pullCmd(c *cli.Context, image string) error {
768769
if show, err := cliutils.ShowGenericCmdHelpIfNeeded(c, c.Args(), "dockerpullhelp"); show || err != nil {
769770
return err
770771
}
771-
_, rtDetails, _, skipLogin, filteredDockerArgs, buildConfiguration, err := extractDockerOptionsFromArgs(c.Args())
772+
_, rtDetails, _, skipLogin, _, filteredDockerArgs, buildConfiguration, err := extractDockerOptionsFromArgs(c.Args())
772773
if err != nil {
773774
return err
774775
}
@@ -791,24 +792,24 @@ func pushCmd(c *cli.Context, image string) (err error) {
791792
if show, err := cliutils.ShowCmdHelpIfNeeded(c, c.Args()); show || err != nil {
792793
return err
793794
}
794-
threads, rtDetails, detailedSummary, skipLogin, filteredDockerArgs, buildConfiguration, err := extractDockerOptionsFromArgs(c.Args())
795+
threads, rtDetails, detailedSummary, skipLogin, validateSha, filteredDockerArgs, buildConfiguration, err := extractDockerOptionsFromArgs(c.Args())
795796
if err != nil {
796797
return
797798
}
798799
printDeploymentView := log.IsStdErrTerminal()
799-
PushCommand := container.NewPushCommand(containerutils.DockerClient)
800-
PushCommand.SetThreads(threads).SetDetailedSummary(detailedSummary || printDeploymentView).SetCmdParams(filteredDockerArgs).SetSkipLogin(skipLogin).SetBuildConfiguration(buildConfiguration).SetServerDetails(rtDetails).SetImageTag(image)
801-
supported, err := PushCommand.IsGetRepoSupported()
800+
pushCommand := container.NewPushCommand(containerutils.DockerClient)
801+
pushCommand.SetThreads(threads).SetDetailedSummary(detailedSummary || printDeploymentView).SetCmdParams(filteredDockerArgs).SetSkipLogin(skipLogin).SetBuildConfiguration(buildConfiguration).SetServerDetails(rtDetails).SetImageTag(image).SetValidateSha(validateSha)
802+
supported, err := pushCommand.IsGetRepoSupported()
802803
if err != nil {
803804
return err
804805
}
805806
if !supported {
806807
return cliutils.NotSupportedNativeDockerCommand("docker-push")
807808
}
808-
err = commands.Exec(PushCommand)
809-
result := PushCommand.Result()
809+
err = commands.Exec(pushCommand)
810+
result := pushCommand.Result()
810811
defer cliutils.CleanupResult(result, &err)
811-
err = cliutils.PrintCommandSummary(PushCommand.Result(), detailedSummary, printDeploymentView, false, err)
812+
err = cliutils.PrintCommandSummary(pushCommand.Result(), detailedSummary, printDeploymentView, false, err)
812813
return
813814
}
814815

@@ -824,7 +825,7 @@ func dockerNativeCmd(c *cli.Context) error {
824825
if show, err := cliutils.ShowCmdHelpIfNeeded(c, c.Args()); show || err != nil {
825826
return err
826827
}
827-
_, _, _, _, cleanArgs, _, err := extractDockerOptionsFromArgs(c.Args())
828+
_, _, _, _, _, cleanArgs, _, err := extractDockerOptionsFromArgs(c.Args())
828829
if err != nil {
829830
return err
830831
}
@@ -833,7 +834,7 @@ func dockerNativeCmd(c *cli.Context) error {
833834
}
834835

835836
// Remove all the none docker CLI flags from args.
836-
func extractDockerOptionsFromArgs(args []string) (threads int, serverDetails *coreConfig.ServerDetails, detailedSummary, skipLogin bool, cleanArgs []string, buildConfig *build.BuildConfiguration, err error) {
837+
func extractDockerOptionsFromArgs(args []string) (threads int, serverDetails *coreConfig.ServerDetails, detailedSummary, skipLogin bool, validateSha bool, cleanArgs []string, buildConfig *build.BuildConfiguration, err error) {
837838
cleanArgs = append([]string(nil), args...)
838839
var serverId string
839840
cleanArgs, serverId, err = coreutils.ExtractServerIdFromCommand(cleanArgs)
@@ -856,6 +857,11 @@ func extractDockerOptionsFromArgs(args []string) (threads int, serverDetails *co
856857
if err != nil {
857858
return
858859
}
860+
// Extract validateSha flag
861+
cleanArgs, validateSha, err = coreutils.ExtractBoolFlagFromArgs(cleanArgs, "validate-sha")
862+
if err != nil {
863+
return
864+
}
859865
cleanArgs, buildConfig, err = build.ExtractBuildDetailsFromArgs(cleanArgs)
860866
return
861867
}

docs/buildtools/dockerpush/help.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,16 @@ func GetDescription() string {
88

99
func GetArguments() string {
1010
return ` docker push args
11-
The docker push args to run docker push.`
11+
The docker push args to run docker push.
12+
13+
--validate-sha
14+
Set to true to enable SHA-based validation during Docker push.
15+
When enabled, manifest validation will use the image's SHA digest instead of name:tag.
16+
This is useful when pushing to virtual repositories where the tag might exist with different content in higher priority repositories.
17+
The SHA digest is automatically determined from the local image.
18+
19+
With this flag, the CLI will:
20+
1. Use the local image's SHA digest for validation instead of the tag
21+
2. Attempt to find the image in the repository by SHA if tag-based lookup fails
22+
3. Continue the operation even if a digest mismatch is detected, with appropriate warnings`
1223
}

utils/cliutils/commandsflags.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package cliutils
22

33
import (
44
"fmt"
5-
"github.com/jfrog/jfrog-cli-artifactory/cliutils/flagkit"
65
"sort"
76
"strconv"
87

8+
"github.com/jfrog/jfrog-cli-artifactory/cliutils/flagkit"
9+
910
commonCliUtils "github.com/jfrog/jfrog-cli-core/v2/common/cliutils"
1011
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
1112

@@ -345,6 +346,7 @@ const (
345346
// Build tool flags
346347
deploymentThreads = "deployment-threads"
347348
skipLogin = "skip-login"
349+
validateSha = "validate-sha"
348350

349351
// Unique docker promote flags
350352
dockerPromotePrefix = "docker-promote-"
@@ -1704,6 +1706,10 @@ var flagsMap = map[string]cli.Flag{
17041706
Name: ApplicationKey,
17051707
Usage: "[Optional] JFrog ApplicationKey Key` ` ",
17061708
},
1709+
validateSha: cli.BoolFlag{
1710+
Name: validateSha,
1711+
Usage: "[Default: false] Set to true to enable SHA validation during Docker push.` `",
1712+
},
17071713
}
17081714

17091715
var commandFlags = map[string][]string{
@@ -1823,12 +1829,10 @@ var commandFlags = map[string][]string{
18231829
BuildName, BuildNumber, deploymentThreads, Project, detailedSummary, xrayScan, xrOutput,
18241830
},
18251831
Docker: {
1826-
BuildName, BuildNumber, module, Project,
1827-
serverId, skipLogin, threads, detailedSummary, watches, repoPath, licenses, xrOutput, fail, ExtendedTable, BypassArchiveLimits, MinSeverity, FixableOnly, vuln,
1832+
url, user, password, accessToken, sshPassphrase, sshKeyPath, serverId, ClientCertPath, ClientCertKeyPath, Project, skipLogin, validateSha,
18281833
},
18291834
DockerPush: {
1830-
BuildName, BuildNumber, module, Project,
1831-
serverId, skipLogin, threads, detailedSummary,
1835+
url, user, password, accessToken, sshPassphrase, sshKeyPath, serverId, ClientCertPath, ClientCertKeyPath, Project, skipLogin, validateSha,
18321836
},
18331837
DockerPull: {
18341838
BuildName, BuildNumber, module, Project,
@@ -1840,7 +1844,7 @@ var commandFlags = map[string][]string{
18401844
},
18411845
ContainerPush: {
18421846
BuildName, BuildNumber, module, url, user, password, accessToken, sshPassphrase, sshKeyPath,
1843-
serverId, skipLogin, threads, Project, detailedSummary,
1847+
serverId, skipLogin, threads, Project, detailedSummary, validateSha,
18441848
},
18451849
ContainerPull: {
18461850
BuildName, BuildNumber, module, url, user, password, accessToken, sshPassphrase, sshKeyPath,

0 commit comments

Comments
 (0)