Skip to content

Commit f7ac313

Browse files
committed
Merge branch 'StephanieAG-StephanieAG-patch-1-OTG'
2 parents 025ffca + 6dd5981 commit f7ac313

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

chapter_10_production_readiness.asciidoc

Lines changed: 35 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)
@@ -260,9 +267,6 @@ Let's rerun our FTs to confirm:
260267
// If we do that, however, we'll need to make sure readers rebuild the image each time
261268
// we add a requirement - such as at this point.
262269

263-
264-
// JAN: That doesn't work until you install whitenoise to venv on local machine
265-
266270
[role="small-code"]
267271
[subs="specialcharacters,macros"]
268272
----
@@ -378,6 +382,7 @@ $ *git add requirements.txt*
378382
$ *git commit -m "Add a requirements.txt with Django, gunicorn and whitenoise"*
379383
----
380384

385+
381386
You may be wondering why we didn't add our other dependency,
382387
Selenium, to our requirements,
383388
or why we didn't just add _all_ the dependencies,
@@ -447,7 +452,7 @@ TIP: Forgetting the `-r` and running `pip install requirements.txt`
447452
// since it's related to the app being production ready).
448453
// TODO yep let's definitely do this.
449454

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

452457
[subs="specialcharacters,quotes"]
453458
----
@@ -457,6 +462,18 @@ $ *docker build -t superlists . && docker run \
457462
-it superlists*
458463
----
459464

465+
And then test to check everything still works:
466+
467+
[role="small-code"]
468+
[subs="specialcharacters,macros"]
469+
----
470+
$ pass:quotes[*TEST_SERVER=localhost:8888 python src/manage.py test functional_tests \
471+
--failfast*]
472+
[...]
473+
474+
OK
475+
----
476+
460477
=== Using Environment Variables to Adjust Settings for Production
461478

462479
((("DEBUG settings")))
@@ -495,9 +512,10 @@ Environment variables also have the advantage of working for non-Django stuff to
495512
There are lots of ways you might do this.
496513

497514
Here's what I propose; it may seem a little fiddly,
498-
but I'll provide a little justification for each choice.
515+
but I'll provide a little justification for each choice.
499516
Let them be an inspiration (but not a template) for your own choices!
500517

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

502520
[role="sourcecode"]
503521
.superlists/settings.py (ch10l006)
@@ -745,7 +763,15 @@ CMD gunicorn --bind :8888 superlists.wsgi:application
745763

746764
// TODO: gitignore src/static
747765

748-
Well, it was fiddly, but that should get us to passing tests!
766+
Well, it was fiddly, but that should get us to passing tests after we build & run the docker container!
767+
768+
[subs="specialcharacters,quotes"]
769+
----
770+
$ *docker build -t superlists . && docker run \
771+
-p 8888:8888 \
772+
--mount type=bind,source=./src/db.sqlite3,target=/src/db.sqlite3 \
773+
-it superlists*
774+
----
749775

750776

751777
[role="small-code"]
@@ -861,7 +887,7 @@ If you're like me you might find yourself wondering if we really _did_ see them
861887
and starting to doubt your own sanity.
862888
But the explanation is that Django's
863889
https://docs.djangoproject.com/en/4.2/ref/logging/#default-logging-configuration[default logging configuration]
864-
changes when DEBUG is turned off:
890+
changes when DEBUG is turned off.
865891

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

875901
Here's pretty much the simplest possible logging config
876-
which just prints everything to the console (i.e. standard out).
902+
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.
877903

878904

879905
[role="sourcecode"]

0 commit comments

Comments
 (0)