π°οΈQuick Start
Python Docker Quick Start
For most users, the recommended way to use the AISDB Python package is by installing it with pip. The main purpose of the Python docker images in this repository is to provide a build environment for the Python wheel files that can be used for pip installation, as well as providing a reference and testing environment. The meridiancfi/aisdb:latest
image is based on python:slim
with the AISDB package wheel installed. In the meridiancfi/aisdb-manylinux:latest
image, wheel binary files are compiled from Rust and Python source code using a manylinux
base docker image. The Manylinux project aims to provide a convenient way to distribute binary Python extensions as wheels on Linux. To start the container, ensure that docker
and docker-compose
are installed, and enter into the command line:
The current working directory will be mounted inside the container as a volume. The same can be achieved with docker-compose
in the context of the repository compose file:
Compose Services
In addition to the Python AISDB docker image, AISDB provides a complete suite of cloud services for storing, accessing, viewing, and networking AIS data. These services are defined in the docker-compose.yml
file in the project repository. Cloud services are implemented in a microservices architecture, using a software-defined network defined in the compose file. Services include:
docserver
NodeJS webserver to display Sphinx documentation (such as this webpage)
webserver
NodeJS web application front-end interface for AISDB.
postgresdb
AISDB Postgres database storage.
db-
Web application back-end. Serves vectorized AIS tracks from the Postgres database in response to JSON-formatted queries.
receiver
Listens for IP-enabled AIS transmitters over TLS/TCP or UDP channels, and stores incoming AIS messages in the postgres database. Optionally forwards filtered messages to a downstream UDP channel in raw or parsed format.
upstream-ais
Live streaming AIS server. Listens for AIS messages forwarded by the
receiver
service, and reverse-proxy messages to downstream TCP clients or UDP channels. This service provides live-streaming data to the front endwebserver
.
To start all AISDB cloud services, navigate to the repository root directory and enter into the command line (root permissions may be required):
Development and Deployment
The following services are used for the development and deployment of AISDB
build-wheels
Build manylinux-compatible wheels for Python package distribution. The resulting wheel file is installed in aisdb-python.
python-test
Run Python package integration tests. Based on the aisdb-python docker image..
nginx
NGINX gateway router. Routes incoming traffic to the appropriate cloud service. The following ports are exposed by the gateway:
80
: redirects to port 443443
: serves web application endpoints over HTTPS9920
: Proxy for theupstream-ais
service stream output (raw format).9922
: Proxy for thereceiver
service stream output (JSON format).
The following endpoints are available over HTTPS:
/
: Proxy for thewebserver
service./doc
: Proxy for thedocserver
service./ws
: Proxy for thedb-server
service./stream
: Alias of port9922
./stream-raw
: Alias of port9920
./coverage
: Alias of/docs/coverage
.
certbot
TLS/SSL certificate renewal service. Renews certificates used by the
nginx
service.privkey.pem
andfullchain.pem
certificates are mounted in thenginx
container inside directory/etc/letsencrypt/live/$FQDN/
, where$FQDN
is the domain name, e.g.127.0.0.1
.
Environment
Services running with docker compose will read environment variables from a .env
file in the project root directory. An example .env
file is included here:
Interacting with Postgres Database
In some cases, Postgres may preferred over SQLite. Postgres offers improved concurrency and scalability over SQLite, at the cost of requiring more disk space and compute resources. The easiest and recommended way to use AISDB with the Postgresql database is via docker (to manually install dependencies, see Web Application Development). To get started, navigate to the repository root directory, and ensure docker and docker-compose are installed. Start the AIS receiver, database server, and postgres database docker images. Sudo permissions may be required for Docker and docker-compose.
Python API
The receiver will fetch live data streaming from the MERIDIAN AIS network, and store it in the postgres database. Start the AIS receiver and Postgres database services from the command line with docker-compose:
The Postgres database may be interfaced using Python in the same manner as the default SQLite database by using aisdb.database.dbconn.PostgresDBConn
as a drop-in replacement for the default aisdb.database.dbconn.DBConn
that uses SQLite.
The resulting dbconn may then be used similar to how DBConn
is used in the Intro Doc
Web API
Start the AIS receiver, Postgres database, and database webserver services from the command line using the following command. See Docker for more info on docker services. Alternatively, the services can be run in a local environment instead of a docker environment as described in Web Application Development.
The receiver service will listen for new data from MERIDIANβs AIS receiver, and store it in the postgres database. The db-server service provides a web API for the AIS data stored in the postgres database. This listens for WebSocket connections on port 9924, and returns JSON-formatted vessel tracks in response to queries. The following Python code provides an example of how to asynchronously query AIS data from db-server. This code can either run in a local Python environment or in the aisdb-python docker image. While this example uses Python, the web API can be accessed using any language or package using the Websocket Protocol, such as JavaScript, as long as requests are formatted as utf8-encoded JSON.
Interacting with the Map
Last updated