LukeMathWalker / zero-to-production

Code for "Zero To Production In Rust", a book on API development using Rust.
https://www.zero2prod.com
Apache License 2.0
5.73k stars 491 forks source link

Chapter 3 - CI Error communicating with database: Connection refused (os error 111) #255

Closed bnzone closed 6 months ago

bnzone commented 6 months ago

Hi, I've been trying to follow the book and fix the broken CI as it said in Chapter 3.8.5.5 Updating Our CI Pipeline

It said to grab the updated version of the GitHub Actions setup here which I did. But my CI fails every time on the same step with error: error communicating with database: Connection refused (os error 111)

https://github.com/bnzone/zero2prod/actions/runs/8442471032/job/23123940815#step:5:207

My workflow - https://github.com/bnzone/zero2prod/blob/main/.github/workflows/general.yml My init_db script - https://github.com/bnzone/zero2prod/blob/main/scripts/init_db.sh

Am I missing some step? Any help is appreciated 🙏🏻

techotron commented 6 months ago

You're at a similar place to me in the book. The workflow file used for that run isn't the same as the one you've updated.

It looks like you've copy/pasted the workflow file without changing the on key to reflect your repo so new workflows aren't running for you. In other words, try changing it to this:

...
on: [push, pull_request]
...

Then cancel the failed run you linked and try it again

Edit: In addition to this, I've just had another problem with running the general.yaml workflow from the book. Look out for the POSTGRES_DB env var value. The workflow has it as "postgres" but the .env (used by the tests) uses the "newsletter" database name. I just fixed the env var in the workflow file to create a newsletter database.

bnzone commented 6 months ago

@techotron Thank you so much for taking a look! 🙂

I updated the on key and the workflow POSTGRES_DB env variable to be "newsletter" and that worked!