@@ -41,7 +41,7 @@ Instead, we'll use the popular Gunicorn Python/WSGI server.
41
41
In addition, several options in _settings.py_ are currently unacceptable.
42
42
`DEBUG=True`, is strongly recommended against for production,
43
43
we'll want to set a unique `SECRET_KEY`,
44
- and as we'll see, other things will come up.
44
+ and, as we'll see, other things will come up.
45
45
46
46
Let's go through and see if we can fix things one by one.
47
47
@@ -81,6 +81,8 @@ CMD gunicorn --bind :8888 superlists.wsgi:application
81
81
----
82
82
====
83
83
84
+ // DAVID: Does this need a bit more explanation?
85
+
84
86
As in the previous chapter, we can use the `docker build && docker run`
85
87
pattern to try out our changes by rebuilding and rerunning our container:
86
88
@@ -92,7 +94,11 @@ $ *docker build -t superlists . && docker run \
92
94
-it superlists*
93
95
----
94
96
95
-
97
+ // DAVID: Incidentally I got the following error:
98
+ // Bind for 0.0.0.0:8888 failed: port is already allocated.
99
+ // Turned out the previous container was still running,
100
+ // I just used the docker kill process you taught me about earlier.
101
+ // Not sure if it's worth including that here, possibly clutter?
96
102
97
103
98
104
@@ -169,6 +175,11 @@ MIDDLEWARE = [
169
175
And if you take another manual look at your site, things should look much healthier.
170
176
Let's rerun our FTs to confirm:
171
177
178
+ // DAVID: Incidentally as per your suggestion Harry I have just been skipping
179
+ // the requirements.txt and instead just amending the pip install in the Dockerfile.
180
+ // If we do that, however, we'll need to make sure readers rebuild the image each time
181
+ // we add a requirement - such as at this point.
182
+
172
183
[role="small-code"]
173
184
[subs="specialcharacters,macros"]
174
185
----
@@ -182,6 +193,11 @@ Ran 3 tests in 10.718s
182
193
OK
183
194
----
184
195
196
+ // DAVID: I got
197
+ // UserWarning: No directory at: /Users/david.seddon/Documents/reviewing/goat-book/src/static/
198
+ // mw_instance = middleware(adapted_handler)
199
+ // I think we need to move the static folder into src too, in the previous chapter.
200
+
185
201
Phew. Let's commit that
186
202
187
203
[subs="specialcharacters,quotes"]
@@ -268,7 +284,7 @@ TIP: Better to fail hard than allow a typo in an environment variable name to
268
284
269
285
==== Setting environment variables inside the Dockerfile
270
286
271
- Now let's set that environment variable in our Dockerfile using then `ENV` directive:
287
+ Now let's set that environment variable in our Dockerfile using the `ENV` directive:
272
288
273
289
[role="sourcecode"]
274
290
.Dockerfile (ch10l006)
@@ -364,7 +380,7 @@ image::images/search-results-400-bad-request.png["Duckduckgo search results with
364
380
`ALLOWED_HOSTS` is a security setting
365
381
designed to reject requests that are likely to be forged, broken or malicious
366
382
because they don't appear to be asking for your site
367
- (HTTP request contain the address they were intended for in a header called "Host").
383
+ (HTTP requests contain the address they were intended for in a header called "Host").
368
384
369
385
By default, when DEBUG=True, `ALLOWED_HOSTS` effectively allows _localhost_,
370
386
our own machine, so that's why it was working OK until now.
@@ -444,6 +460,12 @@ CMD gunicorn --bind :8888 superlists.wsgi:application
444
460
----
445
461
====
446
462
463
+ // DAVID: It would be nice to explain the difference between RUN and CMD.
464
+
465
+ // DAVID: Interestingly when I did this I put the RUN directive after the ENV
466
+ // directive, which led to a KeyError: 'DJANGO_SECRET_KEY' which foxed me for a bit.
467
+ // Might be worth calling out that we're running collectstatic in debug mode.
468
+
447
469
Well, it was fiddly, but that should get us to passing tests!
448
470
449
471
457
479
458
480
We have a container that we're ready to ship to production!
459
481
482
+ // DAVID: It might be worth pointing out what Whitenoise is actually doing.
483
+ // From what I understand, we're still using Django to serve static files.
484
+
460
485
Find out how in the next exciting installment...
461
486
462
487
@@ -482,7 +507,7 @@ $ *rm src/db.sqlite3 && touch src/db.sqlite3*
482
507
TIP: If you use the `-v` option for docker run to mount a nonexistent path,
483
508
Docker will create a new folder at that path.
484
509
This is why we do the `touch db.sqlite3`
485
- so that we have a placeholder empty file where the datbase should be.
510
+ so that we have a placeholder empty file where the database should be.
486
511
Otherwise we get a folder instead of an empty file and django gets even more confused;
487
512
if you ever see an error saying `chown: permission denied`, that's probably it.
488
513
Do a `rm -rf src/db.sqlite3 && touch src/db.sqlite3` to fix it.
@@ -501,6 +526,10 @@ selenium.common.exceptions.NoSuchElementException: Message: Unable to locate
501
526
element: [id="id_list_table"]; [...]
502
527
----
503
528
529
+ // DAVID: Got me thinking, I'm not always clear when I need to rebuild the image.
530
+ // I would have thought I might need to do it here, but I didn't. Might be worth
531
+ // explaining in the previous chapter when we do.
532
+
504
533
And you might spot in the browser that we just see a minimal error page,
505
534
with no debug info (try it manually if you like):
506
535
@@ -536,7 +565,7 @@ I mean, yes, separating the concepts of handlers and loggers and filters,
536
565
and making it all configurable in a nested hierarchy is all well and good
537
566
and covers every possible use case,
538
567
but sometimes you just wanna say "just print stuff to stdout pls",
539
- and you wish that configuring the simplest thing was a little easier].
568
+ and you wish that configuring the simplest thing was a little easier. ].
540
569
541
570
Here's pretty much the simplest possible logging config
542
571
which just prints everything to the console (ie standard out).
@@ -564,7 +593,6 @@ Rebuild and restart our container,
564
593
try the FT again (or submitting a new list item manually)
565
594
and we now should see a clear error message:
566
595
567
-
568
596
----
569
597
Internal Server Error: /lists/new
570
598
Traceback (most recent call last):
0 commit comments