Claude Prompts to create and deploy Dockerized Springboot Backend

This post will show the steps I took to generate a Spring Boot REST API for this javablog. The API consists of a "hello javablog" RESTful get. That's enough to involve a lot of moving parts including (maven, Spring Boot, GitHub Actions and secrets, nginx reverse proxy, Cloudflare ssl/dns, ssh keys). To my knowledge (cutoff point now), there is no way that a coding agent can do all of this yet. I assume that MCPs will come to take away some of this pain in the future. Perhaps instead of MCPs the coding agent will use its own DNS/SSL setup. That will play out in the near future - watch out Cloudflare!

As you can see in this example, the first draft from Claude was a bust. I had to delete it and then use the Spring Website: Spring Initializr to create an example of what I wanted. I pasted the generated pom.xml into the Claude window to show exactly what I wanted (another MCP opportunity). This worked fine and my "hello javablog" was born.

The failed first attempt delivered the wrong major version of Spring Boot despite explicitly asking for it. It wasn't until I deleted the generated code and asked for it with an example that I got what I wanted. Of course this is far from done but insisting upon two kinds of tests (unit test and integration test) means that the desired behavior is repeatable.

The non-Claude activities in this example focus on my Cloudflare account and my Ubuntu API Server. I have firewalled Claude out of these areas because a mistake could cause significant time loss and/or security breaches. I've listed the activities below in case you want to try to follow along.

Github Commits

Activities and Assumptions:

  • you have root access to an Ubuntu server with more than 4GB RAM, 1 CPU and 20GB Disk.
  • your Ubuntu server has docker and nginx installed
  • your DNS and SSL are managed by Cloudflare or a developer-oriented provider
  • follow this nginx example on your server: Leon Dong - Medium - Fast-Setup: Nginx Https Reverse Proxy for Springboot API
  • configure an 'A' record pointing api.yourdomain.com to your IP address.
  • configure "full" SSL between the client, cloudflare, and your nginx server. This means you will need to generate a private key and certificate here:
    Cloudflare -> Select Domain -> SSL/TLS ->Client Certificates

API Demo

Response from https://api.javablog.com/hello:

javablog

Prompts Used

  • "we are going to setup a rest services application to eventually permit comments and feedback for blog posts. As this service will need a database and other services, let's assume it will run in a docker image running inside a docker-compose constructed network. this project will require a sonar and nexus connection - both are already in my maven settings. Use spring boot and rest, jpa, security. version 4.0.2. write a simple hello world "hello javablog" and have the complete maven build test the hello world."
  • "this isn't what I asked for. I specifically asked for rest, jpa and security. You gave me web mvc, jdbc drivers and a load of comments"
  • "this is not what I asked for. Have a look at the generated file I got by using the spring initialzr. this is what i expected and asked for. latest 4.0.2 parent starter, rest, jpa, security and NO MVC. [Pasted text #2 +88 lines]"
  • "we are going to try again - I've deleted your first draft. I want a spring boot REST, JPA, Security application in a single jar, using maven and spring boot 4.0.2. The application should import from spring boot starter parent 4.0.2. there should be a hello "javablog" rest service with a functional unit test using junit jupiter 5+ and a spring boot specific integration test. put this project in the services directory. "
  • "alright - my blogs backend needs to be dockerized - the angular app is delivered via github action to MS Azure. The backend needs to be dockerized not just locally, but the container must be built via a github action that builds the image and makes it available to a server that will use the docker image. For now we will ignore the database and security complexity of hello world. The backend will be served via a nginx proxy at api.javablog.com."
  • "I have podman running locally"
  • "Ok, I've reviewed the api-deploy.yml - it's incomplete. you do not know the server name where we will deploy the backend to yet. why don't we store this as a variable with a public key so the action can communicate with the server - 161.97.175.172"
  • "your instructions are not correct - copy and save as GHCR_TOKEN secret - where? "
  • "aha, now you are giving accurate instructions."
  • "I want the SERVER_HOST and SERVER_USER to also be variables since the script is visible to the world."
  • "done, I added the correct non-root user and the host."
  • "while I did everything you asked, the script fails to deploy. [error log from GitHub Actions showing ssh: no key found]"
  • "there is no passphrase"
  • "the problem was the spaces in the key. When I put the key in the api-deploy.yml incorrect spacing was added. the hello world is visible on my server now."
  • "we are not done yet. I updated the dns and ssl settings and the hello javablog is available via https://api.javablog.com/hello using the 'full' ssl option and an nginx proxy with the certificates provided by Cloudflare. Lets hook the blog up to show hello - then response. For this we need to start a new post. As before, the post should be top most in the list. We are not concerned with anything other than following the previous patterns at this point. Create a post titled Post 3, with placeholder body Post Body 3, and the demo calling the hello world, then all of the prompts used to get to this point."

Comments

Comments are for feedback on this specific post. For general questions, please use Stack Overflow. Comments may be removed after one year.

No comments yet. Be the first to share your thoughts!