Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions artifactory/utils/commandsummary/buildinfosummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/container"
"github.com/jfrog/jfrog-client-go/utils/log"
"net/url"
"path"
"strings"
)
Expand Down Expand Up @@ -249,16 +250,16 @@ func isSupportedModule(module *buildInfo.Module) bool {
}

func createDockerMultiArchTitle(module *buildInfo.Module) string {
parentImageName := strings.Split(module.Parent, ":")[0]
var sha256 string
for _, artifact := range module.Artifacts {
if artifact.Name == container.ManifestJsonFile {
sha256 = artifact.Sha256
break
}
}
if StaticMarkdownConfig.IsExtendedSummary() {
dockerModuleLink := fmt.Sprintf(artifactoryDockerPackagesUiFormat, strings.TrimSuffix(StaticMarkdownConfig.GetPlatformUrl(), "/"), "%2F%2F"+parentImageName, sha256)
parentImageName := strings.Split(module.Parent, ":")[0]
var sha256 string
for _, artifact := range module.Artifacts {
if artifact.Name == container.ManifestJsonFile {
sha256 = artifact.Sha256
break
}
}
dockerModuleLink := fmt.Sprintf(artifactoryDockerPackagesUiFormat, strings.TrimSuffix(StaticMarkdownConfig.GetPlatformUrl(), "/"), "%2F%2F"+url.PathEscape(parentImageName), sha256)
return fmt.Sprintf("%s <a href=%s>(🐸 View)</a>", module.Id, dockerModuleLink)
}
return module.Id
Expand Down
6 changes: 5 additions & 1 deletion artifactory/utils/container/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ func (builder *buildInfoBuilder) createMultiPlatformBuildInfo(fatManifest *FatMa
Properties: imageProperties,
Artifacts: []buildinfo.Artifact{getFatManifestArtifact(searchResultFatManifest)},
}}}
imageLongNameWithoutRepo, err := builder.image.GetImageLongNameWithoutRepoWithTag()
if err != nil {
return nil, err
}
// Create all image arch modules
for _, manifest := range fatManifest.Manifests {
image := candidateImages[manifest.Digest]
Expand All @@ -378,7 +382,7 @@ func (builder *buildInfoBuilder) createMultiPlatformBuildInfo(fatManifest *FatMa
Id: getModuleIdByManifest(manifest, baseModuleId),
Type: buildinfo.Docker,
Artifacts: artifacts,
Parent: baseModuleId,
Parent: imageLongNameWithoutRepo,
})
}
return buildInfo, setBuildProperties(builder.buildName, builder.buildNumber, builder.project, builder.imageLayers, builder.serviceManager)
Expand Down
15 changes: 15 additions & 0 deletions artifactory/utils/container/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ func (image *Image) GetImageShortNameWithTag() (string, error) {
return imageName, nil
}

// GetImageLongNameWithoutRepoWithTag removes the registry hostname and repository name, returning the organization and image name with the tag.
// e.g., "docker-local/myorg/hello-world:latest" -> "myorg/hello-world:latest"
// e.g., "docker-local/hello-world:latest" -> "hello-world:latest"
func (image *Image) GetImageLongNameWithoutRepoWithTag() (string, error) {
imageName, err := image.GetImageLongNameWithTag()
if err != nil {
return "", err
}
parts := strings.Split(imageName, "/")
if len(parts) > 1 {
return strings.Join(parts[1:], "/"), nil
}
return parts[0], nil
}

// Get image tag name of an image.
// e.g.: https://my-registry/docker-local/hello-world:latest. -> latest
func (image *Image) GetImageTag() (string, error) {
Expand Down
22 changes: 22 additions & 0 deletions artifactory/utils/container/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,28 @@ func TestGetImageLongNameWithTag(t *testing.T) {
_, err := NewImage("domain").GetImageLongNameWithTag()
assert.Error(t, err)
}

func TestGetImageLongNameWithoutRepoWithTag(t *testing.T) {
var imageTags = []struct {
in string
expected string
}{
{"domain:8080/repo-name/hello-world:latest", "hello-world:latest"},
{"domain/repo-name/hello-world:latest", "hello-world:latest"},
{"domain/repo-name/org-name/hello-world:latest", "org-name/hello-world:latest"},
{"domain/repo-name/org-name/hello-world", "org-name/hello-world:latest"},
}

for _, v := range imageTags {
result, err := NewImage(v.in).GetImageLongNameWithoutRepoWithTag()
assert.NoError(t, err)
assert.Equal(t, v.expected, result)
}
// Validate failure upon missing image name
_, err := NewImage("domain").GetImageLongNameWithoutRepoWithTag()
assert.Error(t, err)
}

func TestGetImageShortNameWithTag(t *testing.T) {
var imageTags = []struct {
in string
Expand Down
Loading