# Hosting Manual: Setting UP QubiC Platform

## Existing Server Deployment:

```python
// Go to dir where dockerfile is stored
sudo docker build --no-cache -t my-qubic-app .
sudo docker run -p 3306:3306 -p 5000:5000 my-qubic-app
```

sudo docker-compose build

sudo docker network create my-network

sudo docker run --network my-network -it mysql:latest mysql -u root --host doltdb --port 3306

sudo docker-compose up

## New Server Deployment: From Scratch&#x20;

### API & Platform: Follow these steps

1. Log in to Qubic3 Server(You must have Qubic3 server access)
2. ```
   sudo apt-get update
   sudo apt-get install docker.io
   ```
3. `nano Dockerfile`
4. Copy and paste this content

   ```dockerfile
   # Use a base image with Ubuntu
   FROM ubuntu:latest

   # Set non-interactive mode
   ENV DEBIAN_FRONTEND=noninteractive

   # Update package sources and install necessary packages
   RUN apt-get update && apt-get install -y \
       git \
       python3 \
       python3-venv \
       curl \
       lsof \
       wget \
       npm \
       && rm -rf /var/lib/apt/lists/*

   RUN apt-get update && apt-get install -y supervisor \
       && rm -rf /var/lib/apt/lists/*
   # Clone repositories
   RUN git clone https://gitlab.com/DevanshuBrahmbhatt/qubic-data-storage.git /app/qubic-data-storage 

   # Install Dolt
   RUN curl -L https://github.com/dolthub/dolt/releases/latest/download/install.sh | bash \
       && useradd -r -m -d /var/lib/doltdb dolt

   # Additional steps for Dolt setup
   RUN dolt config --global --add user.email doltServer@company.com \
       && dolt config --global --add user.name "Dolt Server Account"

   # Set up and configure MySQL
   RUN apt-get update \
       && apt-get install -y lsb-release \  
       && wget http://repo.mysql.com/mysql-apt-config_0.8.26-1_all.deb \
       && dpkg -i mysql-apt-config_0.8.26-1_all.deb \
       && apt-get update \
       && apt-get install -y mysql-shell mysql-server

   # Install required Python packages
   RUN python3 -m venv /app/venv \
       && /app/venv/bin/pip3 install -r /app/qubic-data-storage/requirements.txt 

   # Initialize Dolt repository and create the "calibration" database
    RUN cd /app/qubic-data-storage \
       && dolt init \
       && dolt sql -q "CREATE DATABASE calibration"


   # Set working directory for frontend

   WORKDIR /app/qubic-data-storage/qubic-data-storage-frontend

   # Install Node.js using NVM
   RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash \
       && . ~/.nvm/nvm.sh \
       && nvm install 14 \
       && nvm use 14 \
       && npm install -g yarn

   RUN ls -la

   ENV PATH="/usr/bin/versions/node/v14.21.3/bin:${PATH}"
   # Build and run Vue.js frontend
   RUN yarn install 
   RUN yarn build

   # Expose the necessary ports
   EXPOSE 3306 5000

   # Set working directory to qubic-data-storage
   WORKDIR /app/qubic-data-storage

   # Activate the virtual environment, run dolt sql-server, and start the services
   # CMD ["/bin/bash", "-c", "\
   #     source /app/venv/bin/activate && \
   #     dolt sql-server -u root & \
   #     /app/venv/bin/flask run --host=0.0.0.0"]

   # Copy supervisor configuration
   COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

   # Start processes
   CMD ["/usr/bin/supervisord"]
   ```
5. <pre><code><strong>ctrl+o
   </strong><strong>Enter
   </strong><strong>ctrl+x
   </strong></code></pre>
6. `nano supervisord.conf`
7. copy and paste this content

   ```properties
   [supervisord]
   nodaemon=true

   [program:dolt]
   command=/bin/bash -c "dolt sql-server -u root"
   autostart=true
   autorestart=true

   [program:flask]
   command=/bin/bash -c "source /app/venv/bin/activate && /app/venv/bin/flask run --host=0.0.0.0"
   directory=/app/qubic-data-storage
   autostart=true
   autorestart=true
   ```
8. <pre><code><strong>ctrl+o
   </strong><strong>Enter
   </strong><strong>ctrl+x
   </strong></code></pre>
9. `sudo docker build --no-cache -t my-qubic-app .`
10. `sudo docker run -p 3306:3306 -p 5000:5000 my-qubic-app`

#### Troubleshooting commands for Docker

```python
# checking process on port 5000 server
sudo lsof -i :5000
# kill process 
sudo kill [PID]

# list all containers
sudo docker ps 
# stop container
sudo docker stop [CONTAINER_ID]
# remove container
sudo docker rm [CONTAINER_ID or NAME]

# list all images
sudo docker images
# remove the docker image
sudo docker rmi [IMAGE_ID or REPOSITORY:TAG]

# (Free up space)List docker volumes
sudo docker volume ls
sudo docker volume rm [VOLUME_NAME]

#(Free up network space) List docker networks
sudo docker network ls
sudo docker network rm [NETWORK_NAME]

# Restart docker
sudo systemctl restart docker
```

## Jupyter Notebook: Follow these steps

```python
 python3 setup.py sdist bdist_wheel
 pip3 install .
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://devanshus-organization.gitbook.io/qubic-docs/new-hosting-script/hosting-manual-setting-up-qubic-platform.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
