Skip to content

Commit e74ee1a

Browse files
committed
Merge branch 'main' of github.com:hjwp/Book-TDD-Web-Dev-Python
2 parents 9457485 + 9f19454 commit e74ee1a

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

chapter_09_docker.asciidoc

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,11 @@ and where testing fits in.
301301
* Get a first cut of our code up and running inside Docker,
302302
with passing tests.
303303

304+
// DAVID: might be worth condensing this bulleted list, it's rather skimmable
305+
// at the moment. For example is there any difference between the first and fourth point?
304306

305307
//RITA: Consider cross-referencing the chapter by number here so we can hyperlink it for convenience.
308+
306309
**Next chapter: Moving to a production-ready configuration**
307310

308311
* Gradually, incrementally change the container configuration
@@ -360,7 +363,7 @@ class NewVisitorTest(StaticLiveServerTestCase):
360363
self.live_server_url = "http://" + test_server #<2>
361364
----
362365
====
363-
366+
// DAVID: could use a walrus operator here?
364367

365368
Do you remember I said that `LiveServerTestCase` had certain limitations?
366369
Well, one is that it always assumes you want to use its own test server,
@@ -463,17 +466,21 @@ TIP: Don't use `export` to set the 'TEST_SERVER' environment variable;
463466

464467
==== Making an src Folder
465468

469+
// DAVID: FWIW it reads weirdly to me to have 'an src' rather than 'a src'.
470+
// It's probably because I pronounce it as 'source' rather than 'S.R.C.'
471+
466472
When preparing a codebase for deployment,
467473
it's often convenient to separate out the actual source code of our production app,
468474
from the rest of the files that you need in the project.
469475
A folder called _src_ is a common convention.
470476

477+
// DAVID: I'd expect src here and below to be in monospace.
478+
471479
Currently, all our code is source code really, so we move everything into _src_
472-
(we'll be seeing some new files appearing outside _src_ shortly.footnote:[
480+
(we'll be seeing some new files appearing outside _src_ shortly).footnote:[
473481
A common thing to find outside of the _src_ folder is a folder called _tests_.
474482
We won't be doing that while we're relying on the standard Django test framework,
475483
but it's a good thing to do if you're using pytest, for example.]
476-
)
477484

478485

479486

@@ -520,6 +527,13 @@ Cool! We'll find out more about all of these steps as the chapter progresses.
520527
Impartiality commands me to also recommend https://podman.io/[Podman],
521528
which is a like-for-like replacement for Docker.
522529
530+
// DAVID: It might be worth mentioning Colima, which I have running on my machine
531+
// instead of Docker because of licensing restrictions. I was able to run the
532+
// same command because I have Colima installed. The good thing about Colima
533+
// is you just use the same `docker` command, don't need to change it.
534+
// Also - possibly worth moving the alternatives a couple of paras further
535+
// up, so that they know their options before running the Docker install?
536+
523537
It's pretty much exactly the same as Docker,
524538
arguably with a few advantages even, but I won't go into detail here.
525539
@@ -531,7 +545,7 @@ Docker is open source too,
531545
so I decided to stick with it. But you could definitely check it out!
532546
533547
You can follow along all the instructions in the book
534-
by just substituing the `docker` binary for `podman` in all the CLI instructions,
548+
by just substituting the `docker` binary for `podman` in all the CLI instructions,
535549
e.g.
536550
537551
[role="skipme"]
@@ -554,6 +568,9 @@ including the operating system, dependencies, and any code you want to run.
554568

555569
Once you have an image, you can run one or many containers that use the same image.
556570

571+
// DAVID: Not sure whether this is going to be understandable in its current form.
572+
// An analogy that I find helpful here is that images are like classes
573+
// and containers are like instances.
557574

558575
==== A First Cut of a Dockerfile
559576

@@ -570,6 +587,11 @@ What do we need to do? Something like this, right?
570587
We create a new file called _Dockerfile_ in the base folder of our repo,
571588
next to the `src/` directory we made earlier:
572589

590+
// DAVID: As discussed, I misread this and put the Dockerfile in src.
591+
// That led to a difficult to understand error message when I tried to build.
592+
// ERROR: failed to solve: failed to compute cache key: failed to calculate
593+
// checksum of ref e126cbb4-3e0c-4e6e-867f-dbfbf5fb190f::k2oys44pcnbefrlpps3ooux7w: "/src": not found
594+
573595
// JAN: I'd suggest to use python3.11:slim or python3:12 slim. Keeping image tags too open leads to issues in a couple of months (not always, but waaay too often)
574596
// JAN: I'd use Docker comments with # for <1>, <2>, ... Otherwise, you need to edit the code when you paste it
575597

@@ -715,6 +737,9 @@ environment?
715737
----
716738
717739
740+
// DAVID: I got:
741+
// python: can't open file '/src/manage.py': [Errno 2] No such file or directory
742+
718743
Ah, we forgot that we need to install Django.
719744
720745
@@ -758,6 +783,7 @@ CMD python manage.py runserver
758783
<3> We install Django with `pip install`, just like we do locally.
759784
760785
786+
// DAVID: Why bother with a virtualenv?
761787
762788
==== Successful Run
763789
@@ -809,6 +835,7 @@ WARNING: Make sure you use the `-it` flags to the Docker `run`
809835
to interrupt the docker process with _Ctrl-C_.
810836
See <<how-to-stop-a-docker-container>> for an escape hatch.
811837
838+
// DAVID: behaviours -> behaviour?
812839
813840
[[how-to-stop-a-docker-container]]
814841
.How to Stop a Docker Container
@@ -826,6 +853,8 @@ you can kill it from another one.
826853
// harsh...
827854
828855
856+
// DAVID: are we actually killing it from another container?
857+
829858
The docker daemon lets you list all the currently running containers
830859
with `docker ps`:
831860
@@ -1046,7 +1075,10 @@ $ *docker build -t superlists . && docker run -p 8888:8888 -it superlists*
10461075
Now that will _change_ the error we see, but only quite subtly (see <<firefox-connection-reset>>).
10471076
Things clearly aren't working yet.
10481077
1078+
// DAVID: FWIW in Chrome the message is "127.0.0.1 didn’t send any data."
1079+
10491080
//RITA: If at all possible, I suggest using the light or daytime theme for all browser screenshots to make them easier to read.
1081+
10501082
[[firefox-connection-reset]]
10511083
.Cannot connect on that port
10521084
image::images/firefox-connection-reset.png["Firefox showing the 'Connection reset' error"]
@@ -1121,6 +1153,9 @@ The long and short of it is that
11211153
we need use the long-form `ipaddr:port` version of the `runserver` command,
11221154
using the magic "wilcard" IP address `0.0.0.0`:
11231155
1156+
// DAVID: Some readers might not be that comfortable with the idea of ports.
1157+
// I think this could do with more explanation.
1158+
11241159
.Dockerfile (ch09l007)
11251160
====
11261161
[source,dockerfile]
@@ -1142,6 +1177,7 @@ $ *docker build -t superlists . && docker run -p 8888:8888 -it superlists*
11421177
Starting development server at http://0.0.0.0:8888/
11431178
----
11441179
1180+
11451181
We can verify it's working with `curl`:
11461182
11471183
[subs="specialcharacters,macros"]
@@ -1229,6 +1265,8 @@ we highlighted as one of the "danger areas" of deployment).
12291265
You might have spotted the yellow Django debug page (<<django-debug-screen>>)
12301266
telling us as much, or if you tried it manually.
12311267
1268+
// DAVID: Grammar on that last sentence?
1269+
12321270
NOTE: The tests saved us from potential embarrassment there.
12331271
The site _looked_ fine when we loaded its front page.
12341272
If we'd been a little hasty and only testing manually,
@@ -1248,6 +1286,8 @@ To be fair, if you look back through the `runserver` command output
12481286
each time we've been starting our container,
12491287
you'll see it's been warning us about this issue:
12501288
1289+
// DAVID: mix between 'you' and 'our' reads weirdly.
1290+
12511291
[role="skipme"]
12521292
----
12531293
You have 19 unapplied migration(s). Your project may not work properly until
@@ -1309,6 +1349,9 @@ OK
13091349
But we don't actually want to package up our database _inside_ the image, do we?
13101350
We want the database on the server to have totally separate data from the one on our machine.
13111351
1352+
// DAVID: This is an important point which might need a bit more explanation.
1353+
// What would happen if we did?
1354+
13121355
In most deployments, you'd probably be talking to a separate database server, like postgres.
13131356
13141357
For the purposes of this book, the easiest analogy to a server that's "outside" our container,
@@ -1402,7 +1445,7 @@ Ahem, that's definitely good enough for now! Let's commit.
14021445
$ *git add Dockerfile*
14031446
$ *git commit -m"First cut of a Dockerfile"*
14041447
----
1405-
1448+
// DAVID: This is the second cut really?
14061449
14071450
Phew. Well, it took a bit of hacking about,
14081451
but now we can be reassured that the basic Docker plumbing works.
@@ -1416,6 +1459,7 @@ In the next chapter, we'll make our hacky image more production-ready.
14161459
But first, time for a well-earned tea break I think, and perhaps a
14171460
https://en.wikipedia.org/wiki/Digestive_biscuit[chocolate biscuit].
14181461
1462+
// DAVID: That ain't no chocolate biscuit!
14191463
14201464
.Test-Driving Server Configuration and Deployment
14211465
*******************************************************************************

0 commit comments

Comments
 (0)