From 70c763bd71b116b6229221013fa9770e7727240a Mon Sep 17 00:00:00 2001 From: Drew Brokke Date: Fri, 5 Dec 2025 17:01:52 -0600 Subject: [PATCH] LPD-73548 templates: conditionally adds the archive flag if Docker is not running in rootless mode --- .../scripts/deploy_part.build.gradle.template | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/templates/scripts/deploy_part.build.gradle.template b/templates/scripts/deploy_part.build.gradle.template index e5ff3475..d19c2ba3 100644 --- a/templates/scripts/deploy_part.build.gradle.template +++ b/templates/scripts/deploy_part.build.gradle.template @@ -3,11 +3,34 @@ deploy { String projectName = "{{PROJECT_NAME}}" String composedArchive = "${destinationDir}/${liferay.deployedFileNameClosure.call(jar)}" - ExecOutput execOutput = providers.exec { - commandLine "docker", "compose", "-p", projectName, "cp", "--archive", composedArchive, "liferay:/opt/liferay/deploy" + List commandArgs = ["docker", "compose", "-p", projectName, "cp"] + + ByteArrayOutputStream out = new ByteArrayOutputStream() + + project.exec { + commandLine "docker", "info", "--format", "json" + standardOutput = out + } + + groovy.json.JsonSlurper jsonSlurper = new groovy.json.JsonSlurper() + + Object dockerInfo = jsonSlurper.parse(out.toByteArray()) + + boolean rootless = dockerInfo['SecurityOptions'].any { + it.contains("name=rootless") } + if (!rootless) { + commandArgs.add("--archive") + } + + commandArgs.addAll([composedArchive, "liferay:/opt/liferay/deploy"]) + logger.lifecycle("Copying jar to Docker container...") - logger.lifecycle(execOutput.standardError.asText.get().trim()) + logger.lifecycle("Using command: ${commandArgs.join(" ")}") + + project.exec { + commandLine commandArgs + } } }