Skip to content

Commit 6e8f7dc

Browse files
committed
Merge pull request #176 from rambo/production_setup
Update production setup instructions
2 parents fb3f898 + 712412f commit 6e8f7dc

File tree

2 files changed

+47
-11
lines changed

2 files changed

+47
-11
lines changed

README.md

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ with custom callbacks for automating things like mailing list subscriptions for
3333

3434
For Ubuntu 14.04 LTS
3535

36+
- Make sure your're using UTF-8 locale
37+
- `sudo locale-gen en_US.UTF-8 ; export LC_ALL=en_US.UTF-8`
38+
- You will want to make your system default locale is UTF-8 one too, see your distribution documentation.
3639
- Add the original repo as upstream `git remote add upstream https://github.com/hacklab-fi/asylum.git`
40+
- Enter the "project" directory: `cd asylum/project`
3741
- Make a branch for your local changes `git checkout -b myhackerspace`
3842
- Install nodejs v4 first (needs PPA and key and stuff, nodesource has a handy script for this)
3943

@@ -54,8 +58,9 @@ sudo apt-get install -y nodejs</code></pre>
5458
- `sudo su - postgres`
5559
- `createuser asylum && createdb -E utf-8 -T template0 -O asylum asylum && psql -U postgres -d postgres -c "alter user asylum with password 'asylum';"`
5660
- Change at least the password,in createdb `-O asylum` is the user that owns the database.
61+
- If installing for production create your `.env` file now.
5762
- `./manage.py migrate`
58-
- `find . -name '._*' | xargs rm ; for app in $( find . -path '*/locale' ); do (cd $(dirname $app) && ../manage.py compilemessages ); done`
63+
- `find . -name '._*' | xargs rm ; for app in $( find . -path '*/locale' | grep -v venv/ ); do (cd $(dirname $app) && ../manage.py compilemessages ); done`
5964
- `./manage.py createinitialrevisions`
6065
- `./manage.py createsuperuser`
6166
- `npm run build`
@@ -67,17 +72,24 @@ sudo apt-get install -y nodejs</code></pre>
6772
- DJANGO_SENTRY_DSN
6873
- https://hub.docker.com/_/sentry/
6974
- https://docs.getsentry.com/hosted/
75+
- OR set `USE_SENTRY=False`
7076
- DATABASE_URL (=postgres://pguser:pgpassword@localhost/dbname)
77+
- DJANGO_SECRET_KEY
78+
- DJANGO_ADMIN_URL (=admin/)
79+
- DJANGO_ALLOWED_HOSTS (comma separated list)
7180
- `./manage.py collectstatic --noinput`
7281
- Setup uWSGI
7382
- `sudo apt-get install uwsgi-plugin-python3 uwsgi`
74-
- `nano -w /etc/uwsgi/apps-available/asylum.ini` (see below)
75-
- `ln -s /etc/uwsgi/apps-available/asylum.ini /etc/uwsgi/apps-enabled/asylum.ini`
76-
- `service uwsgi reload`
83+
- `sudo nano -w /etc/uwsgi/apps-available/asylum.ini` (see below)
84+
- `sudo ln -s /etc/uwsgi/apps-available/asylum.ini /etc/uwsgi/apps-enabled/asylum.ini`
85+
- `sudo service uwsgi restart`
7786
- Setup Nginx
78-
- TODO: instructions
87+
- `sudo apt-get install nginx`
88+
- `sudo nano -w /etc/nginx/sites-available/asylum.ini` (see below)
89+
- `sudo ln -s /etc/nginx/sites-available/asylum.ini /etc/nginx/sites-enabled/asylum.ini`
90+
- `sudo service nginx restart`
7991
- Configure backups
80-
- TODO: instructions
92+
- See the cronjobs below, offsite backups are recommended.
8193

8294
#### uWSGI config example
8395

@@ -95,6 +107,27 @@ chdir = /home/myhackerspace/asylum/project
95107
touch-reload = /home/myhackerspace/asylum/project/reload
96108
env = DJANGO_SETTINGS_MODULE=config.settings.production</code></pre>
97109

110+
#### Nginx config example
111+
112+
<pre><code>upstream asylum {
113+
server 127.0.0.1:9001 fail_timeout=0;
114+
}
115+
server {
116+
listen 80;
117+
server_name asylum.mylab.hacklab.fi;
118+
119+
root /usr/share/nginx/html;
120+
index index.html index.htm;
121+
client_max_body_size 50M;
122+
keepalive_timeout 5;
123+
124+
location / {
125+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
126+
proxy_set_header Host $http_host;
127+
proxy_redirect off;
128+
proxy_pass http://asylum;
129+
}
130+
}</code></pre>
98131

99132
### Updating upstream changes
100133

@@ -104,13 +137,13 @@ In the `project` dir of your checkout
104137
git fetch upstream
105138
git rebase upstream/master master
106139
git checkout myhackerspace
107-
git rebase master
140+
git merge master
108141
source venv/bin/activate
109142
pip install -r requirements/production.txt
110143
./manage.py migrate
111144
npm run build
112145
./manage.py collectstatic --noinput
113-
for app in locale */locale; do (cd $(dirname $app) && ../manage.py compilemessages ); done
146+
find . -name '._*' | xargs rm ; for app in $( find . -path '*/locale' | grep -v venv/ ); do (cd $(dirname $app) && ../manage.py compilemessages ); done
114147

115148
And assuming you have uWSGI configured `touch reload`
116149

@@ -131,8 +164,9 @@ Until we maybe decide on Celery for running various (timed or otherwise) tasks a
131164
- `npm run watch &` If you want to develop the JS/LESS stuff this will autocompile them on change
132165
- `./manage.py runserver 0.0.0.0:8000`
133166
- `maildump -p ~/maildump.pid --stop`
134-
- Make localizations: `find . -name '._*' | xargs rm ; for app in $( find . -path '*/locale' ); do (cd $(dirname $app) && ../manage.py makemessages ); done`
167+
- Make localizations: `find . -name '._*' | xargs rm ; for app in $( find . -path '*/locale' | grep -v venv/ ); do (cd $(dirname $app) && ../manage.py makemessages ); done`
135168
- If you add your own apps, make sure to create the `locale` directory for them too.
169+
- use `npm run fix` to run autopep8 and friends before committing.
136170

137171
If you need the special environment variables in scripts not run via manage.py, use `set -o allexport ; source .env; set +o allexport` to load them.
138172

project/manage.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
import environ
77

8+
ROOT_DIR = environ.Path(__file__) - 1
9+
810
if __name__ == "__main__":
9-
if os.path.isfile('.env'):
10-
environ.Env.read_env('.env')
11+
if os.path.isfile(str(ROOT_DIR + '.env')):
12+
environ.Env.read_env(str(ROOT_DIR + '.env'))
1113
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")
1214

1315
from django.core.management import execute_from_command_line

0 commit comments

Comments
 (0)