diff --git a/result/server.js b/result/server.js index 1c8593e7ee..536b189eb9 100644 --- a/result/server.js +++ b/result/server.js @@ -17,8 +17,12 @@ io.on('connection', function (socket) { }); }); +const dbHost = process.env.POSTGRES_HOST || 'db'; var pool = new Pool({ - connectionString: 'postgres://postgres:postgres@db/postgres' + connectionString: `postgres://postgres:postgres@${dbHost}/postgres`, + ssl: { + rejectUnauthorized: false + } }); async.retry( @@ -26,7 +30,7 @@ async.retry( function(callback) { pool.connect(function(err, client, done) { if (err) { - console.error("Waiting for db"); + console.error(`Waiting for ${dbHost}`); } callback(err, client); }); @@ -35,7 +39,7 @@ async.retry( if (err) { return console.error("Giving up"); } - console.log("Connected to db"); + console.log(`Connected to ${dbHost}`); getVotes(client); } ); diff --git a/vote/app.py b/vote/app.py index 596546612a..bf9f82c9b4 100644 --- a/vote/app.py +++ b/vote/app.py @@ -18,7 +18,8 @@ def get_redis(): if not hasattr(g, 'redis'): - g.redis = Redis(host="redis", db=0, socket_timeout=5) + redis_host = os.environ.get('REDIS_HOST', 'redis') + g.redis = Redis(host=redis_host, db=0, socket_timeout=5) return g.redis @app.route("/", methods=['POST','GET']) diff --git a/worker/Program.cs b/worker/Program.cs index 9b5fb74d1a..f65032825d 100644 --- a/worker/Program.cs +++ b/worker/Program.cs @@ -16,8 +16,10 @@ public static int Main(string[] args) { try { - var pgsql = OpenDbConnection("Server=db;Username=postgres;Password=postgres;"); - var redisConn = OpenRedisConnection("redis"); + var postgresHost = Environment.GetEnvironmentVariable("POSTGRES_HOST") ?? "db"; + var pgsql = OpenDbConnection($"Server={postgresHost};Username=postgres;Password=postgres;SslMode=Prefer;Trust Server Certificate=true;"); + var redisHost = Environment.GetEnvironmentVariable("REDIS_HOST") ?? "redis"; + var redisConn = OpenRedisConnection(redisHost); var redis = redisConn.GetDatabase(); // Keep alive is not implemented in Npgsql yet. This workaround was recommended: @@ -34,7 +36,7 @@ public static int Main(string[] args) // Reconnect redis if down if (redisConn == null || !redisConn.IsConnected) { Console.WriteLine("Reconnecting Redis"); - redisConn = OpenRedisConnection("redis"); + redisConn = OpenRedisConnection(redisHost); redis = redisConn.GetDatabase(); } string json = redis.ListLeftPopAsync("votes").Result; @@ -46,7 +48,7 @@ public static int Main(string[] args) if (!pgsql.State.Equals(System.Data.ConnectionState.Open)) { Console.WriteLine("Reconnecting DB"); - pgsql = OpenDbConnection("Server=db;Username=postgres;Password=postgres;"); + pgsql = OpenDbConnection($"Server={postgresHost};Username=postgres;Password=postgres;SslMode=Prefer;Trust Server Certificate=true;"); } else { // Normal +1 vote requested @@ -151,4 +153,4 @@ private static void UpdateVote(NpgsqlConnection connection, string voterId, stri } } } -} \ No newline at end of file +}