Deploying backend code - tuanchris/dune-weaver GitHub Wiki

There are two modes of deployment for backend code: Docker and Python script. If you are using any of the following supported devices, it is recommended to use Docker. Ensure that the OS is 64-bit.

Supported Devices

  • Raspberry Pi 3, 4, 5
  • Raspberry Pi Zero 2W
  • Any other PC/Mac (Python script deployment only)

Setting Up a Raspberry Pi

Setting up a Raspberry Pi should be straightforward. The recommended way is to use Raspberry Pi Imager.

Steps:

  1. Download and install Raspberry Pi Imager.

  2. Select your hardware, Raspberry Pi OS (64-bit), and your SD card.

    image

  3. Configure advanced options:

    • Enable SSH
    • Configure Wi-Fi credentials

    image

  4. Write the image to your SD card.


SSH into Your Raspberry Pi

SSH allows you to remotely access your Raspberry Pi for setup and maintenance.

Steps:

  1. Insert the SD card into the Raspberry Pi and power it on.
  2. You can connect to your Raspberry Pi using its hostname instead of an IP address. By default, you can use raspberrypi.local.
  3. Open a terminal and connect via SSH:
    ssh [email protected]
    
  4. When prompted, enter the default password (raspberry) or the one you configured during setup.

Docker Deployment

Using Docker for deployment provides several advantages:

  • Automatic Restart: Services will restart after power outages.
  • Auto-Update Feature: Software can be updated directly from the browser.

Install Docker on Raspberry Pi

  1. Update your system:
    sudo apt update && sudo apt upgrade -y
    
  2. Install Docker:
    curl -fsSL https://get.docker.com -o get-docker.sh
    sudo sh get-docker.sh
    
  3. Add your user to the Docker group to run Docker without sudo:
    sudo usermod -aG docker $USER
    
  4. Important: You need to log out and log back in for the group changes to take effect.
    exit
    
    Then reconnect via SSH:
    ssh pi@<your-pi-ip-address>
    
  5. Verify Docker is installed correctly:
    docker --version
    

Deploying Dune Weaver Using Docker Compose

Instead of manually running Docker commands, use the provided docker-compose.yml file to deploy Dune Weaver.

  1. Clone the Dune Weaver repository:
    git clone https://github.com/tuanchris/dune-weaver
    cd dune-weaver
    
  2. Run the service using Docker Compose:
    docker compose up -d
    
  3. Visit <raspberrypi_ip_address>:8080 and confirm that the backend is up. If this succeeds, you DO NOT need to deploy the Python backend below!

To stop the service:

docker compose down

This method ensures that all necessary dependencies and configurations are managed automatically.


Python Script Deployment

For devices that do not support Docker or if you prefer a manual setup, you can run the backend as a Python script. If you want the script to start automatically on boot, follow the instructions below.

One-Time Running of the Script

If you want to run the script manually without setting it up to start on boot, use the following commands:

  1. Clone and change directory:

    git clone https://github.com/tuanchris/dune-weaver
    cd dune-weaver
    
  2. Install Python virtual environment:

    sudo apt install python3-venv
    
  3. Create and activate a virtual environment:

    python3 -m venv .venv
    source .venv/bin/activate
    
  4. Install dependencies:

    pip install -r requirements.txt
    
  5. Run the application:

    python app.py
    

Start the Script on Boot (Linux based system)

To ensure the script runs on startup, create a systemd service. If you change your username, substitute yours for pi below.

  1. Create a new service file:
    sudo nano /etc/systemd/system/dune-weaver.service
    
  2. Add the following content:
    [Unit]
    Description=Dune Weaver Backend
    After=network.target
    
    [Service]
    ExecStart=/home/pi/dune-weaver/.venv/bin/python /home/pi/dune-weaver/app.py
    WorkingDirectory=/home/pi/dune-weaver
    Restart=always
    User=pi
    
    [Install]
    WantedBy=multi-user.target
    
  3. Save the file and reload systemd:
    sudo systemctl daemon-reload
    
  4. Enable and start the service:
    sudo systemctl enable dune-weaver
    sudo systemctl start dune-weaver
    
  5. To check the status of the service:
    sudo systemctl status dune-weaver
    

If you see Failed to start dune-weaver.service - Dune Weaver Backend., chances are you deployed the Docker backend first, so the Python backend cannot start on the same port 8080. You only need to deploy Docker or Python!


Accessing the Web UI

Open up a browser on your phone or on your computer to access the web UI.

  • If you run your backend on your computer, you can access the UI by going to localhost:8080.
  • If deployed onto a raspberry pi, the address should be raspberry.local:8080 or <raspberrypi_ip_address>:8080

Troubleshooting

Check Docker Logs

If you encounter issues with the Docker deployment, check the logs:

docker compose logs -f