aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.dockerignore3
-rw-r--r--Pipfile2
-rw-r--r--docker/uwsgi.ini38
-rw-r--r--docs/deployment.md146
-rwxr-xr-xmanage.py7
5 files changed, 3 insertions, 193 deletions
diff --git a/.dockerignore b/.dockerignore
index 61fa291a..b6334213 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -15,9 +15,6 @@ pydis_site/apps/home/tests
pydis_site/apps/staff/tests
CHANGELOG.md
CONTRIBUTING.md
-docker
-!docker/uwsgi.ini
-!docker/wheels
docker-compose.yml
Dockerfile.local
docs
diff --git a/Pipfile b/Pipfile
index 27a2a452..add1f97b 100644
--- a/Pipfile
+++ b/Pipfile
@@ -16,7 +16,7 @@ requests = "~=2.21"
pygments = "~=2.3.1"
wiki = "~=0.6.0"
pyyaml = "~=5.1"
-pyuwsgi = {version = "~=2.0", sys_platform = "!='win32'"}
+gunicorn = "~=20.0.4"
django-allauth = "~=0.41"
sentry-sdk = "~=0.14"
gitpython = "~=3.1.7"
diff --git a/docker/uwsgi.ini b/docker/uwsgi.ini
deleted file mode 100644
index 3f35258c..00000000
--- a/docker/uwsgi.ini
+++ /dev/null
@@ -1,38 +0,0 @@
-[uwsgi]
-### Exposed ports
-# uWSGI protocol socket
-socket = :4000
-
-### File settings
-# WSGI application
-wsgi = pydis_site.wsgi:application
-# Directory to move into at startup
-chdir = /app
-
-### Concurrency options
-# Run a master to supervise the workers
-master = true
-# Keep a minimum of 1 worker
-cheaper = 1
-# Allow a maximum of 4 workers
-workers = 4
-# Automatically set up meanginful process names
-auto-procname = true
-# Prefix process names with `pydis_site : `
-procname-prefix-spaced = pydis_site :
-
-### Worker options
-# Kill workers if they take more than 30 seconds to respond.
-harakiri = 30
-
-### Startup settings
-# Exit if we can't load the app
-need-app = true
-# `setuid` to an unprivileged user
-uid = 1500
-# Do not use multiple interpreters
-single-interpreter = true
-
-### Hook setup
-# Gracefully kill workers on `SIGQUIT`
-hook-master-start = unix_signal:3 gracefully_kill_them_all
diff --git a/docs/deployment.md b/docs/deployment.md
deleted file mode 100644
index e561b5d0..00000000
--- a/docs/deployment.md
+++ /dev/null
@@ -1,146 +0,0 @@
-# Deployment
-The default Dockerfile should do a good job at running a solid web server that
-automatically adjusts its worker count based on traffic. This is managed by
-uWSGI. You need to configure the `DATABASE_URL` and `SECRET_KEY` variables. If
-you want to deploy to a different host than the default, configure the
-`ALLOWED_HOSTS` variable.
-
-## Static file hosting
-You can either collect the static files in the container and use uWSGI to host
-them, or put them on your host and manage them through a web server running on
-the host like nginx.
-
-## Database migrations
-To bring the schema up-to-date, first stop an existing database container, then
-start a container that just runs the migrations and exits, and then starts the
-main container off the new container again.
-
-## Ansible task
-An example Ansible task to deploy the site is shown below, it should read fairly
-humanly and give you a rough idea of steps needed to deploy the site.
-
-```yml
-- name: ensure the `{{ pysite_pg_username }}` postgres user exists
- become: yes
- become_user: postgres
- postgresql_user:
- name: "{{ pysite_pg_username }}"
- password: "{{ pysite_pg_password }}"
- when: pysite_pg_host == 'localhost'
-
-- name: ensure the `{{ pysite_pg_database }}` postgres database exists
- become: yes
- become_user: postgres
- postgresql_db:
- name: "{{ pysite_pg_database }}"
- owner: "{{ pysite_pg_username }}"
- when: pysite_pg_host == 'localhost'
-
-- name: ensure the `{{ pysite_hub_repository }}` image is up-to-date
- become: yes
- docker_image:
- name: "{{ pysite_hub_repository }}"
- force: yes
-
-- name: ensure the nginx HTTP vhosts are up-to-date
- become: yes
- template:
- src: "nginx/{{ item.key }}.http.conf.j2"
- dest: "/etc/nginx/sites-available/{{ item.value }}.http.conf"
- with_dict: "{{ pysite_domains }}"
- notify: reload nginx
-
-- name: ensure the nginx HTTPS vhosts are up-to-date
- become: yes
- template:
- src: "nginx/{{ item.key }}.https.conf.j2"
- dest: "/etc/nginx/sites-available/{{ item.value }}.https.conf"
- with_dict: "{{ pysite_domains }}"
- notify: reload nginx
-
-- name: ensure the nginx HTTP vhosts are symlinked to `/etc/nginx/sites-enabled`
- become: yes
- file:
- src: /etc/nginx/sites-available/{{ item.value }}.http.conf
- dest: /etc/nginx/sites-enabled/{{ item.value }}.http.conf
- state: link
- with_dict: "{{ pysite_domains }}"
- notify: reload nginx
-
-- name: ensure we have HTTPS certificates
- include_role:
- name: thefinn93.letsencrypt
- vars:
- letsencrypt_cert_domains: "{{ pysite_domains | dict2items | map(attribute='value') | list }}"
- letsencrypt_email: "[email protected]"
- letsencrypt_renewal_command_args: '--renew-hook "systemctl restart nginx"'
- letsencrypt_webroot_path: /var/www/_letsencrypt
-
-- name: ensure the nginx HTTPS vhosts are symlinked to `/etc/nginx/sites-enabled`
- become: yes
- file:
- src: /etc/nginx/sites-available/{{ item.value }}.https.conf
- dest: /etc/nginx/sites-enabled/{{ item.value }}.https.conf
- state: link
- with_dict: "{{ pysite_domains }}"
- notify: reload nginx
-
-- name: ensure the web container is absent
- become: yes
- docker_container:
- name: pysite
- state: absent
-
-- name: ensure the `{{ pysite_static_file_dir }}` directory exists
- become: yes
- file:
- path: "{{ pysite_static_file_dir }}"
- state: directory
- owner: root
- group: root
-
-- name: collect static files
- become: yes
- docker_container:
- image: "{{ pysite_hub_repository }}"
- name: pysite-static-file-writer
- command: python manage.py collectstatic --noinput
- detach: no
- cleanup: yes
- network_mode: host
- env:
- DATABASE_URL: "{{ pysite_pg_database_url }}"
- SECRET_KEY: "me-dont-need-no-secret-key"
- STATIC_ROOT: "/html"
- volumes:
- - "/var/www/pythondiscord.com:/html"
-
-- name: ensure the database schema is up-to-date
- become: yes
- docker_container:
- image: "{{ pysite_hub_repository }}"
- name: pysite-migrator
- detach: no
- cleanup: yes
- command: python manage.py migrate
- network_mode: host
- env:
- DATABASE_URL: "postgres://{{ pysite_pg_username }}:{{ pysite_pg_password }}@{{ pysite_pg_host }}/{{ pysite_pg_database }}"
- SECRET_KEY: "me-dont-need-no-secret-key"
-
-- name: ensure the website container is started
- become: yes
- docker_container:
- image: "{{ pysite_hub_repository }}"
- name: pysite
- network_mode: host
- restart: yes
- restart_policy: unless-stopped
- ports:
- - "127.0.0.1:4000:4000"
- env:
- ALLOWED_HOSTS: "{{ pysite_domains | dict2items | map(attribute='value') | join(',') }}"
- DATABASE_URL: "postgres://{{ pysite_pg_username }}:{{ pysite_pg_password }}@{{ pysite_pg_host }}/{{ pysite_pg_database }}"
- PARENT_HOST: pysite.example.com
- SECRET_KEY: "{{ pysite_secret_key }}"
-```
diff --git a/manage.py b/manage.py
index d4748a3a..62352177 100755
--- a/manage.py
+++ b/manage.py
@@ -10,7 +10,6 @@ import django
from django.contrib.auth import get_user_model
from django.core.management import call_command, execute_from_command_line
-
DEFAULT_ENVS = {
"DJANGO_SETTINGS_MODULE": "pydis_site.settings",
"SUPER_USERNAME": "admin",
@@ -156,10 +155,8 @@ class SiteManager:
call_command("runserver", "0.0.0.0:8000")
return
- import pyuwsgi
-
- # Run uwsgi for production server
- pyuwsgi.run(["--ini", "docker/uwsgi.ini"])
+ # Run gunicorn for production server
+ os.system("gunicorn --preload -b 0.0.0.0:8000 pydis_site.wsgi:application --threads 8 -w 4")
def main() -> None: