From bb519974872a66c5f347b1c9edf487e9cee09a9b Mon Sep 17 00:00:00 2001 From: Georg Ofenbeck - taaofge1 Date: Wed, 1 May 2024 21:34:20 +0200 Subject: [PATCH 1/6] trying buildx --- .../mill/contrib/docker/DockerModule.scala | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/contrib/docker/src/mill/contrib/docker/DockerModule.scala b/contrib/docker/src/mill/contrib/docker/DockerModule.scala index 57c1308ad32..88cf01d8a52 100644 --- a/contrib/docker/src/mill/contrib/docker/DockerModule.scala +++ b/contrib/docker/src/mill/contrib/docker/DockerModule.scala @@ -84,6 +84,15 @@ trait DockerModule { outer: JavaModule => */ def user: T[String] = "" + /** + * Optional platform parameter, if set uses buildkit to build for specified platform. + * + * See also the Docker docs on + * [[https://docs.docker.com/reference/cli/docker/buildx/build/#platform]] + * for more information. + */ + def platform: T[String] = "" + /** * The name of the executable to use, the default is "docker". */ @@ -155,12 +164,17 @@ trait DockerModule { outer: JavaModule => val (pull, _) = pullAndHash() val pullLatestBase = IterableShellable(if (pull) Some("--pull") else None) - val result = os - .proc(executable(), "build", tagArgs, pullLatestBase, dest) + + val result = if (platform().isEmpty) { + os.proc(executable(), "build", tagArgs, pullLatestBase, dest) .call(stdout = os.Inherit, stderr = os.Inherit) - + } else { + os.proc(executable(),"buildx", "build", tagArgs, pullLatestBase, "--platform", platform(), dest) + .call(stdout = os.Inherit, stderr = os.Inherit) + } log.info(s"Docker build completed ${if (result.exitCode == 0) "successfully" else "unsuccessfully"} with ${result.exitCode}") + log.info(platform()) tags() } From 985c8f6bf6c85c12f0a98f310ebfa44360722ba4 Mon Sep 17 00:00:00 2001 From: Georg Ofenbeck - taaofge1 Date: Thu, 2 May 2024 21:18:25 +0200 Subject: [PATCH 2/6] only running buildx if executable is docker --- contrib/docker/src/mill/contrib/docker/DockerModule.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/docker/src/mill/contrib/docker/DockerModule.scala b/contrib/docker/src/mill/contrib/docker/DockerModule.scala index 88cf01d8a52..cde659281bf 100644 --- a/contrib/docker/src/mill/contrib/docker/DockerModule.scala +++ b/contrib/docker/src/mill/contrib/docker/DockerModule.scala @@ -165,7 +165,8 @@ trait DockerModule { outer: JavaModule => val pullLatestBase = IterableShellable(if (pull) Some("--pull") else None) - val result = if (platform().isEmpty) { + val result = if (platform().isEmpty || executable() != "docker") { + if (platform().nonEmpty) log.info("Platform parameter is ignored when using non-docker executable") os.proc(executable(), "build", tagArgs, pullLatestBase, dest) .call(stdout = os.Inherit, stderr = os.Inherit) } else { @@ -174,7 +175,6 @@ trait DockerModule { outer: JavaModule => } log.info(s"Docker build completed ${if (result.exitCode == 0) "successfully" else "unsuccessfully"} with ${result.exitCode}") - log.info(platform()) tags() } From e06fe7dda437bbbfbc490d7981e63afec9b518ad Mon Sep 17 00:00:00 2001 From: Georg Ofenbeck - taaofge1 Date: Fri, 3 May 2024 19:28:41 +0200 Subject: [PATCH 3/6] added the platform option to the docs --- contrib/docker/readme.adoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contrib/docker/readme.adoc b/contrib/docker/readme.adoc index b12f8d5327e..6dd9dbe9de7 100644 --- a/contrib/docker/readme.adoc +++ b/contrib/docker/readme.adoc @@ -64,7 +64,11 @@ object docker extends DockerConfig { def user = "new-user" // Optionally override the docker executable to use something else def executable = "podman" + // If the executable is docker (which is also the default), you can optionally also pass a platform parameter + // docker buildx is then used to build multi-platform images + def platform = "linux/arm64" } ---- + Run mill in interactive mode to see the docker client output, like `mill -i foo.docker.build`. From 6956a1a27799701bc1f013be1da34ad1d79587b7 Mon Sep 17 00:00:00 2001 From: Georg Ofenbeck - taaofge1 Date: Sat, 4 May 2024 12:27:01 +0200 Subject: [PATCH 4/6] Reformat with scalafmt --- .../mill/contrib/docker/DockerModule.scala | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/contrib/docker/src/mill/contrib/docker/DockerModule.scala b/contrib/docker/src/mill/contrib/docker/DockerModule.scala index cde659281bf..8e8038ed72b 100644 --- a/contrib/docker/src/mill/contrib/docker/DockerModule.scala +++ b/contrib/docker/src/mill/contrib/docker/DockerModule.scala @@ -85,12 +85,12 @@ trait DockerModule { outer: JavaModule => def user: T[String] = "" /** - * Optional platform parameter, if set uses buildkit to build for specified platform. - * - * See also the Docker docs on - * [[https://docs.docker.com/reference/cli/docker/buildx/build/#platform]] - * for more information. - */ + * Optional platform parameter, if set uses buildkit to build for specified platform. + * + * See also the Docker docs on + * [[https://docs.docker.com/reference/cli/docker/buildx/build/#platform]] + * for more information. + */ def platform: T[String] = "" /** @@ -164,14 +164,25 @@ trait DockerModule { outer: JavaModule => val (pull, _) = pullAndHash() val pullLatestBase = IterableShellable(if (pull) Some("--pull") else None) - val result = if (platform().isEmpty || executable() != "docker") { - if (platform().nonEmpty) log.info("Platform parameter is ignored when using non-docker executable") + if (!platform().isEmpty) + log.warn( + "Building for other platforms is currently only supported through buildx on docker" + ) os.proc(executable(), "build", tagArgs, pullLatestBase, dest) - .call(stdout = os.Inherit, stderr = os.Inherit) + .call(stdout = os.Inherit, stderr = os.Inherit) } else { - os.proc(executable(),"buildx", "build", tagArgs, pullLatestBase, "--platform", platform(), dest) - .call(stdout = os.Inherit, stderr = os.Inherit) + os.proc( + executable(), + "buildx", + "build", + tagArgs, + pullLatestBase, + "--platform", + platform(), + dest + ) + .call(stdout = os.Inherit, stderr = os.Inherit) } log.info(s"Docker build completed ${if (result.exitCode == 0) "successfully" else "unsuccessfully"} with ${result.exitCode}") From 69c4878def2134e37a1c1147079dbfef0afa23fe Mon Sep 17 00:00:00 2001 From: Georg Ofenbeck - taaofge1 Date: Sat, 4 May 2024 12:46:57 +0200 Subject: [PATCH 5/6] Revert "Reformat with scalafmt" This reverts commit 6956a1a27799701bc1f013be1da34ad1d79587b7. --- .../mill/contrib/docker/DockerModule.scala | 33 +++++++------------ 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/contrib/docker/src/mill/contrib/docker/DockerModule.scala b/contrib/docker/src/mill/contrib/docker/DockerModule.scala index 8e8038ed72b..cde659281bf 100644 --- a/contrib/docker/src/mill/contrib/docker/DockerModule.scala +++ b/contrib/docker/src/mill/contrib/docker/DockerModule.scala @@ -85,12 +85,12 @@ trait DockerModule { outer: JavaModule => def user: T[String] = "" /** - * Optional platform parameter, if set uses buildkit to build for specified platform. - * - * See also the Docker docs on - * [[https://docs.docker.com/reference/cli/docker/buildx/build/#platform]] - * for more information. - */ + * Optional platform parameter, if set uses buildkit to build for specified platform. + * + * See also the Docker docs on + * [[https://docs.docker.com/reference/cli/docker/buildx/build/#platform]] + * for more information. + */ def platform: T[String] = "" /** @@ -164,25 +164,14 @@ trait DockerModule { outer: JavaModule => val (pull, _) = pullAndHash() val pullLatestBase = IterableShellable(if (pull) Some("--pull") else None) + val result = if (platform().isEmpty || executable() != "docker") { - if (!platform().isEmpty) - log.warn( - "Building for other platforms is currently only supported through buildx on docker" - ) + if (platform().nonEmpty) log.info("Platform parameter is ignored when using non-docker executable") os.proc(executable(), "build", tagArgs, pullLatestBase, dest) - .call(stdout = os.Inherit, stderr = os.Inherit) + .call(stdout = os.Inherit, stderr = os.Inherit) } else { - os.proc( - executable(), - "buildx", - "build", - tagArgs, - pullLatestBase, - "--platform", - platform(), - dest - ) - .call(stdout = os.Inherit, stderr = os.Inherit) + os.proc(executable(),"buildx", "build", tagArgs, pullLatestBase, "--platform", platform(), dest) + .call(stdout = os.Inherit, stderr = os.Inherit) } log.info(s"Docker build completed ${if (result.exitCode == 0) "successfully" else "unsuccessfully"} with ${result.exitCode}") From 44cf6044dc0a767d09ab2ba8bd5a3c1892c0b803 Mon Sep 17 00:00:00 2001 From: Georg Ofenbeck - taaofge1 Date: Sat, 4 May 2024 12:53:53 +0200 Subject: [PATCH 6/6] fix of the accidental commited local reformat --- .../mill/contrib/docker/DockerModule.scala | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/contrib/docker/src/mill/contrib/docker/DockerModule.scala b/contrib/docker/src/mill/contrib/docker/DockerModule.scala index cde659281bf..90e0c0943f7 100644 --- a/contrib/docker/src/mill/contrib/docker/DockerModule.scala +++ b/contrib/docker/src/mill/contrib/docker/DockerModule.scala @@ -85,12 +85,12 @@ trait DockerModule { outer: JavaModule => def user: T[String] = "" /** - * Optional platform parameter, if set uses buildkit to build for specified platform. - * - * See also the Docker docs on - * [[https://docs.docker.com/reference/cli/docker/buildx/build/#platform]] - * for more information. - */ + * Optional platform parameter, if set uses buildkit to build for specified platform. + * + * See also the Docker docs on + * [[https://docs.docker.com/reference/cli/docker/buildx/build/#platform]] + * for more information. + */ def platform: T[String] = "" /** @@ -164,14 +164,23 @@ trait DockerModule { outer: JavaModule => val (pull, _) = pullAndHash() val pullLatestBase = IterableShellable(if (pull) Some("--pull") else None) - val result = if (platform().isEmpty || executable() != "docker") { - if (platform().nonEmpty) log.info("Platform parameter is ignored when using non-docker executable") + if (platform().nonEmpty) + log.info("Platform parameter is ignored when using non-docker executable") os.proc(executable(), "build", tagArgs, pullLatestBase, dest) - .call(stdout = os.Inherit, stderr = os.Inherit) + .call(stdout = os.Inherit, stderr = os.Inherit) } else { - os.proc(executable(),"buildx", "build", tagArgs, pullLatestBase, "--platform", platform(), dest) - .call(stdout = os.Inherit, stderr = os.Inherit) + os.proc( + executable(), + "buildx", + "build", + tagArgs, + pullLatestBase, + "--platform", + platform(), + dest + ) + .call(stdout = os.Inherit, stderr = os.Inherit) } log.info(s"Docker build completed ${if (result.exitCode == 0) "successfully" else "unsuccessfully"} with ${result.exitCode}")