Skip to content

Commit

Permalink
Merge branch 'master' into 475-use-k8s-job-instead-of-pod-for-blob-ca…
Browse files Browse the repository at this point in the history
…che-transfer
  • Loading branch information
munishchouhan authored May 6, 2024
2 parents 3e9e790 + caf2f57 commit d93a42a
Show file tree
Hide file tree
Showing 11 changed files with 2,311 additions and 80 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GH_SEQERA_TOKEN }}

- name: Delete build workspace
if: failure()
run: |
sudo rm -rf /home/runner/work/wave/wave/build-workspace
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.5-A0
1.7.5
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Wave changelog
1.7.5 - 2 May 2024
- Fix community repo naming normalisation [a9b12d76]

1.7.4 - 30 Apr 2024
- Prevent use community registry w/o packages (2) [9eb11031]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class BuildConfig {
@Value('${wave.build.compress-caching:true}')
Boolean compressCaching = true

@Value('${wave.build.reserved-words:[]}')
Set<String> reservedWords

@PostConstruct
private void init() {
log.debug("Builder config: " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,31 @@ class ContainerController {
}
}

protected String targetRepo(String repo, ImageNameStrategy strategy) {
assert repo, 'Missing default public repository setting'
// ignore everything that's not a public (community) repo
if( !buildConfig.defaultPublicRepository )
return repo
if( !repo.startsWith(buildConfig.defaultPublicRepository))
return repo

// check if the repository does not ue any reserved word
final parts = repo.tokenize('/')
if( parts.size()>1 && buildConfig.reservedWords ) {
for( String it : parts[1..-1] ) {
if( buildConfig.reservedWords.contains(it) )
throw new BadRequestException("Use of repository '$repo' is not allowed")
}
}

// the repository is fully qualified use as it is
if( parts.size()>1 ) {
return repo
}
else
return repo + (!strategy || strategy==ImageNameStrategy.imageSuffix ? '/library' : '/library/build')
}

BuildRequest makeBuildRequest(SubmitContainerTokenRequest req, PlatformId identity, String ip) {
if( !req.containerFile )
throw new BadRequestException("Missing dockerfile content")
Expand All @@ -273,15 +298,20 @@ class ContainerController {
final spackContent = spackFileFromRequest(req)
final format = req.formatSingularity() ? SINGULARITY : DOCKER
final platform = ContainerPlatform.of(req.containerPlatform)
final buildRepository = req.buildRepository ?: (req.freeze && buildConfig.defaultPublicRepository ? buildConfig.defaultPublicRepository : buildConfig.defaultBuildRepository)
final buildRepository = targetRepo( req.buildRepository ?: (req.freeze && buildConfig.defaultPublicRepository
? buildConfig.defaultPublicRepository
: buildConfig.defaultBuildRepository), req.nameStrategy)
final cacheRepository = req.cacheRepository ?: buildConfig.defaultCacheRepository
final configJson = dockerAuthService.credentialsConfigJson(containerSpec, buildRepository, cacheRepository, identity)
final containerConfig = req.freeze ? req.containerConfig : null
final offset = DataTimeUtils.offsetId(req.timestamp)
final scanId = scanEnabled && format==DOCKER ? LongRndKey.rndHex() : null
final containerFile = spackContent ? prependBuilderTemplate(containerSpec,format) : containerSpec
// use 'imageSuffix' strategy by default for public repo images
final nameStrategy = req.nameStrategy==null && buildRepository && buildConfig.defaultPublicRepository && buildRepository.startsWith(buildConfig.defaultPublicRepository) ? ImageNameStrategy.imageSuffix : null
final nameStrategy = req.nameStrategy==null
&& buildRepository
&& buildConfig.defaultPublicRepository
&& buildRepository.startsWith(buildConfig.defaultPublicRepository) ? ImageNameStrategy.imageSuffix : null

checkContainerSpec(containerSpec)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,10 @@ class ContainerBuildServiceImpl implements ContainerBuildService {
final ret2 = buildStore.getBuild(request.targetImage)
if( ret2 ) {
log.info "== Hit build cache for request: $request"
return new BuildTrack(ret2.id, request.targetImage, true)
// note: mark as cached only if the build result is 'done'
// if the build is still in progress it should be marked as not cached
// so that the client will wait for the container completion
return new BuildTrack(ret2.id, request.targetImage, ret2.done())
}
// invalid state
throw new IllegalStateException("Unable to determine build status for '$request.targetImage'")
Expand Down
16 changes: 1 addition & 15 deletions src/main/groovy/io/seqera/wave/util/ContainerHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ class ContainerHelper {
throw new BadRequestException("Unsupported image naming strategy: '${nameStrategy}'")
}

format==SINGULARITY ? "oras://${normaliseRepo(repo)}:${tag}" : "${normaliseRepo(repo)}:${tag}"
format==SINGULARITY ? "oras://${repo}:${tag}" : "${repo}:${tag}"
}

static protected String normalise0(String tag, int maxLength, String pattern) {
Expand Down Expand Up @@ -357,20 +357,6 @@ class ContainerHelper {
value ? normalise0(value.toLowerCase(), maxLength, /[^a-z0-9_.\-\/]/) : null
}

static protected String normaliseRepo(String value) {
if( !value )
return value
final parts = value.tokenize('/')
if( parts.size()>2 )
return value
if( parts.size()==1 ) {
return parts[0] + '/library/build'
}
else {
return parts[0] + '/library/' + parts[1]
}
}

static String makeContainerId(String containerFile, String condaFile, String spackFile, ContainerPlatform platform, String repository, BuildContext buildContext) {
final attrs = new LinkedHashMap<String,String>(10)
attrs.containerFile = containerFile
Expand Down
Loading

0 comments on commit d93a42a

Please sign in to comment.