@@ -736,7 +736,7 @@ func TestDockerLoginWithServer(t *testing.T) {
736736 } else {
737737 credentials = "--user=" + * tests .JfrogUser + " --password=" + * tests .JfrogPassword
738738 }
739- err := coreTests .NewJfrogCli (execMain , "jfrog config" , credentials ).Exec ("add" , "artDocker" , "--interactive=false" , "--url=" + "http://localhost:8082" , "--enc-password=" + strconv .FormatBool (true ))
739+ err := coreTests .NewJfrogCli (execMain , "jfrog config" , credentials ).Exec ("add" , "artDocker" , "--interactive=false" , "--url=" + "http://localhost:8082" , "--enc-password=" + strconv .FormatBool (true ), "--overwrite" )
740740 assert .NoError (t , err )
741741
742742 imageName := path .Join (* tests .ContainerRegistry , tests .DockerRemoteRepo , "alpine:latest" )
@@ -1158,3 +1158,92 @@ CMD ["sh"]`, baseImage)
11581158
11591159 inttestutils .DeleteBuild (serverDetails .ArtifactoryUrl , buildName , artHttpDetails )
11601160}
1161+
1162+ func TestContainerPullWithSha (t * testing.T ) {
1163+ cleanup := initNativeDockerWithArtTest (t )
1164+ defer cleanup ()
1165+ var credentials string
1166+ if * tests .JfrogAccessToken != "" {
1167+ credentials = "--access-token=" + * tests .JfrogAccessToken
1168+ } else {
1169+ credentials = "--user=" + * tests .JfrogUser + " --password=" + * tests .JfrogPassword
1170+ }
1171+ err := coreTests .NewJfrogCli (execMain , "jfrog config" , credentials ).Exec ("add" , "artDocker" , "--interactive=false" , "--url=" + "http://localhost:8082" , "--enc-password=" + strconv .FormatBool (true ), "--overwrite" )
1172+ assert .NoError (t , err )
1173+ runJfrogCli (t , "config" , "use" , "artDocker" )
1174+ imageName , err := inttestutils .BuildTestImage (tests .DockerImageName + ":1" , "" , tests .DockerLocalRepo , container .DockerClient )
1175+ assert .NoError (t , err )
1176+ defer tests2 .DeleteTestImage (t , imageName , container .DockerClient )
1177+
1178+ // Push container image
1179+ runCmdWithRetries (t , jfrogRtCliTask (container .DockerClient .String ()+ "-push" , imageName , tests .DockerVirtualRepo ))
1180+ buildNumber := "1"
1181+
1182+ dockerImage := container.DockerImage {
1183+ Image : imageName ,
1184+ }
1185+ manifestSha , err := dockerImage .GetManifestDetails ()
1186+ assert .NoError (t , err )
1187+ imageTag := strings .ReplaceAll (imageName , ":1" , "@" + manifestSha )
1188+
1189+ // pull image with SHA
1190+ runJfrogCli (t , "docker" , "pull" , imageTag , "--build-name=" + tests .DockerBuildName , "--build-number=" + buildNumber )
1191+ runRt (t , "build-publish" , tests .DockerBuildName , buildNumber )
1192+
1193+ imagePath := path .Join (tests .DockerVirtualRepo , tests .DockerImageName , "1" ) + "/"
1194+ module := tests .DockerImageName + "@" + manifestSha
1195+ validateContainerBuild (tests .DockerBuildName , buildNumber , imagePath , module , 0 , 7 , t )
1196+
1197+ inttestutils .ContainerTestCleanup (t , serverDetails , artHttpDetails , tests .DockerImageName , tests .DockerBuildName , tests .DockerVirtualRepo )
1198+
1199+ }
1200+
1201+ func TestContainerFatManifestPullWithSha (t * testing.T ) {
1202+ cleanup := initNativeDockerWithArtTest (t )
1203+ defer cleanup ()
1204+ var credentials string
1205+ if * tests .JfrogAccessToken != "" {
1206+ credentials = "--access-token=" + * tests .JfrogAccessToken
1207+ } else {
1208+ credentials = "--user=" + * tests .JfrogUser + " --password=" + * tests .JfrogPassword
1209+ }
1210+ err := coreTests .NewJfrogCli (execMain , "jfrog config" , credentials ).Exec ("add" , "artDocker" , "--interactive=false" , "--url=" + "http://localhost:8082" , "--enc-password=" + strconv .FormatBool (true ), "--overwrite" )
1211+ assert .NoError (t , err )
1212+ runJfrogCli (t , "config" , "use" , "artDocker" )
1213+ imageName := "traefik"
1214+ buildNumber := "1"
1215+ for _ , dockerRepo := range [... ]string {tests .DockerRemoteRepo , tests .DockerVirtualRepo } {
1216+ func () {
1217+ // calculate the sha of the image provided above
1218+ dockerImage := container.DockerImage {
1219+ Image : imageName ,
1220+ }
1221+ manifestSha , err := dockerImage .GetManifestDetails ()
1222+ assert .NoError (t , err )
1223+
1224+ imageTag := path .Join (* tests .ContainerRegistry , dockerRepo , imageName + "@" + manifestSha )
1225+ // Pull container image
1226+ defer tests2 .DeleteTestImage (t , imageTag , container .DockerClient )
1227+ // pull image with SHA
1228+ runJfrogCli (t , "docker" , "pull" , imageTag , "--build-name=" + tests .DockerBuildName , "--build-number=" + buildNumber )
1229+ runRt (t , "build-publish" , tests .DockerBuildName , buildNumber )
1230+
1231+ // Validate
1232+ publishedBuildInfo , found , err := tests .GetBuildInfo (serverDetails , tests .DockerBuildName , buildNumber )
1233+ if err != nil {
1234+ assert .NoError (t , err )
1235+ return
1236+ }
1237+ if ! found {
1238+ assert .True (t , found , "build info was expected to be found" )
1239+ return
1240+ }
1241+ buildInfo := publishedBuildInfo .BuildInfo
1242+ module := imageName + "@" + manifestSha
1243+ validateBuildInfo (buildInfo , t , 6 , 0 , module , entities .Docker )
1244+
1245+ inttestutils .DeleteBuild (serverDetails .ArtifactoryUrl , tests .DockerBuildName , artHttpDetails )
1246+ }()
1247+ }
1248+
1249+ }
0 commit comments