Skip to content

Commit aaad9b4

Browse files
authored
[Experimental] Use zstd compression in Docker builds (#39409)
* [Experimental] Use zstd compression in Docker builds * fix load errors
1 parent 583601b commit aaad9b4

3 files changed

Lines changed: 21 additions & 7 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"comment": "Modify this file in a trivial way to cause this test suite to run",
3-
"modification": 4
3+
"modification": 5
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"comment": "Modify this file in a trivial way to cause this test suite to run",
3-
"modification": 3
3+
"modification": 4
44
}

buildSrc/src/main/groovy/org/apache/beam/gradle/BeamDockerPlugin.groovy

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class BeamDockerPlugin implements Plugin<Project> {
6161
boolean push = false
6262
String builder = null
6363
String target = null
64+
String compression = 'zstd'
6465

6566
File resolvedDockerfile = null
6667
File resolvedDockerComposeTemplate = null
@@ -72,6 +73,9 @@ class BeamDockerPlugin implements Plugin<Project> {
7273
DockerExtension(Project project) {
7374
this.project = project
7475
this.copySpec = project.copySpec()
76+
if (project.hasProperty('docker-compression')) {
77+
this.compression = project.property('docker-compression')
78+
}
7579
}
7680

7781
void resolvePathsAndValidate() {
@@ -235,13 +239,23 @@ class BeamDockerPlugin implements Plugin<Project> {
235239
if (!ext.platform.isEmpty()) {
236240
buildCommandLine.addAll('--platform', String.join(',', ext.platform))
237241
}
238-
if (ext.load) {
239-
buildCommandLine.add '--load'
242+
if (ext.load && ext.push) {
243+
throw new Exception("cannot combine 'push' and 'load' options")
240244
}
241-
if (ext.push) {
242-
buildCommandLine.add '--push'
245+
if (ext.compression != null && !ext.compression.isEmpty()) {
246+
if (ext.push) {
247+
buildCommandLine.add "--output=type=registry,compression=${ext.compression},force-compression=true,oci-mediatypes=true"
248+
} else if (ext.load) {
249+
buildCommandLine.add '--load'
250+
} else {
251+
buildCommandLine.add "--output=type=image,compression=${ext.compression},force-compression=true,oci-mediatypes=true"
252+
}
253+
} else {
243254
if (ext.load) {
244-
throw new Exception("cannot combine 'push' and 'load' options")
255+
buildCommandLine.add '--load'
256+
}
257+
if (ext.push) {
258+
buildCommandLine.add '--push'
245259
}
246260
}
247261
if (ext.builder != null) {

0 commit comments

Comments
 (0)