@@ -34,7 +34,6 @@ NOTE: Why not ping me a note once your site is live on the web,
34
34
It always gives me a warm and fuzzy feeling...
35
35
36
36
37
- //TODO useful blog post https://linuxhandbook.com/autostart-podman-containers/
38
37
39
38
40
39
.🚧 Warning, this chapter is heavily under construction
@@ -58,7 +57,7 @@ But otherwise it might be best to skip ahead to <<chapter_12_organising_test_fil
58
57
((("domain names")))
59
58
We're going to need a couple of domain names at this point in the book--they
60
59
can both be subdomains of a single domain. I'm going to use
61
- _superlists.ottg.eu_ and _superlists-staging .ottg.eu_ .
60
+ _superlists.ottg.co.uk_ and _staging .ottg.co.uk_ .
62
61
If you don't already own a domain, this is the time to register one!
63
62
Again, this is something I really want you to _actually_ do.
64
63
If you've never registered a domain before,
@@ -76,8 +75,8 @@ I promise seeing your site on a "real" website will be a thrill.
76
75
((("server provisioning", id="seerver09")))
77
76
We can separate out "deployment" into two tasks:
78
77
79
- - 'Provisioning' a new server to be able to host the code
80
- - 'Deploying' a new version of the code to an existing server
78
+ - _Provisioning_ a new server to be able to host the code
79
+ - _Deploying_ a new version of the code to an existing server
81
80
82
81
Ultimately, infrastructure-as-code tools can let you automate both of these,
83
82
but for the purposes of this book, we can live with manual provisioning.
@@ -119,10 +118,10 @@ from all the grizzled dinosaurs out there.
119
118
120
119
==== Spinning Up a Server
121
120
122
- I'm not going to dictate how you do this--whether you choose Amazon AWS,
123
- Rackspace, Digital Ocean, your own server in your own data centre or a
124
- Raspberry Pi in a cupboard under the stairs, any solution should be fine ,
125
- as long as:
121
+ I'm not going to dictate how you do this--whether
122
+ you choose Amazon AWS, Rackspace, Digital Ocean, your own server in a data centre,
123
+ or a Raspberry Pi in a cupboard under the stairs,
124
+ any solution should be fine, as long as:
126
125
127
126
* Your server is running Ubuntu 22.04 (aka "Jammy/LTS").
128
127
@@ -144,8 +143,9 @@ https://github.com/hjwp/Book-TDD-Web-Dev-Python/blob/master/server-quickstart.md
144
143
145
144
NOTE: Some people get to this chapter, and are tempted to skip the domain bit,
146
145
and the "getting a real server" bit, and just use a VM on their own PC.
147
- Don't do this. It's _not_ the same, and you'll have more difficulty
148
- following the instructions, which are complicated enough as it is.
146
+ Don't do this.
147
+ It's _not_ the same, and you'll have more difficulty following the instructions,
148
+ which are complicated enough as it is.
149
149
If you're worried about cost, have a look at the link above for free options.
150
150
((("getting help")))
151
151
@@ -205,9 +205,9 @@ DNS records take some time to "propagate" around the world
205
205
(it's controlled by a setting called "TTL", Time To Live),
206
206
so once you've set up your A-record,
207
207
you can check its progress on a "propagation checking" service like this one:
208
- https://www.whatsmydns.net/#A/superlists- staging.ottg.eu .
208
+ https://www.whatsmydns.net/#A/staging.ottg.co.uk .
209
209
210
- I'm planning to host my staging server at 'superlists- staging.ottg.eu ':
210
+ I'm planning to host my staging server at 'staging.ottg.co.uk ':
211
211
212
212
213
213
=== A first Cut of an Ansible Script
@@ -253,18 +253,42 @@ TODO: forget podman, just use docker.
253
253
- hosts: all
254
254
255
255
tasks:
256
- - name: Install podman <1>
257
- ansible.builtin.apt: <2>
258
- name: podman <3>
259
- update_cache: yes
260
- become: true
261
256
262
- - name: Run container
263
- containers.podman.podman_container:
257
+ - name: Install docker <1>
258
+ become: true
259
+ block:
260
+ - name: Add Docker GPG apt Key
261
+ ansible.builtin.apt_key: <2>
262
+ url: https://download.docker.com/linux/ubuntu/gpg
263
+ state: present
264
+
265
+ - name: Add Docker Repository
266
+ ansible.builtin.apt_repository:
267
+ repo: deb https://download.docker.com/linux/ubuntu jammy stable
268
+ state: present
269
+
270
+ - name: Update apt and install docker-ce
271
+ ansible.builtin.apt:
272
+ name: docker-ce
273
+ state: latest
274
+ update_cache: true
275
+
276
+ - name: Install Docker Module for Python
277
+ ansible.builtin.pip:
278
+ name: docker
279
+
280
+ - name: Add our user to Docker allowed users
281
+ ansible.builtin.user:
282
+ name: elspeth
283
+ groups: docker
284
+ append: true
285
+
286
+ - name: Run test container
287
+ community.docker.docker_container:
264
288
name: testcontainer
265
- image: busybox
266
289
state: started
267
- cmd: echo hello world
290
+ image: busybox
291
+ command: echo hello world
268
292
----
269
293
====
270
294
@@ -274,7 +298,7 @@ TODO: forget podman, just use docker.
274
298
Each one usually has a human-readable `name` attribute.
275
299
276
300
<2> Each tasks uses an ansible "module" to do its work.
277
- This one uses the `builtin.apt` module which provides
301
+ The next few use the `builtin.apt` module which provides
278
302
a wrapper around the `apt` Debian & Ubuntu package management tool.
279
303
280
304
<3> Each module then provides a bunch of parameters which control
@@ -292,7 +316,7 @@ $ *ansible-playbook --user=elspeth -i 192.168.56.10, infra/ansible-provision.yam
292
316
----
293
317
294
318
TODO: show ansible output.
295
- TODO: stop using local ip
319
+ TODO: stop using local ip
296
320
297
321
298
322
=== SSHing Into the Server and Viewing Container Logs
@@ -542,7 +566,7 @@ self-explanatory.
542
566
[role="small-code"]
543
567
[subs="specialcharacters,macros"]
544
568
----
545
- $ pass:quotes[*TEST_SERVER=superlists- staging.ottg.eu python manage.py test functional_tests*]
569
+ $ pass:quotes[*TEST_SERVER=staging.ottg.co.uk python manage.py test functional_tests*]
546
570
[...]
547
571
OK
548
572
----
@@ -601,10 +625,10 @@ So, let's try using it for our live site!
601
625
[role="small-code against-server"]
602
626
[subs=""]
603
627
----
604
- $ <strong>fab deploy:[email protected] .eu </strong>
628
+ $ <strong>fab deploy:[email protected] .co.uk </strong>
605
629
606
630
Done.
607
- Disconnecting from [email protected] .eu ... done.
631
+ Disconnecting from [email protected] .co.uk ... done.
608
632
----
609
633
610
634
0 commit comments