@@ -80,14 +80,12 @@ We'll need to first install Gunicorn into our container,
80
80
and then use it instead of `runserver`:
81
81
82
82
83
- // todo test this
84
- [role="skipme"]
85
83
[subs="specialcharacters,quotes"]
86
84
----
87
- $ *pip install gunicorn*
85
+ $ *python -m pip install gunicorn*
88
86
Collecting gunicorn
89
87
[...]
90
- Successfully installed gunicorn-21.2.0
88
+ Successfully installed gunicorn-22.[...]
91
89
----
92
90
93
91
[[what-is-wsgi]]
@@ -173,8 +171,7 @@ As we run the functional tests, you'll see them warning us of a problem, once ag
173
171
The test for adding list items passes happily,
174
172
but the test for layout + styling fails. Good job, tests!
175
173
176
- // todo: replace pause-first with systematic pause after every docker spinup
177
- [role="small-code pause-first"]
174
+ [role="small-code"]
178
175
[subs="specialcharacters,macros"]
179
176
----
180
177
$ pass:quotes[*TEST_SERVER=localhost:8888 python src/manage.py test functional_tests \
@@ -216,7 +213,7 @@ files from Python.
216
213
217
214
First we install Whitenoise into our local environment:
218
215
219
- [role="skipme"]
216
+
220
217
[subs="specialcharacters,quotes"]
221
218
----
222
219
*pip install whitenoise*
@@ -315,8 +312,9 @@ I'm sure you'll come across many others.]
315
312
316
313
The `pip freeze` command will show us everything that's installed in our virtualenv at the moment:
317
314
318
- // JAN: This is true only if one installs the libraries locally. So far when following the book we installed them only inside Docker image
319
315
316
+ // version numbers change too much
317
+ [role="skipme"]
320
318
[subs="specialcharacters,quotes"]
321
319
----
322
320
$ *pip freeze*
@@ -351,7 +349,7 @@ Django, Gunicorn and Whitenoise:
351
349
[subs="specialcharacters,quotes"]
352
350
----
353
351
$ *pip freeze | grep -i django*
354
- Django==4.2.11
352
+ Django==4.2.[...]
355
353
356
354
$ *pip freeze | grep -i django >> requirements.txt*
357
355
$ *pip freeze | grep -i gunicorn >> requirements.txt*
@@ -361,7 +359,7 @@ $ *pip freeze | grep -i whitenoise >> requirements.txt*
361
359
That should give us a requirements.txt file that looks like this:
362
360
363
361
364
- [role="sourcecode"]
362
+ [role="sourcecode skipme "]
365
363
.requirements.txt (ch10l004)
366
364
====
367
365
[source,python]
@@ -410,6 +408,7 @@ TIP: Itamar Turner-Traurig has a great guide to
410
408
411
409
Now let's see how we use that requirements file in our Dockerfile:
412
410
411
+ [role="sourcecode"]
413
412
.Dockerfile (ch10l005)
414
413
====
415
414
[source,dockerfile]
@@ -510,7 +509,7 @@ Let them be an inspiration (but not a template) for your own choices!
510
509
Note that this if statement replaces the DEBUG and SECRET_KEY lines that are included by default in the settings.py file:
511
510
512
511
[role="sourcecode"]
513
- .superlists/settings.py (ch10l006)
512
+ .src/ superlists/settings.py (ch10l006)
514
513
====
515
514
[source,python]
516
515
----
@@ -578,6 +577,7 @@ And try it out...
578
577
579
578
580
579
580
+ [role="ignore-errors"]
581
581
[subs="specialcharacters,macros"]
582
582
----
583
583
$ pass:specialcharacters,quotes[*docker build -t superlists . && docker run \
@@ -589,7 +589,7 @@ $ pass:specialcharacters,quotes[*docker build -t superlists . && docker run \
589
589
File "/src/superlists/settings.py", line 22, in <module>
590
590
SECRET_KEY = os.environ["DJANGO_SECRET_KEY"]
591
591
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
592
- File "<frozen os>", line 685, in __getitem__
592
+ [...]
593
593
KeyError: 'DJANGO_SECRET_KEY'
594
594
----
595
595
@@ -673,7 +673,7 @@ Let's use another environment variable for that:
673
673
674
674
675
675
[role="sourcecode"]
676
- .superlists/settings.py (ch10l008)
676
+ .src/ superlists/settings.py (ch10l008)
677
677
====
678
678
[source,python]
679
679
----
@@ -744,7 +744,7 @@ ENV DJANGO_DEBUG_FALSE=1
744
744
CMD gunicorn --bind :8888 superlists.wsgi:application
745
745
----
746
746
====
747
- // CSANAD: I think it would be important to use a non-privileged user in Docker
747
+
748
748
749
749
// DAVID: It would be nice to explain the difference between RUN and CMD.
750
750
@@ -760,9 +760,11 @@ Well, it was fiddly, but that should get us to passing tests after we build & ru
760
760
[subs="specialcharacters,quotes"]
761
761
----
762
762
$ *docker build -t superlists . && docker run \
763
- -p 8888:8888 \
764
- --mount type=bind,source=./src/db.sqlite3,target=/src/db.sqlite3 \
765
- -it superlists*
763
+ -p 8888:8888 \
764
+ --mount type=bind,source=./src/db.sqlite3,target=/src/db.sqlite3 \
765
+ -e DJANGO_SECRET_KEY=sekrit \
766
+ -e DJANGO_ALLOWED_HOST=localhost \
767
+ -it superlists*
766
768
----
767
769
768
770
and...
@@ -811,6 +813,7 @@ TODO: apologies, WIP, this is definitely a good idea for security, needs writing
811
813
812
814
Dockerfile should gain some lines a bit like this:
813
815
816
+ [role="sourcecode skipme"]
814
817
.Dockerfile (ch10l0XX)
815
818
====
816
819
[source,dockerfile]
@@ -868,6 +871,7 @@ image::images/server_error_500.png["A minimal error page saying just Server erro
868
871
869
872
But if you look in your docker terminal, you'll see there is no traceback:
870
873
874
+ [role="skipme"]
871
875
----
872
876
[2024-02-28 10:41:53 +0000] [7] [INFO] Starting gunicorn 21.2.0
873
877
[2024-02-28 10:41:53 +0000] [7] [INFO] Listening at: http://0.0.0.0:8888 (7)
@@ -918,10 +922,23 @@ LOGGING = {
918
922
----
919
923
====
920
924
921
- Rebuild and restart our container,
922
- try the FT again (or submitting a new list item manually)
925
+ Rebuild and restart our container...
926
+
927
+ [subs="specialcharacters,quotes"]
928
+ ----
929
+ $ *docker build -t superlists . && docker run \
930
+ -p 8888:8888 \
931
+ --mount type=bind,source=./src/db.sqlite3,target=/src/db.sqlite3 \
932
+ -e DJANGO_SECRET_KEY=sekrit \
933
+ -e DJANGO_ALLOWED_HOST=localhost \
934
+ -it superlists*
935
+ ----
936
+
937
+ Then try the FT again (or submitting a new list item manually)
923
938
and we now should see a clear error message:
924
939
940
+ // TODO: test get from docker logs
941
+ [role="skipme"]
925
942
----
926
943
Internal Server Error: /lists/new
927
944
Traceback (most recent call last):
@@ -946,7 +963,7 @@ when considering production-readiness,
946
963
we've worked in small steps and used our tests all the way along,
947
964
and we're now ready to deploy our container to a real server!
948
965
949
- Find out how, in our next exciting installment ...
966
+ Find out how, in our next exciting instalment ...
950
967
951
968
952
969
[role="pagebreak-before less_space"]
0 commit comments