From a1ab1e8e0ae790c7b3a41a985c521bf4e3acdff5 Mon Sep 17 00:00:00 2001 From: Matt Cengia Date: Fri, 17 Jul 2020 13:35:54 +1000 Subject: [PATCH] Tidy Gradle dockerBuildX target Build linux/amd64, linux/arm64, and linux/arm/v7 (arm 32-bit) targets all at once. This still requires Gradle and JDK on the local machine (i.e. outside of the Docker build container), because it seems pointless to build the .jar 3 times, once for each architecture, but tags all the images with the same tag, rather than using a tag for each architecture. This allows clients to all use the same image tag, but pull down the architecture that's right for them. I'd like to have it build the .jar file in a container (so the host doesn't need JDK and Gradle), but couldn't think how to do that efficiently (i.e. only once), with this approach. --- build.gradle | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index bed09a6..5b1185c 100644 --- a/build.gradle +++ b/build.gradle @@ -275,22 +275,10 @@ task dockerBuild(type: Exec) { } task dockerBuildX(type: Exec, dependsOn: shadowJar) { - commandLine 'docker', 'buildx', 'build', '--load', '--platform', 'linux/arm64', '-t', dockerImageTag + '-arm64', project.rootDir + commandLine 'docker', 'buildx', 'build', '--push', '--platform', 'linux/arm64,linux/amd64,linux/arm/v7', '-t', dockerImageTag , project.rootDir doLast { exec { - commandLine 'docker', 'buildx', 'build', '--load', '--platform', 'linux/amd64', '-t', dockerImageTag + '-amd64', project.rootDir - } - - exec { - commandLine 'docker', 'tag', dockerImageTag + '-arm64', "${dockerImageName}:latest-arm64-dev" - } - - exec { - commandLine 'docker', 'tag', dockerImageTag + '-amd64', "${dockerImageName}:latest-amd64-dev" - } - - exec { - commandLine 'docker', 'tag', dockerImageTag + '-amd64', "${dockerImageName}:latest-dev" + commandLine 'docker', 'buildx', 'build', '--push', '--platform', 'linux/arm64,linux/amd64,linux/arm/v7', '-t', "${dockerImageName}:latest-dev", project.rootDir } } }