Skip to content
This repository has been archived by the owner on Apr 2, 2023. It is now read-only.

Add Quarkus Pub/Sub Sample #33

Merged
merged 13 commits into from Oct 29, 2020
Merged

Add Quarkus Pub/Sub Sample #33

merged 13 commits into from Oct 29, 2020

Conversation

dzou
Copy link
Contributor

@dzou dzou commented Oct 22, 2020

Adds a Quarkus Cloud Pub/Sub sample.

Fixes #30

Notes: I think it's possible to test this out (if you want) even if you don't have GraalVM installed. Quarkus offers the mvn package -P graal -Dquarkus.native.container-build=true command which conducts the build in a docker container and you should be able to run the resulting executable after ./target/quarkus-pubsub-sample-1.0.0-SNAPSHOT-runner.

Copy link
Member

@meltsufin meltsufin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool!
Just some minor comments regarding getting the sample running more smoothly.

@@ -0,0 +1,57 @@
####
# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this file auto-generated by something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup - this code was generated from the Quarkus equivalent of Initialzr.

Copy link
Contributor

@elefeint elefeint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome; did not test :)

@dzou
Copy link
Contributor Author

dzou commented Oct 26, 2020

@kostacasa - Hey sorry to bother you. I wanted to ask about your native image builds on Cloud Build. We've been able to get a quarkus sample app working with the Pub/Sub libraries locally (compilation + running), however when we try to build the quarkus app on Cloud Build we seem to get a new error.

I was just curious if you've seen this before and have handled it -- however, if not, no worries! (figure it was worth a shot asking). To me it seemed like it might be a Cloud Build-specific error.

Step #0: Detailed message:
Step #0: Error: Detected a started Thread in the image heap. Threads running in the image generator are no longer running at image run time.  Object has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. The object was probably created by a class initializer and is reachable from a static field. You can request class initialization at image run time by using the option --initialize-at-run-time=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
Step #0: Trace: Object was reached by 
Step #0: 	reading field sun.net.www.http.KeepAliveCache.keepAliveTimer of
Step #0: 		constant sun.net.www.http.KeepAliveCache@2cc2b8b9 reached by 
Step #0: 	reading field sun.net.www.http.HttpClient.kac
Step #0: Error: No instances of java.net.PlainSocketImpl are allowed in the image heap as this class should be initialized at image runtime. Object has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked.
Step #0: Trace: Object was reached by 
Step #0: 	reading field java.net.Socket.impl of
Step #0: 		constant java.net.Socket@226716c8 reached by 
Step #0: 	reading field sun.net.NetworkClient.serverSocket of
Step #0: 		constant sun.net.www.http.HttpClient@3c765f46 reached by 
Step #0: 	reading field sun.net.www.http.KeepAliveEntry.hc of
Step #0: 		constant sun.net.www.http.KeepAliveEntry@ff27720 reached by 
Step #0: 	indexing into array
Step #0: 		constant java.lang.Object[]@6ee171b2 reached by 
Step #0: 	reading field java.util.ArrayDeque.elements of
Step #0: 		constant sun.net.www.http.ClientVector@10200337 reached by 
Step #0: 	reading field java.util.HashMap$Node.value of
Step #0: 		constant java.util.HashMap$Node@3b7ed33b reached by 
Step #0: 	indexing into array
Step #0: 		constant java.util.HashMap$Node[]@1b761920 reached by 
Step #0: 	reading field java.util.HashMap.table of
Step #0: 		constant sun.net.www.http.KeepAliveCache@2cc2b8b9 reached by 
Step #0: 	reading field sun.net.www.http.HttpClient.kac

@kostacasa
Copy link
Contributor

Hello! Interesting, have not seen that specific error unfortunately.

This is the Dockerfile we use for building native images:

## Stage 1 : build with maven builder image with native capabilities
FROM quay.io/quarkus/centos-quarkus-maven:20.1.0-java11 AS build
COPY pom.xml /usr/src/app/
COPY src /usr/src/app/src
COPY .m2 /usr/src/app/.m2
USER root
RUN chown -R quarkus /usr/src/app
USER quarkus
ENV JAVA_OPTIONS="-XshowSettings:vm"
ENV MAVEN_OPTS=-Xmx8G
RUN mvn -f /usr/src/app/pom.xml -Dmaven.repo.local=/usr/src/app/.m2/repository -Pnative deploy

## Stage 2 : create the docker final image
FROM registry.access.redhat.com/ubi8/ubi-minimal
WORKDIR /work/
COPY --from=build /usr/src/app/target/*-runner /work/application

# set up permissions for user `1001`
RUN chmod 775 /work /work/application \
  && chown -R 1001 /work \
  && chmod -R "g+rwX" /work \
  && chown -R 1001:root /work

EXPOSE 8080
USER 1001

CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]

And our cloud build step is just a simple docker builder execution (we pull .m2 cache first).

    # Retrieve the cached .m2 directory from GCS
    -   name: 'gcr.io/cloud-builders/gsutil'
        entrypoint: bash
        args:
            - '-c'
            - |
                mkdir -p .m2/repository/
                cd .m2/repository/
                gsutil cp gs://m2_cache/$REPO_NAME.tar .
                if [ -f "$REPO_NAME.tar" ]; then
                    echo "Extracting archive"
                    tar -xf $REPO_NAME.tar
                    echo "Extracted"
                    rm $REPO_NAME.tar
                    ls
                fi
                true

    -   name: gcr.io/cloud-builders/docker
        args:
            - build
            - '--file=src/main/docker/Dockerfile.multistage'
            - '--tag=$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME:$SHORT_SHA'
            - '--network=cloudbuild'
            - '.'

@dzou
Copy link
Contributor Author

dzou commented Oct 27, 2020

Ahh thanks so much, this is very helpful. I think what might be missing for us is maybe we should also try using the quay.io Quarkus images. Appreciate the tip @kostacasa

Copy link
Member

@meltsufin meltsufin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great! (I didn't try the compiled version though.)

@dzou dzou dismissed elefeint’s stale review October 29, 2020 00:19

Changes addressed!

@dzou dzou merged commit 07c2487 into master Oct 29, 2020
@dzou dzou deleted the add-quarkus-sample branch October 29, 2020 00:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement a working sample for Quarkus
5 participants