3131import java .nio .file .NoSuchFileException ;
3232import java .nio .file .Path ;
3333import java .time .OffsetDateTime ;
34- import java .util .Arrays ;
35- import java .util .Base64 ;
36- import java .util .List ;
37- import java .util .Optional ;
34+ import java .util .*;
3835import java .util .stream .Collectors ;
3936
4037import ch .qos .logback .classic .Level ;
6057import io .seqera .wave .util .Packer ;
6158import org .slf4j .LoggerFactory ;
6259import picocli .CommandLine ;
63- import static io . seqera . wave . cli . util . Checkers . isEmpty ;
64- import static io .seqera .wave .cli .util .Checkers .isEnvVar ;
60+
61+ import static io .seqera .wave .cli .util .Checkers .* ;
6562import static io .seqera .wave .util .DockerHelper .addPackagesToSpackFile ;
6663import static io .seqera .wave .util .DockerHelper .condaFileFromPackages ;
6764import static io .seqera .wave .util .DockerHelper .condaFileFromPath ;
@@ -200,6 +197,9 @@ public class App implements Runnable {
200197 @ Option (names = {"--include" }, paramLabel = "false" , description = "Include one or more containers in the specified base image" )
201198 List <String > includes ;
202199
200+ @ Option (names = {"--label" }, paramLabel = "false" , description = "Include one or more labels in the wave build image. e.g. KEY=VALUE" )
201+ List <String > label ;
202+
203203 public static void main (String [] args ) {
204204 try {
205205 final App app = new App ();
@@ -382,13 +382,28 @@ protected void validateArgs() {
382382 if ( !isEmpty (platform ) && !VALID_PLATFORMS .contains (platform ) )
383383 throw new IllegalCliArgumentException (String .format ("Unsupported container platform: '%s'" , platform ));
384384
385+ // check labels
386+ if ( label !=null ) {
387+ for ( String it : label ) {
388+ if ( !isLabel (it ) ) throw new IllegalCliArgumentException ("Invalid docker label syntax - offending value: " + it );
389+ }
390+ }
391+
385392 }
386393
387394 protected Client client () {
388395 return new Client ().withEndpoint (waveEndpoint );
389396 }
390397
391398 protected SubmitContainerTokenRequest createRequest () {
399+ Map <String , String > labels = null ;
400+ if (label !=null ){
401+ labels = new HashMap <>();
402+ for (String singleLabel : label ){
403+ String [] singleLabelArray = singleLabel .split ("=" );
404+ labels .put (singleLabelArray [0 ], singleLabelArray [1 ]);
405+ }
406+ }
392407 return new SubmitContainerTokenRequest ()
393408 .withContainerImage (image )
394409 .withContainerFile (containerFileBase64 ())
@@ -407,6 +422,7 @@ protected SubmitContainerTokenRequest createRequest() {
407422 .withFreezeMode (freeze )
408423 .withDryRun (dryRun )
409424 .withContainerIncludes (includes )
425+ .withLabels (labels )
410426 ;
411427 }
412428
0 commit comments