1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# dispatch-tracker
Most of the features are here and the application should fulfill the use
case at this time.
## Things to fix/add going forward:
* Friendly Error pages
* Description format field for customer objects &
* on load create page dynamically pull in cursomter description format
and display above the form field
* Upload Invoice logos on Identity Objects for use in Invoices
* Change Name To "Load Pay System" -- we're going to think about it
* Freight Invoicing System
* Figure out if auditlog timestamps are fucked or not with timezones
## To get a development system setup:
Not strictly part of the Django app, but worth noting that if you have
Postgres installed locally but don't want to muck with permissions, service
etc it's as simple as:
```bash
pg_ctl -D pg_data initdb
pg_ctl -D pg_data -l pg_log start
echo create database $(id -un)\; | psql postgres
echo create database dispatch | psql
```
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:
```
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
```
``` bash
cd app
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
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 \
--invoices=true
# Default is 2 weeks for start/end date, no
# defaults for any other options
# Run a local development server, listens to the world
./manage.py runserver 0.0.0.0:8080
```
## To get a production system setup:
Alpine Linux is used as the example, but it should be similar for most systems:
``` bash
# 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
```
Now install the Nginx configuration, careful to use
`unix:/tmp/dispatch-tracker.sock` for `uwsgi_pass`.
If you're using `runit` you can use the following script for the service:
```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`
```
./docker-compose up -d
```
Then
```
sh docker-scripts/setup.sh
```
Docker compose is configured to bring up the Nginx instance on
http://172.21.23.2 If you're on Windows or MacOS I'm told can't access it
directly via IP, so https://localhost:36200 should work instead.
# Misc
Name brainstorming / Use case:
```
Subcontractor invoicing system
Subcontractor Freight Invoicing System
A business solution for subcontractors that don't invoice you.
```
|