Skip to content

Commit b5892d0

Browse files
authored
Updated chapter_10_production_readiness.asciidoc
potential edits to OTG Ch 10
1 parent e55c8e2 commit b5892d0

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

chapter_10_production_readiness.asciidoc

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,14 @@ Believe it or not, this pun didn't actually hit me until I was rewriting this ch
212212
For 10 years it was right under my nose. I think that makes it funnier actually.]
213213
files from Python.
214214

215-
This is how we tell Django to enable it, in _settings.py_:
215+
First we install whitenoise into our local environment:
216+
217+
[source,python]
218+
----
219+
pip install whitenoise
220+
----
221+
222+
Then we tell Django to enable it, in _settings.py_:
216223

217224
[role="sourcecode"]
218225
.src/superlists/settings.py (ch10l002)
@@ -263,9 +270,6 @@ Let's rerun our FTs to confirm:
263270
// If we do that, however, we'll need to make sure readers rebuild the image each time
264271
// we add a requirement - such as at this point.
265272

266-
267-
// JAN: That doesn't work until you install whitenoise to venv on local machine
268-
269273
[role="small-code"]
270274
[subs="specialcharacters,macros"]
271275
----
@@ -379,10 +383,13 @@ That's a good first cut, let's commit it:
379383
// But I understand it's a trade-off so the reader does get bogged down.
380384
// TODO: add a note about this and a link to some more reading
381385

386+
====
387+
[subs="specialcharacters,quotes"]
382388
----
383389
$ *git add requirements.txt*
384390
$ *git commit -m "Add a requirements.txt with Django, gunicorn and whitenoise"*
385391
----
392+
====
386393

387394
You may be wondering why we didn't add our other dependency,
388395
Selenium, to our requirements,
@@ -452,7 +459,7 @@ TIP: Forgetting the `-r` and running `pip install requirements.txt`
452459
// But we can cover this in a later chapter (the next one looks like a good fit,
453460
// since it's related to the app being production ready).
454461

455-
Let's do a build & run & test to check everything still works:
462+
Let's build & run:
456463

457464
[subs="specialcharacters,quotes"]
458465
----
@@ -462,6 +469,18 @@ $ *docker build -t superlists . && docker run \
462469
-it superlists*
463470
----
464471

472+
And then test to check everything still works:
473+
474+
[role="small-code"]
475+
[subs="specialcharacters,macros"]
476+
----
477+
$ pass:quotes[*TEST_SERVER=localhost:8888 python src/manage.py test functional_tests \
478+
--failfast*]
479+
[...]
480+
481+
OK
482+
----
483+
465484
=== Using Environment Variables to Adjust Settings for Production
466485

467486
((("DEBUG settings")))
@@ -500,9 +519,10 @@ Environment variables also have the advantage of working for non-Django stuff to
500519
There are lots of ways you might do this.
501520

502521
Here's what I propose; it may seem a little fiddly,
503-
but I'll provide a little justification for each choice.
522+
but I'll provide a little justification for each choice.
504523
Let them be an inspiration (but not a template) for your own choices!
505524

525+
Note that this if statement replaces the DEBUG and SECRET_KEY lines that are included by default in the settings.py file:
506526

507527
[role="sourcecode"]
508528
.superlists/settings.py (ch10l006)
@@ -749,7 +769,15 @@ CMD gunicorn --bind :8888 superlists.wsgi:application
749769

750770
// TODO: gitignore src/static
751771

752-
Well, it was fiddly, but that should get us to passing tests!
772+
Well, it was fiddly, but that should get us to passing tests after we build & run the docker container!
773+
774+
[subs="specialcharacters,quotes"]
775+
----
776+
$ *docker build -t superlists . && docker run \
777+
-p 8888:8888 \
778+
--mount type=bind,source=./src/db.sqlite3,target=/src/db.sqlite3 \
779+
-it superlists*
780+
----
753781

754782

755783
[role="small-code"]
@@ -865,7 +893,7 @@ If you're like me you might find yourself wondering if we really _did_ see them
865893
and starting to doubt your own sanity.
866894
But the explanation is that Django's
867895
https://docs.djangoproject.com/en/4.2/ref/logging/#default-logging-configuration[default logging configuration]
868-
changes when DEBUG is turned off:
896+
changes when DEBUG is turned off.
869897

870898
This means we need to interact with the standard library's `logging` module,
871899
unfortunately one of the most fiddly parts of the Python standard libraryfootnote:[
@@ -877,7 +905,7 @@ but sometimes you just wanna say "just print stuff to stdout pls",
877905
and you wish that configuring the simplest thing was a little easier.].
878906

879907
Here's pretty much the simplest possible logging config
880-
which just prints everything to the console (i.e. standard out).
908+
which just prints everything to the console (i.e. standard out). I've added this code to the very end of the settings.py file.
881909

882910

883911
[role="sourcecode"]

0 commit comments

Comments
 (0)