This repository contains the FastAPI backend service for the Luonnonmetsäkartat applet on Avoin Map. Its main functionality is to handle data management of forest areas, layers, and images for administrators of the Luonnonmetsäkartat-applet. This service integrates with several external services.
- Framework: FastAPI
- Database: PostgreSQL with PostGIS for spatial data storage.
- Database Migrations: Alembic
- Authentication: Zitadel for OIDC-based authentication.
- Map Publishing: GeoServer
- File Storage: S3-compatible object storage.
- Containerization: Docker & Docker Compose
The application is designed to be run using Docker Compose, which orchestrates the application container and its database dependencies.
- Docker
- Docker Compose
-
Create Environment File: Copy the template file to create your local environment configuration.
cp .env.template .env
-
Set Compose Profile: Open the
.envfile and set theCOMPOSE_PROFILESvariable. For most development work,sandboxis the recommended profile.# .env COMPOSE_PROFILES=sandbox # dev, sandbox, or prod
-
Configure Sandbox Environment: The
sandboxprofile connects the service to shared sandbox instances of PostGIS, GeoServer, and S3 storage. This is the most effective way to develop, as it mirrors the production setup.IMPORTANT: Fill in the environment variables in your
.envfile with the credentials for the sandbox environment, not the production ones. This includesPOSTGRES_*,GEOSERVER_*, andZITADEL_*variables.
Use Docker Compose to build and run the services defined in your selected profile.
# Build and run the services in the background
docker-compose up --build -dTo see logs from the running containers:
docker-compose logs -fThis project includes a template for a VS Code Dev Container, providing a fully configured and consistent development environment.
- Rename the Template: In the
.devcontainerdirectory, renamedevcontainer.template.jsontodevcontainer.json. - Configure Profile: Open
devcontainer.jsonand ensure theserviceandrunServicesproperties match your desired profile (e.g.,app-sandbox). - Launch: Open the project folder in VS Code and use the command "Dev Containers: Reopen in Container". This will build the Docker environment and connect your VS Code instance to the running application container.
In the dev and sandbox profiles, a Jupyter Notebook server is also started. This provides a powerful environment for interactive testing, data exploration, and prototyping new features.
- Access: Navigate to
http://localhost:<NOTEBOOK_PORT>in your browser (e.g.,http://localhost:8888if using the default port from.env.template). - Authentication: You will be prompted for a token. Use the value of
NOTEBOOK_TOKENfrom your.envfile.
The notebooks/ directory is mounted into the container, so you can create and edit notebooks locally, and they will be available in the Jupyter environment.
Database schema changes are managed with Alembic. To generate or apply migrations, you need to run commands inside the application container.
-
Access the container shell:
docker-compose exec app-sandbox bash -
Run Alembic commands:
# Auto-generate a new migration script based on model changes poetry run alembic revision --autogenerate -m "Your migration description" # Apply the latest migrations to the database poetry run alembic upgrade head
The project uses a hybrid testing strategy:
- Local Tests: A dedicated test database (
postgis-test) is included in thedocker-compose.ymlfor running local unit and integration tests that do not require external services. - Sandbox Tests: The most important tests are run against the live sandbox environment. This ensures that the integrations with PostGIS, GeoServer, and other services are working correctly. These tests are typically located in files like
main_prod_test.pyandgeoserver_prod_test.py.
Please be aware that running the complete test suite, especially the sandbox tests, requires access to specific test datasets. This data is not included in this public repository and cannot be made public. To gain access to the test