@@ -27,7 +27,7 @@ object GraalVMNativeImagePlugin extends AutoPlugin {
2727
2828 import autoImport ._
2929
30- private val GraalVMBaseImage = " ghcr.io/graalvm/graalvm-ce "
30+ private val GraalVMBaseImagePath = " ghcr.io/graalvm/"
3131
3232 override def requires : Plugins = JavaAppPackaging
3333
@@ -48,9 +48,20 @@ object GraalVMNativeImagePlugin extends AutoPlugin {
4848 includeFilter := " *" ,
4949 resources := resourceDirectories.value.descendantsExcept(includeFilter.value, excludeFilter.value).get,
5050 UniversalPlugin .autoImport.containerBuildImage := Def .taskDyn {
51+ val splitPackageVersion = " (.*):(.*)" .r
5152 graalVMNativeImageGraalVersion.value match {
52- case Some (tag) => generateContainerBuildImage(s " $GraalVMBaseImage: $tag" , graalVMNativeImagePlatformArch.value)
53- case None => Def .task(None : Option [String ])
53+ case Some (splitPackageVersion(packageName, tag)) =>
54+ packageName match {
55+ case " graalvm-community" => Def .task(Some (s " $GraalVMBaseImagePath$packageName: $tag" ): Option [String ])
56+ case _ =>
57+ generateContainerBuildImage(
58+ s " ${GraalVMBaseImagePath }graalvm-ce: $tag" ,
59+ graalVMNativeImagePlatformArch.value
60+ )
61+ }
62+ case Some (tag) =>
63+ generateContainerBuildImage(s " ${GraalVMBaseImagePath }graalvm-ce: $tag" , graalVMNativeImagePlatformArch.value)
64+ case None => Def .task(None : Option [String ])
5465 }
5566 }.value,
5667 packageBin := {
@@ -140,21 +151,26 @@ object GraalVMNativeImagePlugin extends AutoPlugin {
140151 image : String ,
141152 streams : TaskStreams
142153 ): File = {
143-
154+ import sys . process . _
144155 stage(targetDirectory, classpathJars, resources, streams)
145156
146157 val graalDestDir = " /opt/graalvm"
147158 val stageDestDir = s " $graalDestDir/stage "
148159 val resourcesDestDir = s " $stageDestDir/resources "
149- val platformFlag = platformArch.map(arch => Seq (" --platform" , arch)).getOrElse(Seq .empty)
160+ val hostPlatform =
161+ (dockerCommand ++ Seq (" system" , " info" , " --format" , " {{.OSType}}/{{.Architecture}}" )).!! .trim
150162
151- val command = dockerCommand ++ Seq (" run" ) ++ platformFlag ++ Seq (
163+ val command = dockerCommand ++ Seq (
164+ " run" ,
152165 " --workdir" ,
153166 " /opt/graalvm" ,
154167 " --rm" ,
168+ " --platform" ,
169+ platformArch.getOrElse(hostPlatform),
155170 " -v" ,
156171 s " ${targetDirectory.getAbsolutePath}: $graalDestDir" ,
157172 image,
173+ " native-image" ,
158174 " -cp" ,
159175 (resourcesDestDir +: classpathJars.map(jar => s " $stageDestDir/ " + jar._2)).mkString(" :" ),
160176 s " -H:Name= $binaryName"
@@ -180,9 +196,13 @@ object GraalVMNativeImagePlugin extends AutoPlugin {
180196 platformArch : Option [String ] = None
181197 ): Def .Initialize [Task [Option [String ]]] =
182198 Def .task {
199+ import sys .process ._
200+
183201 val dockerCommand = (DockerPlugin .autoImport.dockerExecCommand in GraalVMNativeImage ).value
184202 val streams = Keys .streams.value
185- val platformValue = platformArch.getOrElse(" local" )
203+ val hostPlatform =
204+ (dockerCommand ++ Seq (" system" , " info" , " --format" , " {{.OSType}}/{{.Architecture}}" )).!! .trim
205+ val platformValue = platformArch.getOrElse(hostPlatform)
186206
187207 val (baseName, tag) = baseImage.split(" :" , 2 ) match {
188208 case Array (n, t) => (n, t)
@@ -208,7 +228,7 @@ object GraalVMNativeImagePlugin extends AutoPlugin {
208228 Cmd (" WORKDIR" , " /opt/graalvm" ),
209229 ExecCmd (" RUN" , " gu" , " install" , " native-image" ),
210230 ExecCmd (" RUN" , " sh" , " -c" , " ln -s /opt/graalvm-ce-*/bin/native-image /usr/local/bin/native-image" ),
211- ExecCmd (" ENTRYPOINT " , " native-image" )
231+ ExecCmd (" CMD " , " native-image" )
212232 ).makeContent
213233
214234 val command = dockerCommand ++ Seq (
@@ -246,7 +266,7 @@ object GraalVMNativeImagePlugin extends AutoPlugin {
246266 val mappings = classpathJars ++ resources.map {
247267 case (resource, path) => resource -> s " resources/ $path"
248268 }
249- Stager .stage(GraalVMBaseImage )(streams, stageDir, mappings)
269+ Stager .stage(GraalVMBaseImagePath )(streams, stageDir, mappings)
250270 }
251271}
252272
0 commit comments