https://kotlinlang.org logo
#http4k
Title
# http4k
s

snowe

12/02/2023, 12:02 AM
I’m trying to get http4k compiling with graalvm to deploy to aws lambda. I’m looking at the example
graalvm
in the examples repo and just trying to compile that (I have already been trying with my own app for hours lol) and I’m getting the following error message:
Copy code
0.0s
 => ERROR [graalvm 2/5] RUN gu install native-image                                                                                                                                                                                                                                           1.6s
------                                                                                                                                                                                                                                                                                             
 > [graalvm 2/5] RUN gu install native-image:
0.565 Downloading: Release index file from <http://oca.opensource.oracle.com|oca.opensource.oracle.com>
1.513 Error: Error reading component list: <https://oca.opensource.oracle.com/gds/meta-data.json>
------
Dockerfile:2
--------------------
   1 |     FROM <http://ghcr.io/graalvm/graalvm-ce:java11-21.3.0|ghcr.io/graalvm/graalvm-ce:java11-21.3.0> as graalvm
   2 | >>> RUN gu install native-image
   3 |     
   4 |     COPY . /home/app/http4k-example
--------------------
ERROR: failed to solve: process "/bin/sh -c gu install native-image" did not complete successfully: exit code: 3
I change the ce container to 22 and it gets further
Copy code
FROM <http://ghcr.io/graalvm/graalvm-ce:22|ghcr.io/graalvm/graalvm-ce:22> as graalvm
but then I get java errors.
Copy code
1.759 Fatal error: java.lang.UnsupportedClassVersionError: com/example/HelloWorldKt has been compiled by a more recent version of the Java Runtime (class file version 62.0), this version of the Java Runtime only recognizes class file versions up to 61.0
so then I switch to java17 graalvm 22
Copy code
❯ asdf local java graalvm-22.3.1+java17
that leads to
Copy code
0.0s
 => [graalvm 3/5] COPY . /home/app/http4k-example                                                                                                                                                                                                                                             0.0s
 => [graalvm 4/5] WORKDIR /home/app/http4k-example                                                                                                                                                                                                                                            0.0s
 => [graalvm 5/5] RUN native-image --no-fallback --no-server -cp build/libs/Example-all.jar com.example.HelloWorldKt                                                                                                                                                                         35.4s
 => [stage-1 3/3] COPY --from=graalvm /home/app/http4k-example/com.example.helloworldkt /app/http4k-example                                                                                                                                                                                   0.1s
 => exporting to image                                                                                                                                                                                                                                                                        0.0s 
 => => exporting layers                                                                                                                                                                                                                                                                       0.0s 
 => => writing image sha256:86d8a2b414461509200613c7d388f9a0e91a759f6e7b22d9f466a924e7053a29                                                                                                                                                                                                  0.0s 
 => => naming to <http://docker.io/library/http4k-graal-example|docker.io/library/http4k-graal-example>                                                                                                                                                                                                                                       0.0s 
                                                                                                                                                                                                                                                                                                   
What's Next?
  1. Sign in to your Docker account → docker login
  2. View a summary of image vulnerabilities and recommendations → docker scout quickview
Running http4k on GraalVM...
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
exec /app/http4k-example: no such file or directory
the amd64 thing shouldn’t be causing problems, so it seems like the
copy --from=graalvm
is causing issues. Not sure what issues though. But weirdly I am getting a completely different error in my project. This is already too long so I’ll paste that error in the thread.
Copy code
0.0s
 => CACHED [graalvm 4/5] WORKDIR /home/app/http4k-example                                                                                                                                                                                                     0.0s
 => ERROR [graalvm 5/5] RUN native-image --no-fallback --no-server -cp build/libs/projectname-1.0.0-SNAPSHOT.jar.jar com.sunrun.pricing.lambda.Http4kFnKt                                                                                                     1.5s
------                                                                                                                                                                                                                                                             
 > [graalvm 5/5] RUN native-image --no-fallback --no-server -cp build/libs/projectname-1.0.0-SNAPSHOT.jar.jar com.sunrun.pricing.lambda.Http4kFnKt:
0.133 Warning: Ignoring server-mode native-image argument --no-server.
1.482 ========================================================================================================================
1.482 GraalVM Native Image: Generating 'com.sunrun.pricing.lambda.http4kfnkt' (executable)...
1.482 ========================================================================================================================
1.485 [1/7] Initializing...                                                                                    (0.0s @ 0.14GB)
1.486 Error: Main entry point class 'com.sunrun.pricing.lambda.Http4kFnKt' neither found on the classpath nor on the modulepath.
1.486 modulepath: '/opt/graalvm-ce-java17-22.3.3/lib/svm/library-support.jar'
1.487 Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
1.511 Error: Image build request failed with exit status 1
------
Dockerfile:7
--------------------
   5 |     WORKDIR /home/app/http4k-example
   6 |     
   7 | >>> RUN native-image --no-fallback --no-server -cp build/libs/projectname-1.0.0-SNAPSHOT.jar.jar com.sunrun.pricing.lambda.Http4kFnKt
   8 |     
   9 |     FROM frolvlad/alpine-glibc
--------------------
ERROR: failed to solve: process "/bin/sh -c native-image --no-fallback --no-server -cp build/libs/projectname-1.0.0-SNAPSHOT.jar.jar com.sunrun.pricing.lambda.Http4kFnKt" did not complete successfully: exit code: 1
is the error I’m getting in my code.
Copy code
FROM <http://ghcr.io/graalvm/graalvm-ce:22|ghcr.io/graalvm/graalvm-ce:22> as graalvm
RUN gu install native-image

COPY . /home/app/http4k-example
WORKDIR /home/app/http4k-example

RUN native-image --no-fallback --no-server -cp build/libs/projectname-1.0.0-SNAPSHOT.jar.jar com.sunrun.pricing.lambda.Http4kFnKt

FROM frolvlad/alpine-glibc
RUN apk update && apk add libstdc++
EXPOSE 8080
COPY --from=graalvm /home/app/http4k-example/com.sunrun.pricing.lambda.http4kfnkt /app/http4k-example
ENTRYPOINT ["/app/http4k-example"]
is my dockerfile. I’ve verified that the
META-INF/manifest.mf
file is referencing the correct class. I’ve checked that the zip is there. I check that it’s named correctly. Not sure what the issue is here.
d

dave

12/02/2023, 1:29 PM
the new versions of graal have "helpfully| removed the old image files. I've updated the example to use:
Copy code
FROM ghcr.io/graalvm/native-image:21 as graalvm
... which builds the native image (but doesn't run on my M1 mac).
If you're targeting AWS lambda on Graal then you could also try following this guide: https://www.http4k.org/guide/tutorials/going_native_with_graal_on_aws_lambda/
s

snowe

12/04/2023, 5:15 PM
Hm. even after pulling your changes I still get
Copy code
Running http4k on GraalVM...
exec /app/http4k-example: no such file or directory
when running
./build_and_run.sh
Here’s the full log
Untitled
And yeah I’ve read that guide, that’s what I’ve been following but then got strange errors I couldn’t get around, so I came back to try the examples repo.
d

dave

12/04/2023, 5:27 PM
Yes - (I think) that's because of the architecture mismatch. The file is actually inside the image, but it can't boot within the final container.
Are you on Apple Silicon?
s

snowe

12/04/2023, 5:28 PM
yeah, M1.
interesting.. So with quarkus I’m able to build on m1 and run on m1 just fine. I do have to use the mandrel images rather than direct graalvm images though.
d

dave

12/04/2023, 5:31 PM
This banner makes me think working on ARM is a thing with those images.. 😂
s

snowe

12/04/2023, 5:31 PM
lol yeah.
strange that the error would be that there’s no such file or directory? I’ve had architecture mismatches with our quarkus code before and it always gives a library error around dylib or stuff like that.
really weird error with mandrel.
@dave switching to
FROM <http://ghcr.io/graalvm/native-image-community:21|ghcr.io/graalvm/native-image-community:21> as graalvm
allowed the build to succeed and the code to run on m1
oh i also added
--static
at line 6. not sure that’s needed. let me test without
d

dave

12/05/2023, 3:45 PM
if you could PR it that would be amazing if you get it working ❤️
s

snowe

12/05/2023, 3:45 PM
will do!
d

dave

12/05/2023, 5:41 PM
have had a play. Looks like the minimal Dockerfile is just: 🙃
Copy code
FROM <http://ghcr.io/graalvm/native-image-community:21|ghcr.io/graalvm/native-image-community:21> as graalvm

COPY . /home/app/http4k-example
WORKDIR /home/app/http4k-example

RUN native-image --static --no-fallback -cp build/libs/example.jar com.example.HelloWorldKt

FROM frolvlad/alpine-glibc
EXPOSE 8080
COPY --from=graalvm /home/app/http4k-example/com.example.helloworldkt /app/http4k-example
ENTRYPOINT ["/app/http4k-example"]
(I've updated the repo so don't worry about the PR 🙂 )
s

snowe

12/05/2023, 5:41 PM
Oops. I didn’t make the PR haha
i was done with it but had several meetings in a row
d

dave

12/05/2023, 5:42 PM
no worries -thanks for the pointers anyway!
s

snowe

12/05/2023, 5:42 PM
sure thing
Ok, I finally got it all running/working, except an error in aws when running there. I’ll post that in the main channel, instead of this thread.
👍 1
32 Views