Open lamba92 opened 4 years ago
Same here, this is becoming more important to use buildx
as support for multi-architecture builds and pushing list (fat) manifests are increasingly being done.
project.tasks.docker.with {
commandLine getDockerBuildCmd()
doFirst { logger.lifecycle("${commandLine.join(' ')}") }
}
def getDockerBuildCmd() {
def buildCommandLine = ['docker', 'buildx', 'build', '--load', '--platform', 'linux/amd64']
if (docker.noCache) {
buildCommandLine.add '--no-cache'
}
if (docker.network != null) {
buildCommandLine.addAll('--network', docker.network)
}
if (!docker.buildArgs.isEmpty()) {
for (Map.Entry<String, String> buildArg : docker.buildArgs.entrySet()) {
buildCommandLine.addAll('--build-arg', "${buildArg.getKey()}=${buildArg.getValue()}")
}
}
if (!docker.labels.isEmpty()) {
for (Map.Entry<String, String> label : docker.labels.entrySet()) {
if (!label.getKey().matches(LABEL_KEY_PATTERN)) {
throw new GradleException(String.format("Docker label '%s' contains illegal characters. " +
"Label keys must only contain lowercase alphanumberic, `.`, or `-` characters (must match %s).",
label.getKey(), LABEL_KEY_PATTERN.pattern()))
}
buildCommandLine.addAll('--label', "${label.getKey()}=${label.getValue()}")
}
}
if (docker.pull) {
buildCommandLine.add '--pull'
}
buildCommandLine.addAll('-t', docker.name, '.')
return buildCommandLine
}
This is great to see. I couldn't wait, so I ended up creating my own Gradle plugin with a focus on using docker buildx
.
There were many many lessons learned along the way. Just a couple gotchas:
docker run --rm --privileged multiarch/qemu-user-static --reset --persistent yes
docker manifest create --amend <your tagged image>
docker manifest push --purge <your tagged list manifest>
I'd be in need to automate a multiarch build similar to this example. Is there any task available?