Skip to content

Commit

Permalink
Add digest to container index and minor changes
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed Feb 3, 2025
1 parent d6aaf62 commit e2d083d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 26 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies {
implementation 'jakarta.persistence:jakarta.persistence-api:3.0.0'
implementation 'io.seqera:lib-mail:1.2.1'
implementation 'io.seqera:lib-pool:1.0.0'
implementation 'io.seqera:wave-api:0.15.0'
implementation 'io.seqera:wave-api:0.15.1 '
implementation 'io.seqera:wave-utils:0.15.1'
implementation 'io.seqera:lib-crypto:1.0.0'
implementation 'io.micronaut:micronaut-http-client'
Expand Down
32 changes: 13 additions & 19 deletions src/main/groovy/io/seqera/wave/controller/ViewController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import io.micronaut.scheduling.TaskExecutors
import io.micronaut.scheduling.annotation.ExecuteOn
import io.micronaut.views.ModelAndView
import io.micronaut.views.View
import io.seqera.wave.core.ContainerPlatform
import io.seqera.wave.exception.HttpResponseException
import io.seqera.wave.exception.NotFoundException
import io.seqera.wave.service.builder.ContainerBuildService
Expand Down Expand Up @@ -392,27 +391,22 @@ class ViewController {
HttpResponse<Map<String,Object>> viewInspect(@QueryValue String image, @Nullable @QueryValue String platform) {
final binding = new HashMap(10)
try {
def containerSpec
if ( platform ){
final spec = inspectService.containerSpec(image, platform, null)
binding.imageName = spec.imageName
binding.reference = spec.reference
binding.digest = spec.digest
binding.registry = spec.registry
binding.hostName = spec.hostName
binding.config = JacksonHelper.toJson(spec.config)
binding.manifest = JacksonHelper.toJson(spec.manifest)
} else {
final spec = inspectService.containerOrIndexSpec(image, null, null)
if ( !spec.index ){
return viewInspect(image, ContainerPlatform.DEFAULT_ARCH)
}
final spec = inspectService.containerOrIndexSpec(image, platform, null)
if ( spec.container ){
binding.imageName = spec.container.imageName
binding.reference = spec.container.reference
binding.digest = spec.container.digest
binding.registry = spec.container.registry
binding.hostName = spec.container.hostName
binding.config = JacksonHelper.toJson(spec.container.config)
binding.manifest = JacksonHelper.toJson(spec.container.manifest)
}
else {
binding.imageName = image
binding.digest = spec.index.digest
binding.schemaVersion = spec.index.schemaVersion
binding.mediaType = spec.index.mediaType
def manifests = spec.index.manifests
.findAll{ ContainerPlatform.ALLOWED_ARCH.contains(it.platform.architecture)}
binding.manifests = JacksonHelper.toJson(manifests)
binding.manifests = JacksonHelper.toJson(spec.index.manifests)
}
}
catch (Exception e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,9 @@ class ContainerAugmenter {
// when the target platform is not specific and it's a index media type
// return the container index specification
if( !platform && (type==DOCKER_IMAGE_INDEX_V2 || type==OCI_IMAGE_INDEX_V1) ) {
final spec = IndexSpec.parse(manifestsList)
final spec = IndexSpec
.parse(manifestsList)
.withDigest(digest)
return new ContainerOrIndexSpec(spec)
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/io/seqera/wave/inspect-view.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@
{{else if schemaVersion}}
<h3>Index Specification</h3>
<table>
<tr>
<td>Digest</td>
<td>{{digest}}</td>
</tr>
<tr>
<td>Schema Version</td>
<td>{{schemaVersion}}</td>
Expand Down
41 changes: 36 additions & 5 deletions src/test/groovy/io/seqera/wave/core/ContainerAugmenterTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -803,11 +803,42 @@ class ContainerAugmenterTest extends Specification {
spec.manifests.size()>0
}

def 'should fetch container index with digest' () {
given:
def REGISTRY = 'docker.io'
def IMAGE = 'library/busybox'
def REFERENCE = 'sha256:a5d0ce49aa801d475da48f8cb163c354ab95cab073cd3c138bd458fc8257fbf1'
def registry = lookupService.lookup(REGISTRY)
def creds = credentialsProvider.getDefaultCredentials(REGISTRY)
def httpClient = HttpClientFactory.neverRedirectsHttpClient()
and:

def client = new ProxyClient(httpClient, httpConfig)
.withRoute(Mock(RoutePath))
.withImage(IMAGE)
.withRegistry(registry)
.withCredentials(creds)
.withLoginService(loginService)
and:
def scanner = new ContainerAugmenter()
.withClient(client)

when:
def spec = scanner
.getContainerSpec(IMAGE, REFERENCE, WaveDefault.ACCEPT_HEADERS)
.getIndex()
then:
spec.digest == 'sha256:a5d0ce49aa801d475da48f8cb163c354ab95cab073cd3c138bd458fc8257fbf1'
spec.schemaVersion == 2
spec.mediaType == 'application/vnd.oci.image.index.v1+json'
spec.manifests.size()>0
}

def 'should fetch container manifest' () {
given:
def REGISTRY = 'docker.io'
def IMAGE = 'library/busybox'
def REFERENCE = 'sha256:6d9ac9237a84afe1516540f40a0fafdc86859b2141954b4d643af7066d598b74'
def REFERENCE = 'sha256:79c9716db559ffde1170a4faf04910a08d930f511e6904c4899a1f7be2abfb34'
def registry = lookupService.lookup(REGISTRY)
def creds = credentialsProvider.getDefaultCredentials(REGISTRY)
def httpClient = HttpClientFactory.neverRedirectsHttpClient()
Expand All @@ -831,8 +862,8 @@ class ContainerAugmenterTest extends Specification {
then:
spec.registry == 'docker.io'
spec.imageName == 'library/busybox'
spec.reference == 'sha256:6d9ac9237a84afe1516540f40a0fafdc86859b2141954b4d643af7066d598b74'
spec.digest == 'sha256:6d9ac9237a84afe1516540f40a0fafdc86859b2141954b4d643af7066d598b74'
spec.reference == 'sha256:79c9716db559ffde1170a4faf04910a08d930f511e6904c4899a1f7be2abfb34'
spec.digest == 'sha256:79c9716db559ffde1170a4faf04910a08d930f511e6904c4899a1f7be2abfb34'
and:
!spec.isV1()
spec.isV2()
Expand All @@ -844,8 +875,8 @@ class ContainerAugmenterTest extends Specification {
spec.manifest.schemaVersion == 2
spec.manifest.mediaType == 'application/vnd.oci.image.manifest.v1+json'
spec.manifest.config.mediaType == 'application/vnd.oci.image.config.v1+json'
spec.manifest.config.digest == 'sha256:3f57d9401f8d42f986df300f0c69192fc41da28ccc8d797829467780db3dd741'
spec.manifest.config.size == 581
spec.manifest.config.digest == 'sha256:af47096251092caf59498806ab8d58e8173ecf5a182f024ce9d635b5b4a55d66'
spec.manifest.config.size == 372
}


Expand Down

0 comments on commit e2d083d

Please sign in to comment.