This is a demo Python server written with FastAPI. The server connects to PostgreSQL and exposes Prometheus metrics.
The server is packaged as a "rock" using Canonical's OCI-compliant format for container images.
You'll need Rockcraft and Docker.
By default, Docker requires sudo. To use Docker as a regular user, run sudo usermod -aG docker $USER then log out and log back in again.
-
Build the container image from source:
rockcraft packThis creates a
.rockfile. The name of the.rockfile depends on your system architecture. -
Make the container image available to Docker:
rockcraft.skopeo --insecure-policy \ copy "oci-archive:<rock>" "docker-daemon:api-demo-server:integration"Where
<rock>is the path to the.rockfile. -
Run the container image alongside PostgreSQL:
docker compose up -
In a separate terminal, check that the server is available:
curl http://localhost:8000/versionThis returns a JSON object that contains the server's version number.
The server has several other API endpoints, including:
- API docs - http://localhost:8000/docs
- Prometheus metrics - http://localhost:8000/metrics
If you modify the server, rebuild the container image and run the PostgreSQL integration tests:
rockcraft pack
make integration
The integration tests require Docker.
Alternatively, run rockcraft test. This builds the container image and runs the integration tests inside a LXD container. It's slower, but you don't need Docker on your system.
DEMO_SERVER_LOGFILE- Path to the file where logs should be writtenDEMO_SERVER_DB_HOST- IP address of the database hostDEMO_SERVER_DB_PORT- Port of the database hostDEMO_SERVER_DB_USER- Username that has access to the databaseDEMO_SERVER_DB_PASSWORD- Password for theDEMO_SERVER_DB_USERuser