github.com/jfrog/jfrog-cli-core/v2@v2.52.0/artifactory/utils/container/manifest.go (about) 1 package container 2 3 import ( 4 "path" 5 "strings" 6 7 "github.com/jfrog/jfrog-client-go/artifactory" 8 "github.com/jfrog/jfrog-client-go/artifactory/services/utils" 9 ) 10 11 // To unmarshal config layer file 12 type configLayer struct { 13 History []history `json:"history,omitempty"` 14 } 15 16 type history struct { 17 Created string `json:"created,omitempty"` 18 CreatedBy string `json:"created_by,omitempty"` 19 EmptyLayer bool `json:"empty_layer,omitempty"` 20 } 21 22 // To unmarshal manifest.json file 23 type manifest struct { 24 Config manifestConfig `json:"config,omitempty"` 25 Layers []layer `json:"layers,omitempty"` 26 } 27 28 type manifestConfig struct { 29 Digest string `json:"digest,omitempty"` 30 } 31 32 type layer struct { 33 Digest string `json:"digest,omitempty"` 34 MediaType string `json:"mediaType,omitempty"` 35 } 36 37 type FatManifest struct { 38 Manifests []ManifestDetails `json:"manifests"` 39 } 40 41 type ManifestDetails struct { 42 Digest string `json:"digest"` 43 Platform Platform `json:"platform"` 44 } 45 46 type Platform struct { 47 Architecture string `json:"architecture"` 48 Os string `json:"os"` 49 } 50 51 // Return all the search patterns in which manifest can be found. 52 func getManifestPaths(imagePath, repo string, commandType CommandType) []string { 53 // pattern 1: reverse proxy e.g. ecosysjfrog-docker-local.jfrog.io. 54 paths := []string{path.Join(repo, imagePath, "*")} 55 // pattern 2: proxy-less e.g. orgab.jfrog.team/docker-local. 56 endOfRepoNameIndex := strings.Index(imagePath[1:], "/") 57 proxylessTag := imagePath[endOfRepoNameIndex+1:] 58 paths = append(paths, path.Join(repo, proxylessTag, "*")) 59 // If image path includes more than 3 slashes, Artifactory doesn't store this image under 'library', thus we should not look further. 60 if commandType != Push && strings.Count(imagePath, "/") <= 3 { 61 // pattern 3: reverse proxy - this time with 'library' as part of the path. 62 paths = append(paths, path.Join(repo, "library", imagePath, "*")) 63 // pattern 4: Assume proxy-less - this time with 'library' as part of the path. 64 paths = append(paths, path.Join(repo, "library", proxylessTag, "*")) 65 } 66 return paths 67 } 68 69 func getManifest(resultMap map[string]*utils.ResultItem, serviceManager artifactory.ArtifactoryServicesManager, repo string) (imageManifest *manifest, err error) { 70 if len(resultMap) == 0 { 71 return 72 } 73 manifestSearchResult, ok := resultMap["manifest.json"] 74 if !ok { 75 return 76 } 77 err = downloadLayer(*manifestSearchResult, &imageManifest, serviceManager, repo) 78 return 79 } 80 81 func getFatManifest(resultMap map[string]*utils.ResultItem, serviceManager artifactory.ArtifactoryServicesManager, repo string) (imageFatManifest *FatManifest, err error) { 82 if len(resultMap) == 0 { 83 return 84 } 85 manifestSearchResult, ok := resultMap["list.manifest.json"] 86 if !ok { 87 return 88 } 89 err = downloadLayer(*manifestSearchResult, &imageFatManifest, serviceManager, repo) 90 return 91 }