Skip to content

Commit 2abede7

Browse files
committed
A bit of reordering in 9
1 parent 63ca6a4 commit 2abede7

File tree

1 file changed

+59
-78
lines changed

1 file changed

+59
-78
lines changed

chapter_09_docker.asciidoc

+59-78
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
****
66
With Early Release ebooks, you get books in their earliest form—the author's raw and unedited content as they write—so you can take advantage of these technologies long before the official release of these titles.
77
8-
This will be the 9th chapter of the final book. The GitHub repo is available at https://github.com/hjwp/book-example.
8+
This will be the 9th chapter of the final book. The GitHub repo is available at https://github.com/hjwp/book-example/tree/chapter_09_docker.
99
1010
If you have comments about how we might improve the content and/or examples in this book, or if you notice missing material within this chapter, please reach out to the author at [email protected].
1111
****
@@ -51,11 +51,11 @@ on the actual internet.
5151
Give it a buzzword name like "DevOps"
5252
if that's what it takes to convince you it's worth it.
5353

54-
.Warning, chapter under construction
54+
.New content alert! Pls send feedback.
5555
****
5656
As part of my work on the third edition of the book,
57-
I'm making big changes to the deployment chapters,
58-
and this is a very new draft.
57+
I've made big changes to the deployment chapters,
58+
so this stuff is all very fresh.
5959
6060
What that means is that I'd, really, really love feedback from readers.
6161
Please have a go at following along and let me know what you think!
@@ -70,7 +70,7 @@ or if any of the instructions don't work for you.
7070
I hope you enjoy the new version!
7171
****
7272

73-
=== TDD and the Danger Areas of Deployment
73+
=== The Danger Areas of Deployment
7474
// XUAN: I read the title as meaning _TDD and_ the danger areas of deployment, but the following section seems to be talking about the danger areas of deployment?
7575

7676
Deploying a site to a live web server can be a tricky topic.
@@ -107,6 +107,14 @@ Security and Configuration::
107107
become dangerous in production
108108
(because they expose our source code in tracebacks).
109109

110+
Reproducibility and Divergence between local dev and prod::
111+
All of the above add up to differences between your local development environemnt
112+
and the way code runs in production.
113+
We want to be able to reproduce the way things work on our machine,
114+
as closely as possible, in production (and vice-versa)
115+
to give us as much confidence as possible that
116+
"it works on my machine" means "it's going to work in production".
117+
110118

111119
One way to approach the problem is to get a server
112120
and start manually configuring and installing everything,
@@ -126,6 +134,8 @@ before we actually take the plunge?
126134
Can we then make small changes one at a time,
127135
solving problems one by one,
128136
rather than having to bite off everything in one mouthful?
137+
Can we use our existing test suite to make sure things
138+
work on the server, as well as locally?
129139

130140
Absolutely we can. And from the title of the chapter,
131141
I'm sure you're already guessing that Docker is going
@@ -210,8 +220,8 @@ NOTE: If you're new to all this, I know it's a lot to wrap your head around!
210220
It takes a while to build a good mental model of what's happening.
211221
Have a look at
212222
https://www.docker.com/resources/what-container/[Docker's resources on containers]
213-
for more explanation,
214-
and hopefully, following along with these chapters and seeing them working in practice
223+
for more explanation.
224+
Hopefully, following along with these chapters and seeing them working in practice
215225
will help you to better understand the theory.
216226

217227

@@ -246,81 +256,16 @@ which, as always, is:
246256
For the purposes of this book,
247257
that's not such a bad justification really!
248258

249-
Yes, I think it's going to be a nice way to have a "pretend"
259+
Yes, it's going to be a nice way to have a "pretend"
250260
deployment on our own machine, before we try the real one--but
251261
also, containers are so popular nowadays,
252262
that it's very likely that you're going to encounter them at work
253263
(if you haven't already).
254264
For many working developers, a container image is the final artifact of their work,
255265
it's what they "deliver",
256-
and most of the rest of the deployment process is taken care of by someone else.
257-
258-
259-
=== Docker and the Danger Areas of Deployment
260-
261-
How will containerizing our software help with the danger areas?
262-
// XUAN: I was expecting this section to give a brief high-level overview of how containerization can help address each one of the danger areas, but the following bullet points don't seem to do that
263-
264-
* Containers can be like little virtual servers and this is how
265-
we will use them,
266-
so they will force us to address many of the problems
267-
like dependency management and configuration.
268-
269-
* We can use the containers to package up as much
270-
of the functionality of our application as possible,
271-
like a production-ready web server and static files system.
272-
This in turn will minimise the amount of configuration
273-
we need to do to our actual servers.
274-
275-
* We can test our containers work by running our functional tests
276-
against them.
277-
278-
* Later, when we deploy our containers to a staging server,
279-
we can run the FTs against that too.
280-
// XUAN: "FTs" = "functional tests"?
281-
// XUAN: This is the first time this chapter mentions "staging", which seems a bit out of the blue. Can you elaborate on what problems does having a staging server solve for the initial list of danger areas of deployment?
282-
283-
* If we automate container creation and deployment to staging,
284-
and we've tested both those things, then we will have
285-
minimised the risk of deployment to production.
286-
287-
// TODO: consider getting rid of the staging server??
288-
// CSANAD: I would keep the staging server.
289-
// SEBASTIAN: I second that.
290-
291-
////
292-
293-
old content follows. is there anything we want to rescue from here?
294-
295-
But there are solutions to all of these. In order:
296-
297-
((("staging sites", "benefits of")))
298-
* Using a 'staging site', on the same infrastructure as the production site,
299-
can help us test out our deployments and get things right before we go to
300-
the "real" site.
301-
302-
* We can also 'run our functional tests against the staging site'. That will
303-
reassure us that we have the right code and packages on the server, and
304-
since we now have a "smoke test" for our site layout, we'll know that the
305-
CSS is loaded correctly.
266+
and often the rest of the deployment process is something they rarely have to think about.
306267

307268

308-
* ((("virtual environment (virtualenv)", "server-based")))Just
309-
like on our own PC, a 'virtualenv' is useful on the server for
310-
managing packages and dependencies when you might be running more than one
311-
Python [keep-together]#application#.
312-
313-
* ((("automated deployment", "benefits of")))((("automated deployment", see="also Fabric")))And
314-
finally, 'automation, automation, automation'. By using an automated
315-
script to deploy new versions, and by using the same script to deploy to
316-
staging and production, we can reassure ourselves that staging is as much
317-
like live as possible.footnote:[What I'm calling a "staging" server, some people would
318-
call a "development" server, and some others would also like to distinguish
319-
"preproduction" servers. Whatever we call it, the point is to have
320-
somewhere we can try our code out in an environment that's as similar as
321-
possible to the real production server.]
322-
////
323-
324269

325270

326271
=== An Overview of Our Deployment Procedure
@@ -355,7 +300,17 @@ and where testing fits in.
355300
* Address issues to do with the database, static files, secrets, and so on.
356301

357302

358-
**<<chapter_11_server_prep,Third chapter>>: Automating deployment to real servers**
303+
**<<chapter_11_server_prep,Third chapter>>: Preparing our staging server and deployment tools**
304+
305+
* We'll set up a "staging":footnote:[
306+
Some people prefer the term pre-prod or test environment.
307+
It's all the same idea.]
308+
server, using the same infrastructure a we plan to use for production.
309+
* Set up a real domain name and point it at this server
310+
* Install Ansible and flush out any networking issues
311+
312+
313+
**<<chapter_12_ansible,Final chapter>>: Preparing our staging server and deployment tools**
359314

360315
* Gradually build up an Ansible playbook to deploy our containers on a real server.
361316

@@ -364,13 +319,39 @@ and where testing fits in.
364319
* Learn how to SSH in to the server to debug things,
365320
where to find logs and other useful information.
366321

367-
* Use Ansible to build an automated script that can deploy
368-
our container to staging.
369-
370322
* Confidently deploy to production once we have a working deployment script for staging.
371323

372324

373325

326+
=== TDD and Docker vs the Danger Areas of Deployment
327+
328+
Hopefully you can start to see how the combination of TDD, Docker, Staging,
329+
and automation are going to help minimise the risk of the various "Danger Areas".
330+
331+
* Containers will act as mini-servers
332+
letting us flush out issues with dependencies, static files, and so on.
333+
A key advantage is that they'll give us a way of getting faster feedback cycles,
334+
because we can spin them up locally very quickly, and make changes quickly.
335+
336+
* Our containers will package up both our Python and system dependencies,
337+
including a production-ready web server and static files system.
338+
as well as many production settings and configuration differences.
339+
This minimises the difference between what we can test locally,
340+
and what we will have on our servers.
341+
342+
* Our FTs mean that we'll have a fully automated way of checking
343+
that everything works.
344+
345+
* Later, when we deploy our containers to a staging server,
346+
we can run the FTs against that too.
347+
It'll be slightly slower and might involve some fiddly compromises,
348+
but it'll give us one more layer of reassurance.
349+
350+
* Finally, by fully automating container creation and deployment,
351+
and by testing the end results of both these things,
352+
we maximise reproducibility, thus minimising the risk of deployment to production.
353+
354+
374355
=== As Always, Start with a Test
375356

376357
((("environment variables")))

0 commit comments

Comments
 (0)