1
votes

I have built an API in Micronaut and trying to deploy in it GCP Cloud Run as a native graalVM image

This is my Dockerfile

# Stage 1: Build the JAR
FROM gradle:jdk11 as gradle
COPY --chown=gradle . /home/app
WORKDIR /home/app
RUN gradle assemble --no-daemon

# Stage 2: Build the native image
FROM ghcr.io/graalvm/graalvm-ce:latest as graalvm
RUN \
    # Install GraalVM Native Image
    gu install native-image;
COPY --from=gradle /home/app/build/libs/greetings-cloud-run-0.1-all.jar /home/app/server.jar
WORKDIR /home/app
RUN native-image -H:Name=greetings-cloud-run --no-server -cp server.jar com.arun.Application


# Stage 3: Prepare Server
FROM frolvlad/alpine-glibc
RUN apk update && apk add libstdc++
EXPOSE 8080
COPY --from=graalvm /home/app/greetings-cloud-run .
ENTRYPOINT ["./greetings-cloud-run"]

I checked till Stage-2 and the native image is running perfectly fine. I included Stage-3 to run my native-image and ending up with below error

$ docker run a/micro                                                                                                                                  
./greetings-cloud-run: /usr/lib/libstdc++.so.6: no version information available (required by ./greetings-cloud-run)
./greetings-cloud-run: Relink `/usr/lib/libgcc_s.so.1' with `/usr/glibc-compat/lib/libc.so.6' for IFUNC symbol `memset'

Need help on how to run my Native image

1
You could try using the Red Hat distoless UBI for quarkus-native if you are willing to switch base images. - Turing85
Thanks .. mine is based out of Micronaut not quarkus - Arun
This should not matter. - Turing85
ah ok. so you mean, i can just have this image for my stage-3 ? - Arun
Yes. The RUN apk ... can be removed and instead, one could add USER nonroot (see quarkus documentation on distoless base images). Rest should work as-is. - Turing85

1 Answers

0
votes

It should be standard thing in Micronaut docs,

try https://guides.micronaut.io/latest/micronaut-creating-first-graal-app-maven-java.html

5.2. Creating native image inside Docker
The output following this approach is a Docker image that runs the native image of your application. You don’t need to install any additional dependencies.

Building GraalVM native image with Maven
$ ./mvnw package -Dpackaging=docker-native