Skip to content

Commit

Permalink
Add support for registry mirror feature
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed Sep 15, 2024
1 parent 592e5ad commit 7c662fa
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repositories {
}

dependencies {
implementation 'io.seqera:wave-api:0.10.0'
implementation 'io.seqera:wave-api:0.12.0'
implementation 'io.seqera:wave-utils:0.12.0'
implementation 'info.picocli:picocli:4.6.1'
implementation 'com.squareup.moshi:moshi:1.15.0'
Expand Down
28 changes: 27 additions & 1 deletion app/src/main/java/io/seqera/wave/cli/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ public class App implements Runnable {
@Option(names = {"--name-strategy"}, paramLabel = "false", description = "Specify the name strategy for the container name, it can be 'none' or 'tagPrefix' or 'imageSuffix'", hidden = true)
private ImageNameStrategy nameStrategy;

@Option(names = {"--mirror-to"}, paramLabel = "false", description = "Specify registry where the container should be mirrored e.g. 'docker.io'")
private String mirrorToRegistry;

@CommandLine.Parameters
List<String> prompt;

Expand Down Expand Up @@ -384,6 +387,27 @@ protected void validateArgs() {
throw new IllegalCliArgumentException("Context path is not a directory - offending value: " + contextDir);
}

if( !isEmpty(mirrorToRegistry) && !isEmpty(containerFile) )
throw new IllegalCliArgumentException("Argument --mirror-to and --containerfile conflict each other");

if( !isEmpty(mirrorToRegistry) && !isEmpty(condaFile) )
throw new IllegalCliArgumentException("Argument --mirror-to and --conda-file conflict each other");

if( !isEmpty(mirrorToRegistry) && !isEmpty(condaPackages) )
throw new IllegalCliArgumentException("Argument --mirror-to and --conda-package conflict each other");

if( !isEmpty(mirrorToRegistry) && !isEmpty(contextDir) )
throw new IllegalCliArgumentException("Argument --mirror-to and --context conflict each other");

if( !isEmpty(mirrorToRegistry) && freeze )
throw new IllegalCliArgumentException("Argument --mirror-to and --freeze conflict each other");

if( !isEmpty(mirrorToRegistry) && !isEmpty(buildRepository) )
throw new IllegalCliArgumentException("Argument --mirror-to and --build-repository conflict each other");

if( !isEmpty(mirrorToRegistry) && !isEmpty(cacheRepository) )
throw new IllegalCliArgumentException("Argument --mirror-to and --cache-repository conflict each other");

if( dryRun && await != null )
throw new IllegalCliArgumentException("Options --dry-run and --await conflicts each other");

Expand Down Expand Up @@ -414,7 +438,9 @@ protected SubmitContainerTokenRequest createRequest() {
.withFreezeMode(freeze)
.withDryRun(dryRun)
.withContainerIncludes(includes)
.withNameStrategy(nameStrategy);
.withNameStrategy(nameStrategy)
.withMirrorRegistry(mirrorToRegistry)
;
}

public void inspect() {
Expand Down
49 changes: 49 additions & 0 deletions app/src/test/groovy/io/seqera/wave/cli/AppTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class AppTest extends Specification {
containerToken: '12345'
expiration: '1970-01-20T13:57:19.913Z'
freeze: null
mirror: null
targetImage: docker.io/some/repo
'''.stripIndent(true)
}
Expand Down Expand Up @@ -389,4 +390,52 @@ class AppTest extends Specification {
e.getMessage() == "Invalid value for option '--name-strategy': expected one of [none, tagPrefix, imageSuffix] (case-sensitive) but was 'wrong'"
}

def 'should fail when specifying mirror registry and container file' () {
given:
def app = new App()
String[] args = ["--mirror-to", "docker.io", "-f", "foo"]

when:
def cli = new CommandLine(app)
cli.parseArgs(args)
and:
app.validateArgs()
then:
def e = thrown(IllegalCliArgumentException)
and:
e.getMessage() == "Argument --mirror-to and --containerfile conflict each other"
}

def 'should fail when specifying mirror registry and conda package' () {
given:
def app = new App()
String[] args = ["--mirror-to", "docker.io", "--conda-package", "foo"]

when:
def cli = new CommandLine(app)
cli.parseArgs(args)
and:
app.validateArgs()
then:
def e = thrown(IllegalCliArgumentException)
and:
e.getMessage() == "Argument --mirror-to and --conda-package conflict each other"
}

def 'should fail when specifying mirror registry and freeze' () {
given:
def app = new App()
String[] args = ["--mirror-to", "docker.io", "--image", "foo", "--freeze"]

when:
def cli = new CommandLine(app)
cli.parseArgs(args)
and:
app.validateArgs()
then:
def e = thrown(IllegalCliArgumentException)
and:
e.getMessage() == "Argument --mirror-to and --freeze conflict each other"
}

}

0 comments on commit 7c662fa

Please sign in to comment.