Can I build spring-native boot image in low resources machine (like AWS CodeBuild Linux Small 2vCPUs / 3gb ram)?

390 Views Asked by At

I want to build boot build image for GraalVM spring native project using AWS CodeBuild called from AWS CodePipeline, but the build process stops at missing RAM resources. I tried the default spring builder and the following one: paketobuildpacks/builder:tiny.

The specification of the machine is Linux Small - BUILD_GENERAL1_SMALL - LINUX_CONTAINER 3 GB RAM, 2 vCPUs and 64 GB of disk space. The image of the environment is aws/codebuild/standard:6.0.

At my local MacBook M1 Pro, it takes around 5.5 GB of ram (checked in Docker Desktop stats), so I tried at the second plan of BUILD_GENERAL1_MEDIUM as well, and the process went couple lines further, but at the end it was killed as well.

The partial stack trace can be found below (must be cut due to SO spam limits):

> Task :infrastructure:bootBuildImage
Building image 'docker.io/library/experiences-service:latest'
    [creator]     [1/7] Initializing...                                           (12.1s @ 0.56GB)
    [creator]      Version info: 'GraalVM 22.3.0 Java 17 CE'
    [creator]      Java version info: '17.0.5+8-LTS'
    [creator]      C compiler: gcc (linux, x86_64, 7.5.0)
    [creator]      Garbage collector: Serial GC
    [creator]      1 user-specific feature(s)
    [creator]      - org.springframework.aot.nativex.feature.PreComputeFieldFeature
    [creator]     The bundle named: i18n.Parsing, has not been found. If the bundle is part of a module, verify the bundle name is a fully qualified class name. Otherwise verify the bundle path is accessible in the classpath.
    [creator]     The bundle named: i18n.Scalars, has not been found. If the bundle is part of a module, verify the bundle name is a fully qualified class name. Otherwise verify the bundle path is accessible in the classpath.
    [creator]     [2/7] Performing analysis...  [**********]                     (114.5s @ 2.31GB)
    [creator]       28,561 (93.30%) of 30,612 classes reachable
    [creator]       44,044 (68.12%) of 64,654 fields reachable
    [creator]      130,512 (64.11%) of 203,567 methods reachable
    [creator]        1,232 classes,   473 fields, and 5,577 methods registered for reflection
    [creator]           82 classes,    76 fields, and    64 methods registered for JNI access
    [creator]            4 native libraries: dl, pthread, rt, z
    [creator]     OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000006b5380000, 1065353216, 0) failed; error='Not enough space' (errno=12)
    [creator]     #
    [creator]     # There is insufficient memory for the Java Runtime Environment to continue.
    [creator]     # Native memory allocation (mmap) failed to map 1065353216 bytes for committing reserved memory.
    [creator]     # An error report file with more information is saved as:
    [creator]     # /layers/paketo-buildpacks_native-image/native-image/hs_err_pid178.log
    [creator]     Error: Image build request failed with exit status 1
    [creator]     unable to invoke layer creator
    [creator]     unable to contribute native-image layer

Sometimes the process is finished by code 137:

[creator]     [2/7] Performing analysis...  [**********]                     (122.4s @ 3.24GB)
    [creator]       28,561 (93.30%) of 30,612 classes reachable
    [creator]       44,044 (68.12%) of 64,654 fields reachable
    [creator]      130,512 (64.11%) of 203,565 methods reachable
    [creator]        1,232 classes,   473 fields, and 5,577 methods registered for reflection
    [creator]           82 classes,    76 fields, and    64 methods registered for JNI access
    [creator]            4 native libraries: dl, pthread, rt, z
    [creator]     Error: Image build request failed with exit status 137

I tried to pass some limits of resources using

  • passing arguments to the gradle using gradle.properties: org.gradle.jvmargs=-Xmx512m
  • passing argument JAVA_TOOL_OPTIONS and BPL_JVM_THREAD_COUNT to the BuildBootImage gradle tasks using the following code. In the logs the limit is logged but there is nothing in results.
    tasks.withType<org.springframework.boot.gradle.tasks.bundling.BootBuildImage> {
        if (org.apache.tools.ant.taskdefs.condition.Os.isArch("aarch64")) {
            builder.set("dashaun/java-native-builder-arm64:latest")
        } else {
            builder.set("paketobuildpacks/builder:tiny")
        }
        environment.set(
            mapOf(
                "JAVA_TOOL_OPTIONS" to "-Xmx512m",
                "BPL_JVM_THREAD_COUNT" to "50",
                "BP_NATIVE_IMAGE" to "true",
                "BP_JVM_VERSION" to "17",
                "BP_NATIVE_IMAGE_BUILD_ARGUMENTS" to "--initialize-at-run-time=io.netty.handler.ssl.BouncyCastleAlpnSslUtils"
            )
        )
        imageName.set(rootProject.name)
    }

I am looking for any option to pass to the Docker environment or paketobuildpacks to limit used resources?

0

There are 0 best solutions below