FastAPI and Spring Boot Admin in Docker Compose
Overview⚓︎
The pyctuator github page explains that while "many Java shops use Spring Boot as their main web framework ... and Spring Boot Admin to monitor their microservicess", often their is a need to "integrate a couple of Python microservices". Pyctuator "allows you to easily integrate your Python microservices into your existing Spring Boot Admin deployment."
I found myself in this situation recently, with a fastAPI application that needed to be integrated into a sea of java spring apps. Being able to integrate this application into the existing Spring Boot Admin application significantly reduced resistance associated with using a different technology.
In this blog post I will demostrate setting up a FastAPI application to work with Spring Boot Admin. Its pretty straight forward.
Demo⚓︎
The required directory / file structure looks like this
. base directory
├── docker-compose.yml
├── main.py ## this file is our sample FastAPI application
└── Dockerfile ## this file builds our FastAPI application
main.py
from fastapi import FastAPI
from pyctuator.pyctuator import Pyctuator
app = FastAPI(title="FastAPI Sample App")
@app.get("/")
def hello():
return {"sample": "response"}
Pyctuator(
app,
"FastAPI Sample App",
app_url="http://app:80",
pyctuator_endpoint_url="http://app:80/pyctuator",
registration_url="http://spring-admin:8080/instances"
)
Dockerfile
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7
RUN pip install --no-cache-dir pyctuator
COPY ./main.py /app/main.py
Docker-Compose
version: "2.2"
services:
app:
build:
context: ./
ports:
- 80:80
networks:
- test
spring-admin:
image: michayaak/spring-boot-admin:2.2.3-1
ports:
- 8080:8080
networks:
- test
networks:
test:
Once the files have been created just run docker-compose up
and the sample FastAPI app and the Spring Boot Admin app will both boot up. Now open your browser and open
http://localhost:80/docs
to see the sample FastAPI applicationhttp://localhost:8080
to see the Spring Boot Admin app
The below screenshots show the Sample FastAPI App within Spring Boot Admin.
That was easy - wasn't it?