Skip to content

Commit 4aa8e82

Browse files
authored
Merge branch 'dev' into add_onemodel_service_support
2 parents 21ee276 + 60a3b4b commit 4aa8e82

File tree

6 files changed

+62
-16
lines changed

6 files changed

+62
-16
lines changed

artifactory/utils/container/buildinfo.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package container
22

33
import (
44
"encoding/json"
5-
ioutils "github.com/jfrog/gofrog/io"
65
"os"
76
"path"
87
"strings"
98

9+
ioutils "github.com/jfrog/gofrog/io"
10+
1011
buildinfo "github.com/jfrog/build-info-go/entities"
1112

1213
artutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
@@ -91,10 +92,23 @@ func (builder *buildInfoBuilder) getSearchableRepo() string {
9192

9293
// Set build properties on image layers in Artifactory.
9394
func setBuildProperties(buildName, buildNumber, project string, imageLayers []utils.ResultItem, serviceManager artifactory.ArtifactoryServicesManager) (err error) {
95+
// Skip if no build info is provided
96+
if buildName == "" || buildNumber == "" {
97+
log.Debug("Skipping setting properties - build name and build number are required")
98+
return nil
99+
}
100+
94101
props, err := build.CreateBuildProperties(buildName, buildNumber, project)
95102
if err != nil {
96103
return
97104
}
105+
106+
// Skip if no properties were created
107+
if len(props) == 0 {
108+
log.Debug("Skipping setting properties - no properties created")
109+
return nil
110+
}
111+
98112
pathToFile, err := writeLayersToFile(imageLayers)
99113
if err != nil {
100114
return

artifactory/utils/container/remoteagent.go

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,14 @@ func (rabib *RemoteAgentBuildInfoBuilder) Build(module string) (*buildinfo.Build
5353
// Search for image manifest and layers in Artifactory.
5454
func (rabib *RemoteAgentBuildInfoBuilder) handleManifest(resultMap map[string]*utils.ResultItem) (map[string]*utils.ResultItem, *manifest, error) {
5555
if manifest, ok := resultMap["manifest.json"]; ok {
56-
err := rabib.isVerifiedManifest(manifest)
57-
if err != nil {
58-
return nil, nil, err
59-
56+
if !rabib.isVerifiedManifest(manifest) {
57+
log.Debug("Manifest verification failed, continuing with SHA-based validation...")
6058
}
6159
manifest, err := getManifest(resultMap, rabib.buildInfoBuilder.serviceManager, rabib.buildInfoBuilder.repositoryDetails.key)
6260
if err != nil {
6361
return nil, nil, err
6462
}
65-
// // Manifest may hold 'empty layers'. As a result, promotion will fail to promote the same layer more than once.
63+
// Manifest may hold 'empty layers'. As a result, promotion will fail to promote the same layer more than once.
6664
rabib.buildInfoBuilder.imageSha2 = manifest.Config.Digest
6765
log.Debug("Found manifest.json. Proceeding to create build-info.")
6866
return resultMap, manifest, nil
@@ -95,6 +93,8 @@ func (rabib *RemoteAgentBuildInfoBuilder) searchImage() (resultMap map[string]*u
9593
// Search image's manifest.
9694
manifestPathsCandidates := getManifestPaths(imagePath, rabib.buildInfoBuilder.getSearchableRepo(), Push)
9795
log.Debug("Start searching for image manifest.json")
96+
97+
// First try standard tag-based search
9898
for _, path := range manifestPathsCandidates {
9999
log.Debug(`Searching in:"` + path + `"`)
100100
resultMap, err = performSearch(path, rabib.buildInfoBuilder.serviceManager)
@@ -108,15 +108,39 @@ func (rabib *RemoteAgentBuildInfoBuilder) searchImage() (resultMap map[string]*u
108108
return resultMap, nil
109109
}
110110
}
111+
112+
// If tag-based search failed and we have a SHA, try SHA-based search
113+
if rabib.manifestSha2 != "" {
114+
log.Debug("Tag-based search failed. Trying SHA-based search with: " + rabib.manifestSha2)
115+
// Extract repository path without tag
116+
repoPath := imagePath[:strings.LastIndex(imagePath, "/")]
117+
// Convert SHA format from sha256:xxx to sha256__xxx for Artifactory path format
118+
shaPath := strings.Replace(rabib.manifestSha2, ":", "__", 1)
119+
// Search for the image using SHA path
120+
shaSearchPath := repoPath + "/" + shaPath + "/*"
121+
log.Debug(`Searching by SHA in:"` + shaSearchPath + `"`)
122+
resultMap, err = performSearch(shaSearchPath, rabib.buildInfoBuilder.serviceManager)
123+
if err != nil {
124+
return nil, err
125+
}
126+
if resultMap != nil && (resultMap["list.manifest.json"] != nil || resultMap["manifest.json"] != nil) {
127+
log.Info("Found image by SHA digest in repository")
128+
return resultMap, nil
129+
}
130+
}
131+
111132
return nil, errorutils.CheckErrorf(imageNotFoundErrorMessage, rabib.buildInfoBuilder.image.name)
112133
}
113134

114-
// Verify manifest's sha256. If there is no match, return nil.
115-
func (rabib *RemoteAgentBuildInfoBuilder) isVerifiedManifest(imageManifest *utils.ResultItem) error {
135+
// Verify manifest's sha256. Returns true if manifest is verified, false otherwise.
136+
func (rabib *RemoteAgentBuildInfoBuilder) isVerifiedManifest(imageManifest *utils.ResultItem) bool {
116137
if imageManifest.GetProperty("docker.manifest.digest") != rabib.manifestSha2 {
117-
return errorutils.CheckErrorf(`Found incorrect manifest.json file. Expects digest "` + rabib.manifestSha2 + `" found "` + imageManifest.GetProperty("docker.manifest.digest"))
138+
manifestDigest := imageManifest.GetProperty("docker.manifest.digest")
139+
log.Warn("Manifest digest mismatch detected. Local image digest: " + rabib.manifestSha2 + ", Repository digest: " + manifestDigest)
140+
log.Info("Proceeding with SHA-based validation to ensure correct image identification...")
141+
return false
118142
}
119-
return nil
143+
return true
120144
}
121145

122146
func getFatManifestRoot(fatManifestPath string) string {

common/project/projectconfig.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const (
4545
Docker
4646
Podman
4747
Twine
48+
Helm
4849
)
4950

5051
type ConfigType string
@@ -73,6 +74,7 @@ var ProjectTypes = []string{
7374
"docker",
7475
"podman",
7576
"twine",
77+
"helm",
7678
}
7779

7880
func (projectType ProjectType) String() string {

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ require (
1313
github.com/google/uuid v1.6.0
1414
github.com/gookit/color v1.5.4
1515
github.com/jedib0t/go-pretty/v6 v6.6.5
16-
github.com/jfrog/build-info-go v1.10.11
16+
github.com/jfrog/build-info-go v1.10.12
1717
github.com/jfrog/gofrog v1.7.6
18-
github.com/jfrog/jfrog-client-go v1.53.0
18+
github.com/jfrog/jfrog-client-go v1.53.1
1919
github.com/magiconair/properties v1.8.9
2020
github.com/manifoldco/promptui v0.9.0
2121
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ github.com/jedib0t/go-pretty/v6 v6.6.5 h1:9PgMJOVBedpgYLI56jQRJYqngxYAAzfEUua+3N
111111
github.com/jedib0t/go-pretty/v6 v6.6.5/go.mod h1:Uq/HrbhuFty5WSVNfjpQQe47x16RwVGXIveNGEyGtHs=
112112
github.com/jfrog/archiver/v3 v3.6.1 h1:LOxnkw9pOn45DzCbZNFV6K0+6dCsQ0L8mR3ZcujO5eI=
113113
github.com/jfrog/archiver/v3 v3.6.1/go.mod h1:VgR+3WZS4N+i9FaDwLZbq+jeU4B4zctXL+gL4EMzfLw=
114-
github.com/jfrog/build-info-go v1.10.11 h1:wAMGCAHa49+ec01HqzSidLAHNIub+glh4ksFp3pYy7o=
115-
github.com/jfrog/build-info-go v1.10.11/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE=
114+
github.com/jfrog/build-info-go v1.10.12 h1:KO/YUeKYtDrnpcmsXmwqr6akjzrwA0hSTUB+Op/HF88=
115+
github.com/jfrog/build-info-go v1.10.12/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE=
116116
github.com/jfrog/gofrog v1.7.6 h1:QmfAiRzVyaI7JYGsB7cxfAJePAZTzFz0gRWZSE27c6s=
117117
github.com/jfrog/gofrog v1.7.6/go.mod h1:ntr1txqNOZtHplmaNd7rS4f8jpA5Apx8em70oYEe7+4=
118118
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=

utils/coreutils/cmdutils.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package coreutils
22

33
import (
4-
"github.com/forPelevin/gomoji"
5-
"github.com/jfrog/jfrog-client-go/utils/log"
64
"strconv"
75
"strings"
86

7+
"github.com/forPelevin/gomoji"
8+
"github.com/jfrog/jfrog-client-go/utils/log"
9+
910
"github.com/gookit/color"
1011
"github.com/jfrog/jfrog-client-go/utils/errorutils"
1112
)
@@ -169,6 +170,11 @@ func ExtractSkipLoginFromArgs(args []string) (cleanArgs []string, skipLogin bool
169170
return extractBoolOptionFromArgs(args, "skip-login")
170171
}
171172

173+
// Used by docker
174+
func ExtractBoolFlagFromArgs(args []string, flagName string) (cleanArgs []string, flagValue bool, err error) {
175+
return extractBoolOptionFromArgs(args, flagName)
176+
}
177+
172178
// Used by docker
173179
func ExtractFailFromArgs(args []string) (cleanArgs []string, fail bool, err error) {
174180
return extractBoolOptionFromArgs(args, "fail")

0 commit comments

Comments
 (0)