Spring Boot + Jib + Google Cloud Run + Stack driver debugging

Yeah - there'e no elegant title to this if I want you to understand what exactly you're about to dive into.  It is exactly what it says.  A breif, high-level overview of getting Stack Driver Debugger working on a Spring boot project in Google Cloud Run using jib.  This is not in depth, but much more of an overview of how I got the basics working.

I don't wanna waste a lot of your time, or mine, writing about what each of these things is or does.  If you are here you are probably already familiar with each technology but may be looking to solve this exact use-case.  Or you're bored and wanted to read up.  Either way, while this is basic, it is not ground zero basic.

There were a few good resources that enabled me to get down this path:

Step 1: Download and unzip the stackdriver agent

RUN mkdir /opt/cdbg && \
    wget
-qO- https://storage.googleapis.com/cloud-debugger/compute-java/debian-wheezy/cdbg_java_agent_gce.tar.gz | \
    tar xvz
-C /opt/cdbg---

You'll notice that the first thing we need to do is download the stackdriver agent.  For the time being I did this manually and put it in my repository under my jib directory.  You may have seen an earlier entry about how to copy things into your contianer at build time, but if not here's a little refresher.  It's really easy.  Just put them in a jib directory under src/main/jib.

todo: make the download and unzip of the agent part of my build process so I dont have to check it in.  This assures I get the latest version if it should ever change 

Step 2: Add the agent path to the startup call

RUN  java -agentpath:/opt/cdbg/cdbg_java_agent.so \
   
-jar PATH_TO_JAR_FILE

Jib makes this easy with their extended use properties, in particular the jvmFlags setting.  

jib {
to {
image= "<path to my image repo>"
tags= ['catalog-service-jib']
}
container {
environment=[GOOGLE_APPLICATION_CREDENTIALS: './cred/logging_service_account.json', SPRING_PROFILES_ACTIVE: 'cloud']
ports= ['8080']
jvmFlags = ['-agentpath:./opt/cdbg/cdbg_java_agent.so']
}
}

If you watch closely as your gradle jibdockerbuild step runs you'll notice that it takes care of setting a lot of stuff for you:

Container entrypoint set to [java, -agentpath:./opt/cdbg/cdbg_java_agent.so,  -cp, /app/resources:/app/classes:/app/libs/*, com.insightdi.refarch.catalogservice.CatalogServiceApplication]

Step 3: Enjoy Logging and debugging through GCP

Once I deploy my application in cloud build I can now set breakpoints and add logging statements right through the either the old or the new stack driver debugging interface which ties in nicely with the google cloud source repositories.

Happy debugging

Comments