feldroy / two-scoops-of-django-3.x

The issue tracker, changelog, and code repository for Two Scoops of Django 3.x
https://www.feldroy.com/products/two-scoops-of-django-3-x
341 stars 50 forks source link

Suggestion: Deploying Django Projects #70

Open kakulukia opened 4 years ago

kakulukia commented 4 years ago

Location within the Book

Description

Im very curious about whats in store here, but maybe my 2 cents could add a lil to the whole experience. As stated in 2.5 Python setup differences: sometimes it's hard to keep everything up to date and you end up with different python versions for projects all being deployed at the same server. Having fought a longer battle with uwsgi emperor and the like, my current solution to this problem is using pm2 with a tiny startup script using the uswsi installed in the projects venv.

Benefits:

That sure is not the best option for everybody, but for a bunch of my small projects this works very well.

If interested i could elaborate more.

pydanny commented 4 years ago

Why not supervisord? I'm not opposed to pm2, but isn't that for Node?

kakulukia commented 4 years ago

pm2 started that way, but can run anything. Why not supervisor? It involves a lot more steps to setup itself as well as its services. It already introduces confusion with supervisord and supervisorctl. pm2 on the other hand is dead simple which helps to spend less time with deployment and free some brain power for more interesting stuff.

So the only thing that's needed is a shell script defining how to start uwsgi config.yml. pm2 also supports arguments, but having saved and version controlled the way its started even frees some more brain power. The easy thing about pm2: You don't have to copy or link anything to any special directory. Just start the script and save the new process with the commands mentioned above. Done.

Also my uwsgi config is streamlined in a way that i only need to change the project name to have an easy start with deployment.

uwsgi:
    project: webseite
    base: opt/www

    master: true
    processes: 5
    enable-threads: true
    vacuum: true
    chmod-socket: 666
    #plugin: python
    die-on-term: true
    uid: www-data
    gid: www-data
    thunder-lock: true
    socket: /tmp/%(project).sock
    chdir: /%(base)/%(project)
    pythonpath: /%(base)/%(project)
    home: /%(base)/%(project)/.venv/
    #http: 0.0.0.0:8080
    module: settings.wsgi:application
    harakiri: 20  # respawn processes taking more than 20 seconds
    max-requests: 5000  # respawn processes after serving 5000 requests

The default overview looks like this:

Bildschirmfoto 2020-06-17 um 11 00 10

There is much more that can be configured for sure, but for a basic wagtail page like this one it doesnt need to be complicated. 😎