I wrote this very simple app for a blog post I wrote to demonstrate using OpenRewrite for automated refactoring, and deploying an app to an edge node running EVE-OS.
A Makefile offers the following targets:
make clean
: Runmvn clean
and cleanup Docker environment.make package
: Runmvn package
to build the JAR file.make container
: Build the Docker container and run it locally.- (This doesn't not handle publishing to a container registry.)
make rewrite
: Run the specified OpenRewrite recipes.
I used OpenRewrite to refactor this code and fix three primary things:
- Use the newer dedicated
@GetMapping
as an alternative for@RequestMapping
- Use the SLF4J Logger instead of the basic
System.out.println
- Upgrade from Spring Boot 2.x to 3.x
Everything can be built, refactored, and run locally using the make
command.
Since I wrote this for a blog post that also detailed the deployment to an edge node, I've outlined those steps here as well. Once the app is built (and published to a container registry like Docker Hub), the following steps will deploy it to a local virtualized instance running EVE-OS to simulate an edge node.
I mostly followed this EVE Tutorial which was extremely helpful. However, it was written for Linux and I ran into a few snags that didn't work on MacOS which is the environment I used. As such, I ended up forking the eden
code and tweaking a few minor things just to get everything to work. It was mostly around getting the qemu
environment to run correctly. You can see the specifics here in the forked repo. And of course, instead of running the default nginx
deployment to test things, I deployed this Spring app. I also found I needed to specifically configure additional port forwarding in order to reach the deployed app.
I installed all the following prerequisites if they weren't already installed, using brew
where possible, or otherwise downloading and installing.
make
qemu
go
docker
jq
git
- Start required
qemu
containers:
$ docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
- Build Eden (I used my fork as indicated above):
$ git clone https://github.com/bryanfriedman/eden.git && cd eden/
$ make clean
$ make build-tests
- Setup Eden configuration and prepare port 8080 for our app:
$ ./eden config add default
$ ./eden config set default --key eve.hostfwd --value '{"8080":"8080"}'
$ ./eden setup
- Activate Eden:
$ tcsh
$ source ~/.eden/activate.csh
- Check status, then onboard EVE:
$ ./eden status
$ ./eden eve onboard
$ ./eden status
- Deploy the Spring app from Docker Hub:
$ ./eden pod deploy --name=eve_spring docker://bryanfriedman/legacy-spring-app -p 8080:80
- Wait for the pod to come up:
$ watch ./eden pod ps
- Make sure it works:
$ curl http://localhost:8080