Skip to content

Commit a61622d

Browse files
authored
Add build compression options to Wave request (#32)
Signed-off-by: Paolo Di Tommaso <[email protected]>
1 parent c307713 commit a61622d

File tree

4 files changed

+177
-1
lines changed

4 files changed

+177
-1
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Wave, containers provisioning service
3+
* Copyright (c) 2023-2024, Seqera Labs
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package io.seqera.wave.api;
20+
21+
import java.util.Objects;
22+
23+
/**
24+
* Model compression options for container image builds
25+
*
26+
* @author Paolo Di Tommaso <[email protected]>
27+
*/
28+
public class BuildCompression {
29+
30+
static public final BuildCompression gzip = new BuildCompression().withMode(Mode.gzip);
31+
static public final BuildCompression estargz = new BuildCompression().withMode(Mode.estargz);
32+
static public final BuildCompression zstd = new BuildCompression().withMode(Mode.zstd);
33+
34+
public enum Mode {
35+
gzip, // gzip compression
36+
estargz, // estargz compression
37+
zstd, // zstd compression
38+
;
39+
}
40+
41+
private Mode mode;
42+
private Integer level;
43+
private Boolean force;
44+
45+
public BuildCompression withMode(Mode mode) {
46+
this.mode = mode;
47+
return this;
48+
}
49+
50+
public BuildCompression withLevel(Integer level) {
51+
this.level = level;
52+
return this;
53+
}
54+
55+
public BuildCompression withForce(Boolean force) {
56+
this.force = force;
57+
return this;
58+
}
59+
60+
public Mode getMode() {
61+
return mode;
62+
}
63+
64+
public void setMode(Mode mode) {
65+
this.mode = mode;
66+
}
67+
68+
public Integer getLevel() {
69+
return level;
70+
}
71+
72+
public void setLevel(Integer level) {
73+
this.level = level;
74+
}
75+
76+
public Boolean getForce() {
77+
return force;
78+
}
79+
80+
public void setForce(Boolean force) {
81+
this.force = force;
82+
}
83+
84+
@Override
85+
public boolean equals(Object o) {
86+
if (this == o) return true;
87+
if (o == null || getClass() != o.getClass()) return false;
88+
BuildCompression that = (BuildCompression) o;
89+
return mode == that.mode && Objects.equals(level, that.level) && Objects.equals(force, that.force);
90+
}
91+
92+
@Override
93+
public int hashCode() {
94+
return Objects.hash(mode, level, force);
95+
}
96+
97+
@Override
98+
public String toString() {
99+
return "BuildCompression{" +
100+
"mode=" + mode +
101+
", level=" + level +
102+
", force=" + force +
103+
'}';
104+
}
105+
}

wave-api/src/main/java/io/seqera/wave/api/SubmitContainerTokenRequest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ public class SubmitContainerTokenRequest implements Cloneable {
155155
*/
156156
public List<ScanLevel> scanLevels;
157157

158+
/**
159+
* The compression mode to be used when building a container image
160+
*/
161+
public BuildCompression buildCompression;
162+
158163
public SubmitContainerTokenRequest copyWith(Map opts) {
159164
try {
160165
final SubmitContainerTokenRequest copy = (SubmitContainerTokenRequest) this.clone();
@@ -206,6 +211,8 @@ public SubmitContainerTokenRequest copyWith(Map opts) {
206211
copy.scanMode = (ScanMode) opts.get("scanMode");
207212
if( opts.containsKey("scanLevels"))
208213
copy.scanLevels = (List<ScanLevel>) opts.get("scanLevels");
214+
if( opts.containsKey("buildCompression"))
215+
copy.buildCompression = (BuildCompression) opts.get("buildCompression");
209216
// done
210217
return copy;
211218
}
@@ -341,6 +348,11 @@ public SubmitContainerTokenRequest withScanLevels(List<ScanLevel> levels) {
341348
return this;
342349
}
343350

351+
public SubmitContainerTokenRequest withBuildCompression(BuildCompression mode) {
352+
this.buildCompression = mode;
353+
return this;
354+
}
355+
344356
public boolean formatSingularity() {
345357
return "sif".equals(format);
346358
}
@@ -372,6 +384,7 @@ public String toString() {
372384
", mirror=" + mirror +
373385
", scanMode=" + scanMode +
374386
", scanLevels=" + scanLevels +
387+
", buildCompression=" + buildCompression +
375388
'}';
376389
}
377390
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Wave, containers provisioning service
3+
* Copyright (c) 2023-2024, Seqera Labs
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package io.seqera.wave.api
20+
21+
import spock.lang.Specification
22+
23+
/**
24+
*
25+
* @author Paolo Di Tommaso <[email protected]>
26+
*/
27+
class BuildCompressionTest extends Specification {
28+
29+
def 'should set compression mode' () {
30+
expect:
31+
new BuildCompression().getMode() == null
32+
and:
33+
new BuildCompression().withMode(BuildCompression.Mode.gzip).getMode() == BuildCompression.Mode.gzip
34+
new BuildCompression().withMode(BuildCompression.Mode.zstd).getMode() == BuildCompression.Mode.zstd
35+
new BuildCompression().withMode(BuildCompression.Mode.estargz).getMode() == BuildCompression.Mode.estargz
36+
}
37+
38+
def 'should set compression level'() {
39+
expect:
40+
new BuildCompression().getLevel()==null
41+
and:
42+
new BuildCompression().withLevel(1).getLevel() == 1
43+
new BuildCompression().withLevel(10).getLevel() == 10
44+
}
45+
46+
def 'should set compression force'() {
47+
expect:
48+
new BuildCompression().getForce() == null
49+
and:
50+
new BuildCompression().withForce(false).getForce() == false
51+
new BuildCompression().withForce(true).getForce() == true
52+
}
53+
54+
}

wave-api/src/test/groovy/io/seqera/wave/api/SubmitContainerTokenRequestTest.groovy

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class SubmitContainerTokenRequestTest extends Specification {
5151
mirror: true,
5252
scanMode: ScanMode.async,
5353
scanLevels: List.of(ScanLevel.LOW, ScanLevel.MEDIUM),
54+
buildCompression: BuildCompression.gzip,
5455
)
5556

5657
when:
@@ -79,6 +80,7 @@ class SubmitContainerTokenRequestTest extends Specification {
7980
copy.mirror == req.mirror
8081
copy.scanMode == req.scanMode
8182
copy.scanLevels == req.scanLevels
83+
copy.buildCompression == req.buildCompression
8284
and:
8385
copy.formatSingularity()
8486

@@ -106,7 +108,8 @@ class SubmitContainerTokenRequestTest extends Specification {
106108
nameStrategy: ImageNameStrategy.tagPrefix,
107109
mirror: false,
108110
scanMode: ScanMode.required,
109-
scanLevels: List.of(ScanLevel.HIGH)
111+
scanLevels: List.of(ScanLevel.HIGH),
112+
buildCompression: BuildCompression.estargz,
110113
)
111114
then:
112115
other.towerAccessToken == 'b1'
@@ -131,6 +134,7 @@ class SubmitContainerTokenRequestTest extends Specification {
131134
other.mirror == false
132135
other.scanMode == ScanMode.required
133136
other.scanLevels == List.of(ScanLevel.HIGH)
137+
other.buildCompression == BuildCompression.estargz
134138
and:
135139
!other.formatSingularity()
136140
}

0 commit comments

Comments
 (0)