Deployment of the API
The API is a Python package that can be installed on a Linux system. You can install the package from PyPI, from source, or run it in a Docker container.
Prerequisites
The API uses MongoDB as a database. You can either use a local instance of MongoDB or use a cloud service such as MongoDB Atlas. Specify the connection string in the MONGODB_URL
environment variable.
Installing the API from PyPI
Running the API
You can then create a systemd service to run the application as daemon.
Running in Docker
Make sure you have installed latest Docker on your system.
Running in docker
Docker Compose
You can also use docker-compose file which will run the MongoDB database in a separate container along side the API container.
services:
mongodb:
image: 'mongo:latest'
ports:
- '27017:27017'
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: changeme
api:
image: 'unipoll/api:latest'
ports:
- '80:8000'
environment:
MONGODB_URL: mongodb://root:changeme@mongodb:27017
PORT: 8000
Run the compose file with
Kubernetes deployment
You can deploy the API to Kubernetes cluster using the following manifests:
apiVersion: apps/v1
kind: Deployment
metadata:
name: unipoll-api
namespace: unipoll
labels:
app: unipoll-api
spec:
replicas: 2
selector:
matchLabels:
app: unipoll-api
template:
metadata:
labels:
app: unipoll-api
spec:
containers:
- name: unipoll-api
image: unipoll/api:latest
args: ["--host=0.0.0.0"]
ports:
- containerPort: 80
env:
- name: MONGODB_URL
value: "mongodb://root:9nLkOk853z@10.0.2.162:27017"
Instal the package from source
Get the latest version of the API from the releases page
Make sure you have the following installed on your system:
- Python 3.11
- pip
Unpack the archive with
Optionally, create a virtual environment. Make sure you have installed venv
package. You can create a virtual environment using the following command:
Run the following command in the root directory of the project:
This will install the package and all its dependencies on your system. The you can run the API as a service using systemd.