How to setup wooey in multi-server mode

In this blog we are going to discuss how to setup distributed infrastructure - Django- Celery- Redis- Flower


We are using Wooey Django
https://github.com/wooey/Wooey




1. Pre-requirements


1.1. Docker


To install postgresql and rabbitmq, I will use docker, because this is the easiest way.
To set-up it please follow instruction from this article
[https://docs.docker.com/v17.09/engine/installation/linux/docker-ce/ubuntu/#install-docker-ce](https://docs.docker.com/v17.09/engine/installation/linux/docker-ce/ubuntu/#install-docker-ce)
or just enter following commands:


    sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    sudo apt-key fingerprint 0EBFCD88
    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
    sudo apt-get update
    sudo apt-get install docker-ce docker-ce-cli containerd.io


Now, you able to check it with the next command:


    sudo docker run hello-world


1.2. Install Postgresql


This package can be installed on any server you want. From the box wooey use sqlite3, which you can't use in the multi-server mode. So, don't try to skip this step.


    docker run --name bodia-postgresql-11.2 -d -p 5432:5432 -e POSTGRES_USER=garry_user -e POSTGRES_PASSWORD=garry_password -e POSTGRES_DB=garry_db postgres:11.2-alpine


1.3. Install Rabbitmq


We will use this package as a broker, you can install it wherever you want


    docker run --name garry-rabbitmq-3.6.16 -d -p 5672:5672 -p 15672:15672 -e RABBITMQ_DEFAULT_USER=garry_user -e RABBITMQ_DEFAULT_PASS=garry_password -e RABBITMQ_DEFAULT_VHOST=garry_vhost rabbitmq:3.6.16-alpine

2 Setup wooey


So, let's start. You able to use any interpreter you want, I recommend you to use pipenv, but for this article we will use native python interpreter, without any virtualization.


Let's install PIP package manager. To do it, just type the following commands:


    sudo apt update && sudo apt upgrade
    sudo apt install python-pip


Now, let's install wooey (i've added postgresql adapter as well, just install it)


    pip install wooey psycopg2


Then, you will be able to start a new wooey project:


    wooify -p ProjectName
    cd ProjectName


Create uploads folder, it's nececery because we ant to link it through multiple machines:


    mkdir -p /root/ProjectName/ProjectName/user_uploads


Let's update the user_settings.py to allow wooey to communicate with rabbitmq and postgresql. Just add following lines to the very bottom of your `ProjectName/settings/user_settings.py` file:


    # Database config
    # make sure that you use the right host
    DATABASES = {
         'default': {
             'ENGINE': 'django.db.backends.postgresql_psycopg2',
             'NAME': 'garry_db',
             'USER': 'garry_user',
             'PASSWORD': 'garry_password',
             'HOST': '165.227.137.51',
             'PORT': '5432'
         }
    }
    
    # Broker config
    # make sure that you use the right host
    CELERY_BROKER_URL = 'amqp://garry_user:garry_password@165.227.137.51:5672/garry_vhost'


3. Setup worker


To do it, just follow all the steps from Unit 2.


Then, install


    sudo apt-get install sshfs
    sshfs root@165.22.132.188:/root/ProjectName/ProjectName/user_uploads /root/ProjectName/ProjectName/user_uploads


4. Let's run it


## Run django


First of all, you need to make a migrations and crate the cache table:


    ./manage.py migrate
    ./manage.py createcachetable


Now, you can create a superuser:


    ./manage.py createsuperuser


The last step, run the server:


    ./manage.py runserver 0:8000


Run workers


Just run them, it will work. :)


    celery -A ProjectName worker -c 1 --beat -l info

Comments

Popular Posts