Skip to content

Commit a33610d

Browse files
committed
Shorten doc line lengths for easier reading as source
1 parent f471d45 commit a33610d

File tree

1 file changed

+73
-40
lines changed

1 file changed

+73
-40
lines changed

docs/dev/provisioning.rst

+73-40
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ Cc_Licenses is deployed on the following stack.
1515
Deploying
1616
---------
1717

18-
Here's a recipe for deploying this web site that should work. Automating this is left as an exercise for the reader.
18+
Here's a recipe for deploying this web site that should work. Automating
19+
this is left as an exercise for the reader.
1920

2021
If you haven't before, clone the repo::
2122

@@ -25,16 +26,18 @@ Change to the new directory for the rest of these steps::
2526

2627
$ cd cc-licenses
2728

28-
Check out the "develop" branch if you're wanting to test things still in development, or "master" for production::
29+
Check out the "develop" branch if you're wanting to test things still
30+
in development, or "master" for production::
2931

3032
$ git checkout develop
3133

3234
Do a ``git pull`` to make sure you have the latest from upstream::
3335

3436
$ git pull origin develop
3537

36-
A word to the wise: I often forget that these things change, and have to remind myself to use
37-
the documentation from the version of the code I'm trying to use.
38+
A word to the wise: I often forget that these things change, and have
39+
to remind myself to use the documentation from the version of the code
40+
I'm trying to use.
3841

3942
Environment
4043
...........
@@ -49,44 +52,56 @@ Activate the venv::
4952

5053
$ . /somepath/cc-licenses-venv/bin/activate
5154

52-
Install the Python requirements for production into the virtual environment. (This is the same whether deploying develop or master.)::
55+
Install the Python requirements for production into the virtual
56+
environment. (This is the same whether deploying develop or master.)::
5357

5458
$ pip install -r requirements/production.txt
5559

5660
Settings
5761
........
5862

59-
We configure a particular site deploy by arranging for a bunch of environment variables to be set before starting Django.
63+
We configure a particular site deploy by arranging for a bunch of
64+
environment variables to be set before starting Django.
6065

6166
Tell Django to use the deploy settings::
6267

6368
$ export DJANGO_SETTINGS_MODULE=cc_licenses.settings.deploy
6469

65-
Set the ENVIRONMENT environment variable to a name to distinguish this deploy from others, e.g. "staging" or "production"::
70+
Set the ENVIRONMENT environment variable to a name to distinguish this
71+
deploy from others, e.g. "staging" or "production"::
6672

6773
$ export ENVIRONMENT=staging
6874

69-
Arrange to make an empty Postgres database available for the site, and set environment variable DATABASE_URL pointing to it::
75+
Arrange to make an empty Postgres database available for the site, and
76+
set environment variable DATABASE_URL pointing to it::
7077

7178
$ export DATABASE_URL="postgresql://user:pass@hostname:port/dbname?sslmode=require"
7279

73-
Note: When coming up with this URL, you can test by seeing if psql can connect to it::
80+
Note: When coming up with this URL, you can test by seeing if psql can
81+
connect to it::
7482

7583
$ psql $DATABASE_URL
7684

77-
Create a local directory for static files. This directory needs to be writable during this deploy process, and readable by the Django server at runtime. Call it STATIC_ROOT::
85+
Create a local directory for static files. This directory needs to be
86+
writable during this deploy process, and readable by the Django server
87+
at runtime. Call it STATIC_ROOT::
7888

7989
$ export STATIC_ROOT=/path/to/staticfiles
8090

81-
(This is for files that come from the site source code and will be served as static files, like ``.css`` and ``.js`` files.)
91+
(This is for files that come from the site source code and will be served
92+
as static files, like ``.css`` and ``.js`` files.)
8293

83-
Create a local directory for media files. This directory must be readable and writable by the Django process at runtime. Call it MEDIA_ROOT::
94+
Create a local directory for media files. This directory must be readable
95+
and writable by the Django process at runtime. Call it MEDIA_ROOT::
8496

8597
$ export MEDIA_ROOT=/path/to/mediafiles
8698

87-
(This is for any files that might need to be uploaded by users and stored by the Django process, then served again later. Examples: images, avatars, files - it depends on the site.)
99+
(This is for any files that might need to be uploaded by users and stored
100+
by the Django process, then served again later. Examples: images, avatars,
101+
files - it depends on the site.)
88102

89-
Generate a secret key to use, which should be a long random string. One way::
103+
Generate a secret key to use, which should be a long random string. One
104+
way::
90105

91106
#!/usr/bin/env python3
92107
from django.utils.crypto import get_random_string
@@ -97,32 +112,41 @@ Then set it as DJANGO_SECRET_KEY::
97112

98113
$ export DJANGO_SECRET_KEY=<the random string from above>
99114

100-
This should be different for each site being deployed, but the same on all servers running Django for a particular site, and not changing over time.
115+
This should be different for each site being deployed, but the same on
116+
all servers running Django for a particular site, and not changing over
117+
time.
101118

102119
Set DOMAIN to the hostname the site will be served at::
103120

104121
$ export DOMAIN=www.example.com
105122

106-
The site might need to send email to admins on errors, and to users for things like password resets. Arrange to make an SMTP server available for outgoing email, then set the following Django settings as environment variables:
123+
The site might need to send email to admins on errors, and to users for
124+
things like password resets. Arrange to make an SMTP server available for
125+
outgoing email, then set the following Django settings as environment
126+
variables:
107127

108128
* EMAIL_HOST
109129
* EMAIL_HOST_USER
110130
* EMAIL_HOST_PASSWORD
111131
* EMAIL_USE_TLS
112-
* EMAIL_USE_SSL (just set one of EMAIL_USE_TLS or EMAIL_USE_TLS to a non-empty string to indicate "True"; leave the other unset)
113-
* EMAIL_PORT (optional; defaults to 25, 465, or 587 depending on whether EMAIL_USE_TLS, EMAIL_USE_SSL, or neither are set)
132+
* EMAIL_USE_SSL (just set one of EMAIL_USE_TLS or EMAIL_USE_TLS to a
133+
non-empty string to indicate "True"; leave the other unset)
134+
* EMAIL_PORT (optional; defaults to 25, 465, or 587 depending on
135+
whether EMAIL_USE_TLS, EMAIL_USE_SSL, or neither are set)
114136
* DEFAULT_FROM_EMAIL
115137
* EMAIL_SUBJECT_PREFIX
116138

117139
These are documented starting
118-
`here <https://docs.djangoproject.com/en/3.0/ref/settings/#email-host>`_; I won't bother copying the docs.
140+
`here <https://docs.djangoproject.com/en/3.0/ref/settings/#email-host>`_;
141+
I won't bother copying the docs.
119142

120143
Migrate and collect static
121144
..........................
122145

123-
There are a couple of tasks that need to be done any time the code is updated, before (re)starting
124-
the server. The migrate step only needs to be done on one server since it updates the database
125-
that all servers are sharing. The collectstatic step needs to be done on every server.
146+
There are a couple of tasks that need to be done any time the code is
147+
updated, before (re)starting the server. The migrate step only needs to
148+
be done on one server since it updates the database that all servers are
149+
sharing. The collectstatic step needs to be done on every server.
126150

127151
We generally build this into our deploy process.
128152

@@ -143,12 +167,16 @@ We generally build this into our deploy process.
143167
Run Django
144168
..........
145169

146-
To get a process running Django and serving requests, we'll use a tool called `gunicorn <https://gunicorn.org/>`_ that's installed into the virtual environment.
170+
To get a process running Django and serving requests, we'll use a tool
171+
called `gunicorn <https://gunicorn.org/>`_ that's installed into the
172+
virtual environment.
147173

148174
We'll run this strictly internally, listening for requests on a Unix port.
149175
Our web server will proxy to that port.
150176

151-
Reminder: arrange for the environment variables mentioned above to be set before gunicorn is started. (You can set them on the gunicorn command line with ``-e``, but it gets unwieldy.)
177+
Reminder: arrange for the environment variables mentioned above to be set
178+
before gunicorn is started. (You can set them on the gunicorn command
179+
line with ``-e``, but it gets unwieldy.)
152180

153181
::
154182

@@ -160,11 +188,14 @@ Gunicorn has lots of options for tuning which you can look up.
160188
Run a webserver in front
161189
........................
162190

163-
We usually run nginx as our front-end web server. A simple approach is to add a new config file to /etc/nginx/sites-enabled for each site, making sure
164-
server_name is set correctly in each. E.g. ``/etc/nginx/sites-enabled/www.example.com.conf``
165-
(the name is completely arbitrary). Then reload or restart nginx.
191+
We usually run nginx as our front-end web server. A simple approach is to
192+
add a new config file to /etc/nginx/sites-enabled for each site, making
193+
sure server_name is set correctly in each. E.g.
194+
``/etc/nginx/sites-enabled/www.example.com.conf`` (the name is completely
195+
arbitrary). Then reload or restart nginx.
166196

167-
In that config file, we generally want to redirect non-SSL requests to SSL with something like::
197+
In that config file, we generally want to redirect non-SSL requests to
198+
SSL with something like::
168199

169200
server {
170201
listen *:80;
@@ -177,11 +208,11 @@ In that config file, we generally want to redirect non-SSL requests to SSL with
177208

178209
changing DOMAIN and PATH appropriately.
179210

180-
Then we proxy the SSL requests to Django, by adding something like this to the file (the SSL
181-
cipher settings might be out of date, though).
211+
Then we proxy the SSL requests to Django, by adding something like this
212+
to the file (the SSL cipher settings might be out of date, though).
182213

183-
Note: *after* this is known to be working, you can uncomment the ``Strict-Transport-Security``
184-
line if you want.
214+
Note: *after* this is known to be working, you can uncomment the
215+
``Strict-Transport-Security`` line if you want.
185216

186217
You'll need a valid SSL certificate for this.
187218

@@ -239,13 +270,15 @@ Again, change the all-caps parts appropriately::
239270
Troubleshooting
240271
---------------
241272

242-
Once all that is running, you should be able to visit https://www.example.com and see
243-
the site front page. But, sometimes not everything is quite right the first time :-)
273+
Once all that is running, you should be able to visit
274+
https://www.example.com and see the site front page. But, sometimes not
275+
everything is quite right the first time :-)
244276

245-
A gateway error indicates that gunicorn isn't running. Add some gunicorn logging if necessary,
246-
and check those logs.
277+
A gateway error indicates that gunicorn isn't running. Add some gunicorn
278+
logging if necessary, and check those logs.
247279

248-
If you see the wrong site, nginx isn't properly routing requests for that server name
249-
to our server. See http://nginx.org/en/docs/http/server_names.html. Keep in mind that
250-
nginx defaults to just sending requests to the first server it can find if it doesn't
251-
recognize the incoming server name.
280+
If you see the wrong site, nginx isn't properly routing requests for that
281+
server name to our server. See
282+
http://nginx.org/en/docs/http/server_names.html. Keep in mind that nginx
283+
defaults to just sending requests to the first server it can find if it
284+
doesn't recognize the incoming server name.

0 commit comments

Comments
 (0)