Skip to content

Commit

Permalink
Add support for public build repo
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed Oct 7, 2023
1 parent fbe60a3 commit e723103
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 10 deletions.
3 changes: 3 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ wave:
quay.io:
username: "${QUAY_USER:}"
password: "${QUAY_PAT:}"
quay.io/seqera/wave/containers:
username: "${WAVE_PUBLIC_USER}"
password: "${WAVE_PUBLIC_PAT}"
195996028523.dkr.ecr.eu-west-1.amazonaws.com:
username : "${AWS_ACCESS_KEY_ID:}"
password : "${AWS_SECRET_ACCESS_KEY:}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ interface RegistryCredentialsProvider {
*/
RegistryCredentials getDefaultCredentials(String registry)

default RegistryCredentials getDefaultCredentials(ContainerPath container) {
return getDefaultCredentials((String)(container?.registry))
}
RegistryCredentials getDefaultCredentials(ContainerPath container)

/**
* Provides the credentials for the specified container associated with the user and tower
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package io.seqera.wave.auth

import javax.annotation.Nullable

import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import io.micronaut.context.annotation.Value
Expand Down Expand Up @@ -51,6 +53,10 @@ class RegistryCredentialsProviderImpl implements RegistryCredentialsProvider {
@Value('${wave.build.cache}')
private String defaultCacheRepository

@Nullable
@Value('${wave.build.public}')
private String defaultPublicRepository

/**
* Find the corresponding credentials for the specified registry
*
Expand All @@ -65,16 +71,31 @@ class RegistryCredentialsProviderImpl implements RegistryCredentialsProvider {
return getDefaultCredentials0(registry)
}

protected RegistryCredentials getDefaultCredentials0(String registry) {
@Override
RegistryCredentials getDefaultCredentials(ContainerPath container) {
return container && container.repository==defaultPublicRepository
? getDefaultRepoCredentials0(container)
: getDefaultCredentials0(container?.registry)
}

protected RegistryCredentials getDefaultCredentials0(String registry) {
final config = registryConfigurationFactory.getRegistryKeys(registry)
if( !config ){
log.debug "Unable to find credentials for registry '$registry'"
log.debug "Unable to find default credentials for registry '$registry'"
return null
}
return credentialsFactory.create(registry, config.username, config.password)
}

protected RegistryCredentials getDefaultRepoCredentials0(ContainerPath container) {
final config = registryConfigurationFactory.getRegistryKeys(container.repository)
if( !config ){
log.debug "Unable to find default credentials for repository '$container.repository'"
return null
}
return credentialsFactory.create(container.registry, config.username, config.password)
}

/**
* Provides the credentials for the specified container associated with the user and tower
* workspace specified.
Expand All @@ -99,8 +120,9 @@ class RegistryCredentialsProviderImpl implements RegistryCredentialsProvider {
throw new IllegalArgumentException("Missing required parameter userId -- Unable to retrieve credentials for container repository '$container'")

// use default credentials for default repositories
if( container.repository==defaultBuildRepository || container.repository==defaultCacheRepository )
return getDefaultCredentials(container.registry)
final repo = container.repository
if( repo==defaultBuildRepository || repo==defaultCacheRepository || repo==defaultPublicRepository)
return getDefaultCredentials(container)

return getUserCredentials0(container.registry, userId, workspaceId, towerToken, towerEndpoint)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package io.seqera.wave.controller

import java.nio.file.Path
import java.util.concurrent.CompletableFuture
import javax.annotation.Nullable
import javax.annotation.PostConstruct

import groovy.transform.CompileStatic
Expand Down Expand Up @@ -102,6 +103,10 @@ class ContainerTokenController {
@Value('${wave.build.cache}')
String defaultCacheRepo

@Nullable
@Value('${wave.build.public}')
String defaultPublicRepo

@Value('${wave.scan.enabled:false}')
boolean scanEnabled

Expand Down Expand Up @@ -136,7 +141,7 @@ class ContainerTokenController {

@PostConstruct
private void init() {
log.info "Wave server url: $serverUrl; allowAnonymous: $allowAnonymous; tower-endpoint-url: $towerEndpointUrl"
log.info "Wave server url: $serverUrl; allowAnonymous: $allowAnonymous; tower-endpoint-url: $towerEndpointUrl; default-builld-repo: $defaultBuildRepo; default-cache-repo: $defaultCacheRepo; default-public-repo: $defaultPublicRepo"
}

@Post('/container-token')
Expand Down Expand Up @@ -204,7 +209,7 @@ class ContainerTokenController {
final spackContent = req.spackFile ? new String(req.spackFile.decodeBase64()) : null as String
final format = req.formatSingularity() ? SINGULARITY : DOCKER
final platform = ContainerPlatform.of(req.containerPlatform)
final build = req.buildRepository ?: defaultBuildRepo
final build = req.buildRepository ?: (req.freeze && defaultPublicRepo ? defaultPublicRepo : defaultBuildRepo)
final cache = req.cacheRepository ?: defaultCacheRepo
final configJson = dockerAuthService.credentialsConfigJson(containerSpec, build, cache, user?.id, req.towerWorkspaceId, req.towerAccessToken, req.towerEndpoint)
final containerConfig = req.freeze ? req.containerConfig : null
Expand Down Expand Up @@ -251,7 +256,7 @@ class ContainerTokenController {
throw new BadRequestException("Attributes 'containerImage' and 'containerFile' cannot be used in the same request")
if( req.containerImage?.contains('@sha256:') && req.containerConfig && !req.freeze )
throw new BadRequestException("Container requests made using a SHA256 as tag does not support the 'containerConfig' attribute")
if( req.freeze && !req.buildRepository )
if( req.freeze && !req.buildRepository && !defaultPublicRepo )
throw new BadRequestException("When freeze mode is enabled the target build repository must be specified - see 'wave.build.repository' setting")
if( req.formatSingularity() && !req.freeze )
throw new BadRequestException("Singularity build is only allowed enabling freeze mode - see 'wave.freeze' setting")
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ wave:
scan:
enabled: true
build:
public: 'quay.io/seqera/wave/containers'
workspace: 'build-workspace'
spack:
cacheDirectory: 'spack-cache'
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ wave:
password: ${AZURECR_PAT:test}
europe-southwest1-docker.pkg.dev:
credentials : ${GOOGLECR_KEYS:test}
quay.io/test/public/repo:
username: 'foo'
password: 'bar'
build:
workspace: 'build-workspace'
spack:
Expand Down

0 comments on commit e723103

Please sign in to comment.