Repository navigation
Read Redis and PostgreSQL settings from environment variables - #541
Closed
professordiogodev wants to merge 3 commits into
Closed
professordiogodev wants to merge 3 commits into
professordiogodev wants to merge 3 commits into
Conversation
vote, worker and result had the host names redis and db and the postgres/postgres credentials written into the code, so the services could only run where those names resolve (Compose, Swarm, Kubernetes). Add REDIS_HOST, POSTGRES_HOST, POSTGRES_USER, POSTGRES_PASSWORD and POSTGRES_DB. Every default is the value that was hardcoded, so existing deployments are unchanged. The worker builds its connection string with NpgsqlConnectionStringBuilder so passwords containing ; or = work.
hex() in Python 3 has no trailing L, so [2:-1] cut a real hex digit (a Python 2 leftover). The id is now the full 64 bits.
Author
|
Closing this: I opened it by mistake before I had checked with the course it belongs to. Sorry for the noise. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #370.
Why
vote,workerandresulthave the host namesredisanddb, and thepostgres/postgrescredentials, written into the code. That works wherever those names resolve (Compose, Swarm, the Kubernetes specs) and nowhere else. I use this app to teach a class how to run each service on its own server, and there was no way to point a service at a different Redis or PostgreSQL without editing the source.What changes
New optional environment variables. Every default is the value that was hardcoded, so Compose, Swarm and Kubernetes behave exactly as before.
REDIS_HOSTredisREDIS_HOSTredisPOSTGRES_HOST/POSTGRES_USER/POSTGRES_PASSWORD/POSTGRES_DBdb/postgres/postgres/postgresThree small commits, so any of them can be dropped:
NpgsqlConnectionStringBuilder, so a password containing;or=works (a hand-built string would not).voter_id.hex()in Python 3 has no trailingL, so[2:-1]cuts a real hex digit (a Python 2 leftover). Unrelated to the rest; happy to move it to its own PR if you prefer.How I tested it
On five separate Ubuntu 24.04 servers (vote, result, worker, Redis, PostgreSQL), with the three services running from this branch:
redisanddbby DNS as before, a vote cast on the vote page arrives on the result page.REDIS_HOSTpointing at a wrong address: the vote page cannot reach Redis (the request fails). With the right address it works.Str0ng;p@ss=1: withPOSTGRES_PASSWORDunset the worker logs "Waiting for db"; with it set on the worker and on result, votes flow end to end and the result page updates.I did not run
docker composefor this change (no Docker engine on my machine at the time), so please let CI confirm that. For the .NET build I compiled the worker against .NET 8 on those servers; the code uses onlyNpgsqlConnectionStringBuilder, which Npgsql 4.1.9 provides, but I did not build the net7.0 image.