Skip to content

Tutorial: Deploy on-premises server (manually)

⚠️ Note: This tutorial is intended for advanced users who want to control many aspects of the installation and configuration process. If you are looking for a simpler guide, please refer to the "Deploy on-premises server (via installation script)" tutorial.

This tutorial provides a step-by-step guide to installing and setting up the BeeCR solution on an on-premises server without using Docker. The installation process will be demonstrated on a machine equipped with an NVIDIA Tesla V100 GPU running Ubuntu 20.04 LTS Linux OS. This guide is intended to help users navigate the installation process, ensuring that all prerequisites are met and that the necessary components are correctly installed and configured.

⚠️ Note: As of summer 2024, Ubuntu 20.04 LTS is still supported by Canonical but is somewhat outdated. We chose this OS for our tutorial because it requires additional steps to set up the environment, and we want to demonstrate those. If you are using a more recent version of Ubuntu, you can skip any steps that are not required.

📄 Prerequirements

To deploy the solution on a server, you need the following:

  1. An "x86_64" server running Linux (preferably Ubuntu or Debian).
  2. A graphics card with at least 24 GB of memory.
  3. The curl command-line tool.
  4. Python (versions 3.9 to 3.12) and the virtualenv command-line tool.
  5. The user running the installation process must have root or sudo privileges.
  6. You have downloaded the archive with BeeCR installation files.

1️⃣ Environment Setup

Operating system

Ensure your OS is Linux, architecture is "x86_64" and kernel is non Microsoft WSL:

uname -smr

Example output:

Linux 5.15.0-71-generic x86_64

cURL

Ensure curl is installed. If not, install curl via package manager (on Ubuntu, use the apt):

sudo apt-get update
sudo apt-get install -y curl

Python and virtualenv

Ensure Python (3.9 – 3.12) and virtualenv are installed.

To install Python 3.9 and virtualenv on Ubuntu 20.04 LTS, use the apt package manager:

sudo apt-get update
sudo apt-get install -y python3.9 python3-virtualenv

If multiple Python versions are installed you may need to configure the default version:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1
sudo ln -s /usr/lib/python3/dist-packages/apt_pkg{.cpython-38-x86_64-linux-gnu,}.so

These commands do the following:

  1. Set the priority level for python3.8 (the old Python version) to 1 for the python3 alias.
  2. Set a higher priority level for python3.9 (the new Python version) to 2 for the python3 alias.
  3. Set the priority level for the python alias to python3.
  4. Fix a potential issue with apt_pkg by creating a symlink to a shared library that belongs to an older Python version.

2️⃣ Install and configure the AI server

Install the AI server

curl -fsSL https://ollama.com/install.sh | OLLAMA_VERSION="0.3.6" sh

Create the extra configuration directory /etc/systemd/system/ollama.service.d. Then put there env.conf with the following content:

[Service]
Environment="OLLAMA_HOST=0.0.0.0:11435"
Environment="OLLAMA_KEEP_ALIVE=-1"
Environment="OLLAMA_NUM_PARALLEL=2"

Reload the "systemd" daemon and enable the service:

sudo systemctl daemon-reload
sudo systemctl enable ollama
sudo systemctl start ollama

Ensure the AI server is running:

curl -s "http://localhost:11435"

Pull the AI Model

OLLAMA_HOST="0.0.0.0:11435" ollama pull "codestral:22b"

3️⃣ Install and configure API server

Create virtual environment

sudo virtualenv "/opt/beecr/venv"

Install ASGI Server (Uvicorn)

sudo /opt/beecr/venv/bin/pip3 install "uvicorn~=0.30"

Install the API server package

Choose the whl package according to your Python version. For Python 3.9, install the package that contains py39 in the name. For Python 3.10, install the package that contains py310 in the name. And so on.

If you don't know your Python version, simply run the /opt/beecr/venv/bin/python3 --version command.

sudo /opt/beecr/venv/bin/pip3 install "./path/to/whl/package"

Configure API Server

Create the "systemd" daemon configuration file /etc/systemd/system/beecr.service with the following content:

[Unit]
Description=BeeCR Service
After=network-online.target

[Service]
WorkingDirectory=/opt/beecr
ExecStart=/opt/beecr/venv/bin/python3 -m uvicorn --host 0.0.0.0 --port $PORT --log-config /opt/beecr/logging.json beecr.api.main:app
Restart=always
RestartSec=3
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
Environment="PORT=8000"

[Install]
WantedBy=default.target

Adjust the PORT environment variable if you wish the API server to serve on a different port.

⚠️ Note: If you wish to bind the API server to an IPv6 socket, replace 0.0.0.0 with :: in your "systemd" daemon configuration.

Create the extra configuration directory /etc/systemd/system/beecr.service.d. Then put there env.conf with the following content:

[Service]

# Default GitLab host and token.
#
# Will be used only if the requests do not pass these parameters explicitly.
# Environment="GITLAB_HOST=https://gitlab.com"
# Environment="GITLAB_TOKEN="


# Ollama-compatible API settings.
Environment="OLLAMA_HOST=http://localhost:11435"


# OpenAI-compatible API settings.
#
# Edit if you wish to use AI models via OpenAI-compatible API.
# Environment="OPENAI_HOST=https://api.openai.com"
# Environment="OPENAI_API_KEY="


# Default AI model name.
#
# This AI model will be used for handling API requests without
# an explicit model name passed.
#
# For OpenAI-compatible APIs use model names as they are,
# e.g. "gpt-4o".
#
# For Ollama-compatible APIs use model names with the prefix "ollama/",
# e.g. "ollama/codestral:22b".
Environment="MODEL=ollama/codestral:22b"

Create the working directory for API server /opt/beecr. Then put there logging.json with the following content:

{
    "version": 1,
    "filters": {
        "correlation_id": {
            "()": "asgi_correlation_id.CorrelationIdFilter",
            "uuid_length": 32,
            "default_value": "-"
        }
    },
    "formatters": {
        "default": {
            "format": "%(levelname)s\t[BeeCR-%(correlation_id)s]\t%(message)s",
            "datefmt": "%Y-%m-%d %H:%M:%S"
        }
    },
    "handlers": {
        "console": {
            "formatter": "default",
            "filters": ["correlation_id"],
            "class": "logging.StreamHandler",
            "stream": "ext://sys.stdout",
            "level": "DEBUG"
        }
    },
    "root": {
        "handlers": ["console"],
        "level": "INFO"
    },
    "loggers": {
        "uvicorn": {
            "propagate": true
        },
        "uvicorn.access": {
            "propagate": true
        }
    }
}

Reload the systemd daemon and enable the API server:

sudo systemctl daemon-reload
sudo systemctl enable beecr

4️⃣ Obtain and install the license

If you don't have a license file, follow these steps:

  1. Contact our team via beecr@cvisionlab.com (or any other communication channel if you have contacted us before).
  2. Run the nvidia-smi -L command and provide the BeeCR team the information about your GPU (e.g., GPU 0: Tesla V100-PCIE-32GB (UUID: GPU-d541606d-4910-6857-7cc0-4821bec3f358)).

Once you have received the license file (it must be named beecr.lic), place it in the /opt/beecr directory and restart the beecr service by running the following command:

sudo systemctl restart beecr

5️⃣ Check the logs (optionally)

Use the standard "systemd" daemon commands to manage the service.

For example, to view (and follow) the logs, use the journalctl command-line tool:

journalctl -fu beecr

Output example:

Jul 16 10:53:42 code-review-2004-v100 python3[41610]: INFO        [BeeCR--]        Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
Jul 16 10:53:42 code-review-2004-v100 systemd[1]: beecr.service: Succeeded.
Jul 16 10:53:45 code-review-2004-v100 systemd[1]: Stopped BeecR Service.
Jul 16 10:53:45 code-review-2004-v100 systemd[1]: Started BeecR Service.
Jul 16 10:53:46 code-review-2004-v100 python3[41624]: 🟢 License check passed. License info: GPU based license.
Jul 16 10:53:46 code-review-2004-v100 python3[41624]: INFO        [BeeCR--]        Started server process [41624]
Jul 16 10:53:46 code-review-2004-v100 python3[41624]: INFO        [BeeCR--]        Waiting for application startup.
Jul 16 10:53:46 code-review-2004-v100 python3[41624]: INFO        [BeeCR--]        Settings: pkg_name='beecr-api' version='v1.27.1' domain='beecr.io' protocol='http' port=8000 model='ollama/codestral:22b' temperature=0.8 use_original_code=True language='English' openai_host='https://api.openai.com' openai_api_key='*****' ollama_host='http://localhost:11435' gitlab_host='https://gitlab.com' target=None target_extra=None target_exclude=None.
Jul 16 10:53:46 code-review-2004-v100 python3[41624]: INFO        [BeeCR--]        Application startup complete.
Jul 16 10:53:46 code-review-2004-v100 python3[41624]: INFO        [BeeCR--]        Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)

👍 Conclusion

By following this tutorial, you have successfully installed and configured the BeeCR code review solution on your on-premises server. You have learned how to address common installation issues, such as missing prerequisites and outdated software, and how to manage the service using "systemd" daemon. With the BeeCR solution up and running, you can now leverage its powerful capabilities to enhance your code review processes. If you encounter any further issues or require a license, please contact the our team for support.