Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom labels in wave-api #18

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
22 changes: 15 additions & 7 deletions wave-api/src/main/java/io/seqera/wave/api/ContainerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
package io.seqera.wave.api;


import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;

import static io.seqera.wave.api.ObjectUtils.isEmpty;
Expand All @@ -38,6 +36,11 @@ public class ContainerConfig {

public List<String> env;

/**
* Image labels
*/
public List<String> labels;

public String workingDir;

public List<ContainerLayer> layers;
Expand All @@ -46,14 +49,16 @@ public ContainerConfig() {
entrypoint = null;
cmd = null;
env = null;
labels = null;
workingDir = null;
layers = new ArrayList<>();
}

public ContainerConfig(List<String> entrypoint, List<String> cmd, List<String> env, String workDir, List<ContainerLayer> layers) {
public ContainerConfig(List<String> entrypoint, List<String> cmd, List<String> env, List<String> labels, String workDir, List<ContainerLayer> layers) {
this.entrypoint = entrypoint;
this.cmd = cmd;
this.env = env;
this.labels = labels;
this.workingDir = workDir;
this.layers = layers;
}
Expand All @@ -71,6 +76,7 @@ public boolean empty() {
return isEmpty(entrypoint) &&
isEmpty(cmd) &&
isEmpty(env) &&
isEmpty(labels) &&
isEmpty(workingDir) &&
isEmpty(layers);
}
Expand Down Expand Up @@ -103,20 +109,21 @@ public FusionVersion fusionVersion() {

@Override
public String toString() {
return String.format("ContainerConfig[entrypoint=%s; cmd=%s; env=%s; workingDir=%s; layers=%s]", entrypoint, cmd, env, workingDir, layers);
return String.format("ContainerConfig[entrypoint=%s; cmd=%s; env=%s; labels=%s; workingDir=%s; layers=%s]", entrypoint, cmd, env, labels, workingDir, layers);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ContainerConfig that = (ContainerConfig) o;
return Objects.equals(entrypoint, that.entrypoint) && Objects.equals(cmd, that.cmd) && Objects.equals(env, that.env) && Objects.equals(workingDir, that.workingDir) && Objects.equals(layers, that.layers);
return Objects.equals(entrypoint, that.entrypoint) && Objects.equals(cmd, that.cmd) && Objects.equals(env, that.env)
&& Objects.equals(labels, that.labels) && Objects.equals(workingDir, that.workingDir) && Objects.equals(layers, that.layers);
}

@Override
public int hashCode() {
return Objects.hash(entrypoint, cmd, env, workingDir, layers);
return Objects.hash(entrypoint, cmd, env, labels, workingDir, layers);
}

static ContainerConfig copy(ContainerConfig that) {
Expand All @@ -135,6 +142,7 @@ static public ContainerConfig copy(ContainerConfig that, boolean stripData) {
that.entrypoint!=null ? new ArrayList<>(that.entrypoint) : null,
that.cmd!=null ? new ArrayList<>(that.cmd) : null,
that.env!=null ? new ArrayList<>(that.env) : null,
that.labels != null ? new ArrayList<>(that.labels) : null,
that.workingDir,
that.layers != null ? that.layers.stream().map(it -> ContainerLayer.copy(it,stripData)).collect(Collectors.toList()) : null
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class ContainerConfigTest extends Specification {
def l3 = new ContainerLayer( 'http://bar.com', 'sha256:88788', 100, 'sha256:67890' )

and:
def c1 = new ContainerConfig(['/entry/point.sh'], ['/my/cmd'], ['FOO=1'], '/work/dir', [l1])
def c2 = new ContainerConfig(['/entry/point.sh'], ['/my/cmd'], ['FOO=1'], '/work/dir', [l2])
def c3 = new ContainerConfig(['/entry/xyz.sh'], ['/your/cmd'], ['BAR=2'], '/work/dir', [l3])
def c1 = new ContainerConfig(['/entry/point.sh'], ['/my/cmd'], ['FOO=1'], ['foo=bar'], '/work/dir', [l1])
def c2 = new ContainerConfig(['/entry/point.sh'], ['/my/cmd'], ['FOO=1'], ['foo=bar'], '/work/dir', [l2])
def c3 = new ContainerConfig(['/entry/xyz.sh'], ['/your/cmd'], ['BAR=2'], ['bar=foo'], '/work/dir', [l3])

expect:
c1 == c2
Expand All @@ -51,50 +51,54 @@ class ContainerConfigTest extends Specification {
def c0 = new ContainerConfig()
and:
def l1 = new ContainerLayer( 'http://foo.com', 'sha256:12345', 100, 'sha256:67890' )
def c1 = new ContainerConfig(['/entry/point.sh'], ['/my/cmd'], ['FOO=1'], '/work/dir', [l1])
def c1 = new ContainerConfig(['/entry/point.sh'], ['/my/cmd'], ['FOO=1'], ['foo=bar'], '/work/dir', [l1])

expect:
c0.toString() == 'ContainerConfig[entrypoint=null; cmd=null; env=null; workingDir=null; layers=[]]'
c1.toString() == 'ContainerConfig[entrypoint=[/entry/point.sh]; cmd=[/my/cmd]; env=[FOO=1]; workingDir=/work/dir; layers=[ContainerLayer[location=http://foo.com; tarDigest=sha256:67890; gzipDigest=sha256:12345; gzipSize=100]]]'
c0.toString() == 'ContainerConfig[entrypoint=null; cmd=null; env=null; labels=null; workingDir=null; layers=[]]'
c1.toString() == 'ContainerConfig[entrypoint=[/entry/point.sh]; cmd=[/my/cmd]; env=[FOO=1]; labels=[foo=bar]; workingDir=/work/dir; layers=[ContainerLayer[location=http://foo.com; tarDigest=sha256:67890; gzipDigest=sha256:12345; gzipSize=100]]]'
}

def 'should validate empty' () {
expect:
new ContainerConfig().empty()
new ContainerConfig([], null, null, null, null).empty()
new ContainerConfig(null, [], null, null, null).empty()
new ContainerConfig(null, null, [], null, null).empty()
new ContainerConfig(null, null, null, '', null).empty()
new ContainerConfig(null, null, null, null, []).empty()
new ContainerConfig([], null, null, null, null, null).empty()
new ContainerConfig(null, [], null, null, null, null).empty()
new ContainerConfig(null, null, [], null, null, null).empty()
new ContainerConfig(null, null, null, [], null, null).empty()
new ContainerConfig(null, null, null, null, '', null).empty()
new ContainerConfig(null, null, null, null, null, []).empty()
and:
!new ContainerConfig(['x'], null, null, null, null).empty()
!new ContainerConfig(null, ['x'], null, null, null).empty()
!new ContainerConfig(null, null, ['x'], null, null).empty()
!new ContainerConfig(null, null, null, 'x', null).empty()
!new ContainerConfig(null, null, null, null, [new ContainerLayer()]).empty()
!new ContainerConfig(['x'], null, null, null, null, null).empty()
!new ContainerConfig(null, ['x'], null, null, null, null).empty()
!new ContainerConfig(null, null, ['x'], null, null, null).empty()
!new ContainerConfig(null, null, null, ['x'], null, null).empty()
!new ContainerConfig(null, null, null, null, 'x', null).empty()
!new ContainerConfig(null, null, null, null, null, [new ContainerLayer()]).empty()
}

def 'should validate groovy truth' () {
expect:
!new ContainerConfig()
and:
!new ContainerConfig([], null, null, null, null)
!new ContainerConfig(null, [], null, null, null)
!new ContainerConfig(null, null, [], null, null)
!new ContainerConfig(null, null, null, '', null)
!new ContainerConfig(null, null, null, null, [])
!new ContainerConfig([], null, null, null, null, null)
!new ContainerConfig(null, [], null, null, null, null)
!new ContainerConfig(null, null, [], null, null, null)
!new ContainerConfig(null, null, null, [], null, null)
!new ContainerConfig(null, null, null, null, '', null)
!new ContainerConfig(null, null, null, null, null, [])
and:
new ContainerConfig(['x'], null, null, null, null)
new ContainerConfig(null, ['x'], null, null, null)
new ContainerConfig(null, null, ['x'], null, null)
new ContainerConfig(null, null, null, 'x', null)
new ContainerConfig(null, null, null, null, [new ContainerLayer()])
new ContainerConfig(['x'], null, null, null, null, null)
new ContainerConfig(null, ['x'], null, null, null, null)
new ContainerConfig(null, null, ['x'], null, null, null)
new ContainerConfig(null, null, null, ['x'], null, null)
new ContainerConfig(null, null, null, null, 'x', null)
new ContainerConfig(null, null, null, null, null, [new ContainerLayer()])
}

def 'should copy objects' () {
given:
def l1 = new ContainerLayer( 'http://foo.com', 'sha256:12345', 100, 'sha256:67890' )
def c1 = new ContainerConfig(['/entry/point.sh'], ['/my/cmd'], ['FOO=1'], '/work/dir', [l1])
def c1 = new ContainerConfig(['/entry/point.sh'], ['/my/cmd'], ['FOO=1'], ['foo=bar'], '/work/dir', [l1])

expect:
null == ContainerConfig.copy(null)
Expand All @@ -107,7 +111,7 @@ class ContainerConfigTest extends Specification {
def 'should copy objects and strip data' () {
given:
def l1 = new ContainerLayer( 'data:12345678890', 'sha256:12345', 100, 'sha256:67890' )
def c1 = new ContainerConfig(['/entry/point.sh'], ['/my/cmd'], ['FOO=1'], '/work/dir', [l1])
def c1 = new ContainerConfig(['/entry/point.sh'], ['/my/cmd'], ['FOO=1'], ['foo=bar'], '/work/dir', [l1])

expect:
c1 == ContainerConfig.copy(c1)
Expand All @@ -120,7 +124,7 @@ class ContainerConfigTest extends Specification {
def 'should find fusion version' () {
given:
def l1 = new ContainerLayer( 'https://fusionfs.seqera.io/releases/v2.1.3-amd64.json' )
def config = new ContainerConfig(['/entry/point.sh'], ['/my/cmd'], ['FOO=1'], '/work/dir', [l1])
def config = new ContainerConfig(['/entry/point.sh'], ['/my/cmd'], ['FOO=1'], ['foo=bar'], '/work/dir', [l1])

expect:
config.fusionVersion() == new FusionVersion('2.1.3', 'amd64')
Expand Down