-
Notifications
You must be signed in to change notification settings - Fork 37
Added capability to support docker pull with image sha #323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package ocicontainer | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "github.com/jfrog/jfrog-client-go/artifactory" | ||
|
|
||
| buildinfo "github.com/jfrog/build-info-go/entities" | ||
| "github.com/jfrog/jfrog-client-go/artifactory/services/utils" | ||
| "github.com/jfrog/jfrog-client-go/utils/log" | ||
| ) | ||
|
|
||
| type DockerArtifactsBuilder struct { | ||
| serviceManager artifactory.ArtifactoryServicesManager | ||
| isImagePushed bool | ||
| imageTag string | ||
| repositoryDetails *DockerRepositoryDetails | ||
| } | ||
|
|
||
| // NewDockerArtifactsBuilder creates a new builder for docker build command | ||
| func NewDockerArtifactsBuilder(serviceManager artifactory.ArtifactoryServicesManager, imageTag string, isImagePushed bool) *DockerArtifactsBuilder { | ||
| return &DockerArtifactsBuilder{ | ||
| serviceManager: serviceManager, | ||
| isImagePushed: isImagePushed, | ||
| imageTag: imageTag, | ||
| } | ||
| } | ||
|
|
||
| // getArtifacts collects artifacts for the pushed image | ||
| func (dab *DockerArtifactsBuilder) getArtifacts() (artifacts []buildinfo.Artifact, leadSha string, resultsToApplyProps []utils.ResultItem, err error) { | ||
| var resultItems []utils.ResultItem | ||
| if dab.isImagePushed { | ||
| leadSha, resultItems, resultsToApplyProps, err = dab.collectDetailsForPushedImage(dab.imageTag) | ||
| if err != nil { | ||
| return artifacts, leadSha, resultsToApplyProps, err | ||
| } | ||
| artifacts = dab.createArtifactsFromResults(resultItems) | ||
| } | ||
| return artifacts, leadSha, resultsToApplyProps, err | ||
| } | ||
fluxxBot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // collectDetailsForPushedImage collects layer details for a pushed image | ||
| func (dab *DockerArtifactsBuilder) collectDetailsForPushedImage(imageRef string) (string, []utils.ResultItem, []utils.ResultItem, error) { | ||
| log.Debug(fmt.Sprintf("Building artifacts for the pushed image %s", dab.imageTag)) | ||
| remoteRepo, dockerManifestType, leadSha, err := GetRemoteRepoAndManifestTypeWithLeadSha(imageRef, dab.serviceManager) | ||
| if err != nil { | ||
| return "", []utils.ResultItem{}, []utils.ResultItem{}, err | ||
| } | ||
| searchableRepository, repositoryDetails, err := GetSearchableRepositoryAndDetails(remoteRepo, dab.serviceManager) | ||
| if err != nil { | ||
| return "", []utils.ResultItem{}, []utils.ResultItem{}, err | ||
| } | ||
| dab.repositoryDetails = repositoryDetails | ||
| layers, resultsToApplyProps, err := NewDockerManifestHandler(dab.serviceManager).FetchLayersOfPushedImage(imageRef, searchableRepository, dockerManifestType) | ||
fluxxBot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| log.Debug(fmt.Sprintf("Collected %d layers, %d folders for props", len(layers), len(resultsToApplyProps))) | ||
| return leadSha, layers, resultsToApplyProps, err | ||
| } | ||
|
|
||
| // createArtifactsFromResults converts search results to artifacts | ||
| func (dab *DockerArtifactsBuilder) createArtifactsFromResults(results []utils.ResultItem) []buildinfo.Artifact { | ||
| deduplicated := deduplicateResultsBySha256(results) | ||
| artifacts := make([]buildinfo.Artifact, 0, len(deduplicated)) | ||
| for _, result := range deduplicated { | ||
| artifacts = append(artifacts, result.ToArtifact()) | ||
| } | ||
| return artifacts | ||
| } | ||
|
|
||
| // GetPushedRepo returns the repository where the image was pushed | ||
| func (dab *DockerArtifactsBuilder) GetPushedRepo() string { | ||
fluxxBot marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if dab.repositoryDetails == nil { | ||
| return "" | ||
| } | ||
| if dab.repositoryDetails.RepoType == "virtual" { | ||
fluxxBot marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return dab.repositoryDetails.DefaultDeploymentRepo | ||
fluxxBot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| return dab.repositoryDetails.Key | ||
| } | ||
|
|
||
| // filterLayersFromVirtualRepo filters layers to only include those from the pushed repository | ||
| func filterLayersFromVirtualRepo(items []utils.ResultItem, pushedRepo string) []utils.ResultItem { | ||
| filteredLayers := make([]utils.ResultItem, 0, len(items)) | ||
| for _, item := range items { | ||
| if item.Repo == pushedRepo { | ||
| filteredLayers = append(filteredLayers, item) | ||
| } | ||
| } | ||
| return filteredLayers | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 0 additions & 66 deletions
66
artifactory/commands/ocicontainer/docker_build_artifacts.go
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.