From 39c2270227ff0053ad11e168d76b635f8a3f40f8 Mon Sep 17 00:00:00 2001 From: Sony Mathew Date: Fri, 6 Nov 2020 00:06:07 +0530 Subject: [PATCH] fix: pg pass printed by docker container (#1382) * fix: pg pass printed by docker container (#1371) The "POSTGRES_PASSWORD" variable setting inside the entrypoint script of the rails docker container was printed in the logs when the container was run using docker compose. Fixed this by removing this password being set in this script. Added env file from root directory to the container Updated the tailwind evrsion in yarn lock * fix: moved pg database url check in the entrypoint to another helper created a new helper docker/entrypoints/helpers/pg_database_url.sh to parse the databse url and export the postgres host, user and port. With this the pg is_ready check falls to a common format rather than two formats depending on DATABASE_URL env variable is present or not. * fix: rename pg ready variable in rails entrypoint --- docker-compose.yaml | 1 + docker/entrypoints/helpers/pg_database_url.sh | 10 ++++++++++ docker/entrypoints/rails.sh | 11 ++++------- yarn.lock | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) create mode 100755 docker/entrypoints/helpers/pg_database_url.sh diff --git a/docker-compose.yaml b/docker-compose.yaml index d6aa758d9..1fbf28da9 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -35,6 +35,7 @@ services: - sidekiq ports: - 3000:3000 + env_file: .env environment: - WEBPACKER_DEV_SERVER_HOST=webpack - NODE_ENV=development diff --git a/docker/entrypoints/helpers/pg_database_url.sh b/docker/entrypoints/helpers/pg_database_url.sh new file mode 100755 index 000000000..05424ceb0 --- /dev/null +++ b/docker/entrypoints/helpers/pg_database_url.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env ruby +require 'uri' + +# Let DATABASE_URL env take presedence over individual connection params. +if !ENV['DATABASE_URL'].nil? && ENV['DATABASE_URL'] != '' + uri = URI(ENV['DATABASE_URL']) + puts "export POSTGRES_HOST=#{uri.host} POSTGRES_PORT=#{uri.port} POSTGRES_USERNAME=#{uri.user}" +else + puts "export POSTGRES_PORT=5432" +end \ No newline at end of file diff --git a/docker/entrypoints/rails.sh b/docker/entrypoints/rails.sh index 80dee70ba..7b77e33db 100755 --- a/docker/entrypoints/rails.sh +++ b/docker/entrypoints/rails.sh @@ -9,14 +9,11 @@ rm -rf /app/tmp/cache/* echo "Waiting for postgres to become ready...." # Let DATABASE_URL env take presedence over individual connection params. -if [ -z "$DATABASE_URL" ]; then - PGPASSWORD=$POSTGRES_PASSWORD - PSQL="pg_isready -h $POSTGRES_HOST -p 5432 -U $POSTGRES_USERNAME" -else - PSQL="pg_isready -d $DATABASE_URL" -fi +# This is done to avoid printing the DATABASE_URL in the logs +$(docker/entrypoints/helpers/pg_database_url.sh) +PG_READY="pg_isready -h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USERNAME" -until $PSQL +until $PG_READY do sleep 2; done diff --git a/yarn.lock b/yarn.lock index 09ba479d5..6a816b2ed 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10422,7 +10422,7 @@ table@^5.2.3: slice-ansi "^2.1.0" string-width "^3.0.0" -tailwindcss@^1.8.3: +tailwindcss@^1.9.6: version "1.9.6" resolved "https://registry.yarnpkg.com/tailwindcss/-/tailwindcss-1.9.6.tgz#0c5089911d24e1e98e592a31bfdb3d8f34ecf1a0" integrity sha512-nY8WYM/RLPqGsPEGEV2z63riyQPcHYZUJpAwdyBzVpxQHOHqHE+F/fvbCeXhdF1+TA5l72vSkZrtYCB9hRcwkQ==