Skip to content

Commit 48876ad

Browse files
committed
Address a few of david's suggestions
1 parent be245fc commit 48876ad

File tree

2 files changed

+63
-11
lines changed

2 files changed

+63
-11
lines changed

chapter_11_ansible.asciidoc

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,35 @@ NOTE: Why not ping me a note once your site is live on the web,
3737
It always gives me a warm and fuzzy feeling...
3838
Email me at [email protected].
3939

40+
////
41+
DAVID overall notes
42+
43+
The main challenge is that I found that when I ran into problems I lacked the
44+
mental model to troubleshoot - it's possible that others who don't have access
45+
to Harry(TM) will give up. I think talking through what Ansible is doing, maybe
46+
even a diagram at the beginning of the chapter to show what we're aiming for?
47+
In particular, it's difficult to understand where the Ansible error logs are
48+
coming from (i.e. local, server, container...)
49+
50+
I also think we're missing some stuff at the end about how all this might look
51+
as a development workflow. Maybe talk about setting up scripts (so we don't
52+
have to remember the ansible command?) And what about releasing to production?
53+
It doesn't need much, it just feels unfinished to me.
54+
55+
A few small things:
56+
57+
* I think you should make more of the fact that our functional tests can be
58+
run against a real website hosted elsewhere. The fact that we can do that
59+
was not obvious to me when we wrote those tests. Worth talking about a bit
60+
more?
61+
62+
* Shouldn't we commit our changes to Git at some point, as per the
63+
other chapters?
64+
65+
* Will we be returning to this again in the book? I'd like to
66+
know whether I can destroy my Digital Ocean droplet yet, don't want to get
67+
billed needlessly.
68+
////
4069

4170

4271
.🚧 Warning, chapter under construction 🚧
@@ -680,6 +709,16 @@ KeyError: 'DJANGO_SECRET_KEY'
680709
Whoops, we need to set those environment variables on the server too.
681710

682711

712+
NOTE: If you see an error saying "Error connecting: Error while fetching server API version",
713+
it may be because the Python Docker SDK can't find your docker daemon.
714+
Try restarting Docker Desktop if you're on Windows or a Mac.
715+
If you're not using the standard docker engine, with Colima for example,
716+
you may need to set the `DOCKER_HOST` environment variable
717+
or use a symlink to point to the right place.
718+
See the
719+
https://github.com/abiosoft/colima/blob/main/docs/FAQ.md#cannot-connect-to-the-docker-daemon-at-unixvarrundockersock-is-the-docker-daemon-running[Colima FAQ].
720+
721+
683722
=== Using an env File to Store Our Environment Variables
684723

685724
When we run our container manually locally, we can pass in environment variables with the `-e` flag.
@@ -745,7 +784,7 @@ And here's how we use it in the provisioning script:
745784
image: superlists
746785
state: started
747786
recreate: true
748-
env_file: ~/superlists.env
787+
env_file: ~/superlists.env # <6>
749788
----
750789
====
751790

@@ -763,7 +802,9 @@ And here's how we use it in the provisioning script:
763802

764803
<5> This `lookup('password')` thing I copy-pasted from Stackoverflow.
765804
Come on there's no shame in that.
766-
805+
806+
<6> Here's where Ansible tells Docker to use our env file when it runs our container.
807+
767808

768809
NOTE: Using an env file to store secrets is definitely better than committing
769810
it to version control, but it's maybe not the state of the art either.
@@ -862,13 +903,18 @@ selenium.common.exceptions.WebDriverException: Message: Reached error page:
862903
about:neterror?e=connectionFailure&u=http%3A//staging.ottg.co.uk/[...]
863904
----
864905

865-
// DAVID: I got selenium.common.exceptions.NoSuchElementException
866-
// On the server, I get 'Host not found'.
867906

868907
That `neterror` makes me think it's another networking problem.
869-
Let's try `curl` locally:
908+
909+
NOTE: If your domain provider puts up a temporary holding page,
910+
you may get a 404 rather than a connection error at this point,
911+
and the traceback might have NoSuchElementException instead.
870912

871913

914+
Let's try our standard debugging technique, of using `curl`
915+
both locally and then from inside the container on the server.
916+
First, on our own machine:
917+
872918
[subs="specialcharacters,macros"]
873919
----
874920
$ pass:quotes[*curl -iv staging.ottg.co.uk*]
@@ -877,9 +923,11 @@ curl: (7) Failed to connect to staging.ottg.co.uk port 80 after 25 ms: Couldn't
877923
connect to server
878924
----
879925

880-
// DAVID: I was able to connect, and got Host not found.
926+
NOTE: Similarly, depending on your domain/hosting provider,
927+
you may see "Host not found" here instead.
928+
881929

882-
Now let's ssh in and try `curl` from the server itself:
930+
Now let's ssh in to our server and take a look at the docker logs:
883931

884932
[subs="specialcharacters,quotes"]
885933
----
@@ -890,7 +938,7 @@ elspeth@server$ *docker logs superlists*
890938
[2024-02-28 22:14:43 +0000] [8] [INFO] Booting worker with pid: 8
891939
----
892940

893-
No errors in the logs...
941+
No errors there. Let's try our `curl`:
894942

895943
[subs="specialcharacters,quotes"]
896944
----
@@ -905,7 +953,7 @@ curl: (7) Failed to connect to localhost port 80 after 0 ms: Connection refused
905953
----
906954

907955
Hmm, `curl` fails on the server too.
908-
But all this talk of `port 80`, both locally and on the server, might be giving us a clue.
956+
But all this talk of `port 80`, both locally and on the server, might be giving us a clue!
909957
Let's check `docker ps`:
910958

911959
[subs="specialcharacters,quotes"]
@@ -947,6 +995,7 @@ element: [id="id_list_table"]; [...]
947995

948996
// DAVID: tests pass for me now! And I can create lists on the server...
949997
// Strange, I'm pretty sure I didn't run migrations.
998+
// TODO: let's add an rm db.slqite3 inside the dockerfile maybe, to make sure this doesn't happen.
950999

9511000
=== Mounting the database on the server and running migrations
9521001

@@ -981,7 +1030,7 @@ skipped=0 rescued=0 ignored=0
9811030
----
9821031

9831032
// RITA: Please expand this intro sentence. Here's how to do what?
984-
Here's how
1033+
Here's how
9851034

9861035
[role="sourcecode"]
9871036
.infra/ansible-provision.yaml (ch11l007)

server-quickstart.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ need for a password.
7272
useradd -m -s /bin/bash elspeth # add user named elspeth
7373
# -m creates a home folder, -s sets elspeth to use bash by default
7474
usermod -a -G sudo elspeth # add elspeth to the sudoers group
75-
passwd elspeth # set password for elspeth
75+
# allow elspeth to sudo without retyping password
76+
echo 'elspeth ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/elspeth
77+
# set password for elspeth (you'll need to type one in)
78+
passwd elspeth
7679
su - elspeth # switch-user to being elspeth!
7780
```
7881

0 commit comments

Comments
 (0)