Skip to content

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

pip install unipoll-api

Running the API

unipoll-api run

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 run unipoll/api -e MONGODB_URI=<your connection string>

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

docker compose up -d

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"
apiVersion: v1
kind: Service
metadata:
  name: unipoll-api
  namespace: unipoll
spec:
  selector:
    app: unipoll-api
  ports:
  - port: 80
    targetPort: 9000
    protocol: TCP
    name: http
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: unipoll-api
  labels:
    name: unipoll-api
spec:
  rules:
  - host: unipoll-api.1cl.cc
    http:
      paths:
      - pathType: Prefix
        path: "/"
        backend:
          service:
            name: unipoll-api
            port:
              number: 80

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

$ tar xvfz unipoll-api-<version>.tar.gz

Optionally, create a virtual environment. Make sure you have installed venv package. You can create a virtual environment using the following command:

$ pip install venv
$ python -m venv venv
$ source ven/bin/activate

Run the following command in the root directory of the project:

$ pip install .

This will install the package and all its dependencies on your system. The you can run the API as a service using systemd.