diff options
| author | Mitch Riedstra <mitch@riedstra.us> | 2019-09-15 10:20:40 -0400 |
|---|---|---|
| committer | Mitch Riedstra <mitch@riedstra.us> | 2019-09-15 10:20:40 -0400 |
| commit | 2ec4f69f6f494def901826ad8fdbfb05d2fcfb75 (patch) | |
| tree | 82c6364a7138ccfdcfe9937b833c4ee8c6e5daf7 | |
| parent | 0b42b47b30c70dbc0ac512f3801ae4da6fb25a56 (diff) | |
| download | dispatch-tracker-2ec4f69f6f494def901826ad8fdbfb05d2fcfb75.tar.gz dispatch-tracker-2ec4f69f6f494def901826ad8fdbfb05d2fcfb75.tar.xz | |
Clean up the documentation a little bit moredemodocker-compose
| -rw-r--r-- | README.md | 128 | ||||
| -rw-r--r-- | nginx.conf | 7 |
2 files changed, 75 insertions, 60 deletions
@@ -33,23 +33,30 @@ Your user should be able to connect with just a simple `psql` You will need to install + +Void Linux: +``` +xbps-install base-devel python3-devel postgresql-libs-devel +``` + +Alpine Linux: ``` -base-devel -python3-devel -postgresql-libs-devel +apk add git python3 py3-setuptools py3-virtualenv postgresql-client +# This set can be optionally removed when the virutalenv is built +apk add linux-headers postgresql-dev gcc python3-dev libc-dev ``` -On Void Linux. On Ubuntu machines it will be similar. ``` bash cd app -virtualenv env +python3 -m venv env . env/bin/activate pip install -r requirements.txt cp config-example.yml config.yml sed -i.bak -e"s/USER: postgres$/USER: $(id -un)" config.yml -./manage.py migrate -./manage.py createsuperuser +python3 ./manage.py migrate +python3 ./manage.py createsuperuser +python3 ./manage.py setup_identity # This will create some fake records if you wish ./manage.py insert_fake_data --companies 10 --users 10 \ --loads 400 --start-date='-16w' --end-date='+16w' --attachments=true \ @@ -62,68 +69,69 @@ sed -i.bak -e"s/USER: postgres$/USER: $(id -un)" config.yml -## To get a production system setup: +## To get a production system setup: +Alpine Linux is used as the example, but it should be similar for most systems: ``` bash -export CFG="my-config.yml" -cd app -virtualenv env -. env/bin/activate -pip install -r requirements.txt -cp config.yml $CFG -vi $CFG # This is where you change the SECRET_KEY, static_root, allowed_hosts -# and other settings. -cat uwsgi.ini | sed -e"s/config.yml/$CFG/g" > my-uwsgi.ini -./manage.py collectstatic -./manage.py migrate -./manage.py createsuperuser -uwsgi --ini my-uwsgi.ini # This will start the daemon, it's up to you to -# configure your OS to start it on boot +# psql -U postgres +postgres=# create role dispatch with login password 'mypass'; +postgres=# create database dispatch with owner dispatch; +postgres=# \q +# export _u="dispatch" +$ export _home="/var/dispatch" +# addgroup -S "$_u" +# adduser -h "$_home" -G "$_u" -S -D "$_u" +# # Add Nginx to the dispatch group, on Alpine you must edit /etc/group + # since `gpasswd` doesn't exist. This is so Nginx can see the socket + # But your application can't see everything else Nginx does. +$ chmod 751 "$_home" +# su -s /bin/sh "$_u" +$ . /etc/profile +$ cd +$ git clone https://git.riedstra.us/mitch/dispatch-tracker.git +$ cd dispatch-tracker/app +$ python3 -m virtualenv env +$ . env/bin/activate +$ pip install -r requirements.txt +$ cp config-example.yml config.yml +$ vi config.yml # Set database credentials. Allowed hosts, Debug: false, + # secret key, static root, etc +$ python3 ./manage.py collectstatic +$ python3 ./manage.py migrate +$ python3 ./manage.py createsuperuser +$ uwsgi --processes=1 --threads=4 \ + --socket=/tmp/dispatch-tracker.sock \ + --chmod-socket=664 --module wsgi:application ``` -Below is a sample Nginx configuration, edit for your needs: - -``` nginx -# It's up to you to configure HTTPs, I _highly_ recommend it -server { - listen 80; - # Uncomment if you have ipv6 - # listen [::]:80; - server_name dispatch.example.com; +Now install the Nginx configuration, careful to use +`unix:/tmp/dispatch-tracker.sock` for `uwsgi_pass`. - root /var/www/dispatch.example.com; +If you're using `runit` you can use the following script for the service: - index index.html index.htm; - - # Some applications have trouble with merged slashes - # This likely doesn't but worth noting - merge_slashes off; - - location / { - include uwsgi_params; - uwsgi_pass 127.0.0.1:9200; - } - - # Pass through the static directory - # This should match whatever is in your config file - location /static { - alias /var/www/dispatch.example.com/static; - } - - # This is probably going to be pulled from dispatch/static/robots.txt - location /robots.txt { - alias /var/www/dispatch.example.com/static/robots.txt; - } - - # Enable logging - # You will likely have to create these directories for Nginx to load - access_log /var/log/nginx/dispatch.example.com/access.log; - error_log /var/log/nginx/dispatch.example.com/error.log; - -} +```bash +#!/bin/sh + +_user="dispatch_demo" +_app_pth="/var/dispatch/dispatch-tracker/app/" +_socket="/tmp/dispatch-tracker.sock" + +exec chpst -u "$_user" sh -c " + set -e + cd \"$_app_pth\"; + . env/bin/activate; + exec uwsgi \ + --die-on-term \ + --processes=1 \ + --threads=4 \ + --socket=\"$_socket\" \ + --chmod-socket=664 \ + --module wsgi:application + " ``` + ## Docker Environment setup A quasi production esque setup using `uwsgi` @@ -33,6 +33,8 @@ http { uwsgi_pass app:9200; } + # Pass through the static directory + # This should match whatever is in your config file location /static { alias /var/www; } @@ -40,6 +42,11 @@ http { alias /var/www/static/robots.txt; } + + # Optionally change the log path. + # access_log /var/log/nginx/dispatch.example.com/access.log; + # error_log /var/log/nginx/dispatch.example.com/error.log; + } include conf.d/*.conf; |
