Skip to content

Commit da29c87

Browse files
committed
Try and get chapter 11 ready for TR
1 parent 7ea6757 commit da29c87

File tree

1 file changed

+65
-39
lines changed

1 file changed

+65
-39
lines changed

chapter_11_ansible.asciidoc

Lines changed: 65 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,23 @@ Just remember to substitute it in all the places I've hardcoded it below.
167167
See the guide linked above if you need tips on creating a sudo user.
168168

169169

170+
.Security
171+
*******************************************************************************
172+
A serious discussion of server security is beyond the scope of this book,
173+
and I'd warn against running your own servers
174+
without learning a good bit more about it.
175+
(One reason people choose to use a PaaS to host their code
176+
is that it means a slightly fewer security issues to worry about.)
177+
If you'd like a place to start, here's as good a place as any:
178+
https://plusbryan.com/my-first-5-minutes-on-a-server-or-essential-security-for-linux-servers[My first 5 minutes on a server].
179+
I can definitely recommend the eye-opening experience of installing
180+
fail2ban and watching its logfiles to see just how quickly it picks up on
181+
random drive-by attempts to brute force your SSH login. The internet is a
182+
wild place!
183+
((("security issues and settings", "server security")))
184+
((("Platform-As-A-Service (PaaS)")))
185+
*******************************************************************************
186+
170187
////
171188
172189
TODO: good advice but not quite sure it's phrased quite right for the new version of the chapter.
@@ -1079,15 +1096,13 @@ $ *git log --graph --oneline --decorate*
10791096
////
10801097

10811098

1082-
Anyway, you now have a live website! Tell all your friends! Tell your mum, if
1083-
no one else is interested! And, in the next chapter, it's back to coding
1084-
again.((("", startref="Fstage11")))
1085-
1099+
Anyway, you now have a live website! Tell all your friends!
1100+
Tell your mum, if no one else is interested!
1101+
And, in the next chapter, it's back to coding again.((("", startref="Fstage11")))
10861102

10871103

1088-
Further Reading
1089-
~~~~~~~~~~~~~~~
10901104

1105+
=== Further Reading
10911106

10921107
((("automated deployment", "additional resources")))
10931108
There's no such thing as the One True Way in deployment;
@@ -1112,47 +1127,58 @@ Here are some resources I used for inspiration:
11121127
.Automated Deployment Recap
11131128
*******************************************************************************
11141129
1115-
TODO Maybe recap the key steps of any deployment:
1130+
Here's a brief recap of what we've been through,
1131+
which are a fairly typical set of steps for deployment in general
1132+
1133+
1. *Provisioning* a server. This tends to be vendor-specific,
1134+
so we didn't automate it, but you absolutely can!
1135+
1136+
2. Installing *system dependencies* - in our case, it was mainly Docker,
1137+
but inside the Docker image, we also had some system dependencies too,
1138+
like Python itself.
1139+
1140+
3. Getting our *application code* (or "artifacts") onto the server.
1141+
In our case, since we're using Docker, the thing we needed to transfer was a Docker image.
1142+
We used a manual process, but typically you'd push and pull to an image repository.
1143+
1144+
4. Setting *environment variables and secrets*.
1145+
Depending on how you need to vary them,
1146+
you can set environment variables on your local PC,
1147+
in a Dockerfile, in your Ansible scripts, or on the server itself.
1148+
Figuring out which to use in which case is a big part of deployment.
11161149
1117-
- installing docker (assuming that's the only system dep)
1118-
- getting our image onto the server (normally just with docker push/pull)
1119-
- setting env vars & secrets
1120-
- attaching a database (a mounted file in our case)
1121-
- configuring port
1122-
- running migrations
1123-
- and running or re-running the container
1150+
5. Attaching to the *Database*. In our case we mount a file from the local filesystem.
1151+
More typically, you'd be supplying some environment variables and secrets to define
1152+
a host, port, username and password to use for accessing a database server.
11241153
1125-
old content follows:
1154+
6. Configuring *networking and port mapping*. This includes DNS config,
1155+
as well as Docker configuration. Web apps need to be able to talk to the outside world!
1156+
1157+
7. Running *Database migrations*. We'll revisit this later in the book,
1158+
but migrations are one of the most risky part of a deployment,
1159+
and automating them is a key part of reducing that risk.
1160+
1161+
8. *Switching across* to the new version of our application.
1162+
In our case, we stop the old container and start a new one.
1163+
In more advanced setups, you might be trying to achieve zero-downtime deploys,
1164+
and looking into techniques like red-green deployments.
1165+
1166+
// TODO is there a better word than "switching across"?
1167+
1168+
Every single aspect of deployment can and probably should be automated.
1169+
Here are a couple of general principles to think about
1170+
when implementing infrastructure-as-code:
11261171
11271172
Idempotency::
11281173
If your deployment script is deploying to existing servers,
1129-
you need to design them so that they work against a fresh installation 'and' against
1174+
you need to design them so that they work against a fresh installation _and_ against
11301175
a server that's already configured.
11311176
((("idempotency")))
11321177
1133-
Automating provisioning::
1134-
Ultimately, _everything_ should be automated, and that includes spinning up
1135-
brand new servers.
1136-
This will involve interacting with the API of your hosting provider.
1178+
Declarative::
1179+
As much as possible, we want to try and specify _what_ we want the state to be on the server,
1180+
rather than _how_ we should get there.
1181+
This goes hand-in-hand with the idea of idempotency above.
11371182
1138-
////
1139-
1140-
TODO: find a place for this
1141-
1142-
Security::
1143-
A serious discussion of server security is beyond the scope of this book,
1144-
and I'd warn against running your own servers
1145-
without learning a good bit more about it.
1146-
(One reason people choose to use a PaaS to host their code
1147-
is that it means a slightly fewer security issues to worry about.)
1148-
If you'd like a place to start, here's as good a place as any:
1149-
https://plusbryan.com/my-first-5-minutes-on-a-server-or-essential-security-for-linux-servers[My first 5 minutes on a server].
1150-
I can definitely recommend the eye-opening experience of installing
1151-
fail2ban and watching its logfiles to see just how quickly it picks up on
1152-
random drive-by attempts to brute force your SSH login. The internet is a
1153-
wild place!
1154-
((("security issues and settings", "server security")))
1155-
((("Platform-As-A-Service (PaaS)")))
1156-
////
11571183
11581184
*******************************************************************************

0 commit comments

Comments
 (0)