From 153a6bfde6b1ec339b52b1afea9d2e418c1794d4 Mon Sep 17 00:00:00 2001
From: Quentin Duchemin <quentinduchemin@tuta.io>
Date: Tue, 22 Sep 2020 16:24:00 +0200
Subject: [PATCH] [docker_test.sh] Use testing URLs only after build, to avoid
 them in final image

---
 docker_test.sh          | 16 ++++++++--------
 pica-lufi/Dockerfile    |  2 +-
 pica-lufi/entrypoint.sh |  5 +++++
 pica-lufi/lufi.conf     |  4 ++--
 4 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/docker_test.sh b/docker_test.sh
index 02d46c7b..c4b72d6a 100755
--- a/docker_test.sh
+++ b/docker_test.sh
@@ -75,14 +75,6 @@ cd "$1"
 
 create_dumb_secrets
 
-# Except for registry URL, useful to push to production registry after build
-echo -e "\n==== Replace production URL with testing URL in all files ===="
-for f in $(grep -l -r ".picasoft.net" .); do
-  echo -e "\tFound in" ${f}
-  sed -i "s/.picasoft.net/.test.picasoft.net/g" ${f}
-  sed -i "s/registry.test.picasoft.net/registry.picasoft.net/g" ${f}
-done
-
 echo -e "\n==== Remove and re-create named external volumes ===="
 for v in $(docker-compose config --volumes); do
   res=$(grep $v -A 1 docker-compose.yml | grep 'external' || true)
@@ -103,6 +95,14 @@ docker-compose build
 echo -e "\n==== Pull new versions of external images ===="
 docker-compose pull
 
+# Except for registry URL, useful to push to production registry after build
+echo -e "\n==== Replace production URL with testing URL in all files ===="
+for f in $(grep -l -r ".picasoft.net" .); do
+  echo -e "\tFound in" ${f}
+  sed -i "s/.picasoft.net/.test.picasoft.net/g" ${f}
+  sed -i "s/registry.test.picasoft.net/registry.picasoft.net/g" ${f}
+done
+
 echo -e "\n==== Lauch $1 ===="
 docker-compose up -d
 
diff --git a/pica-lufi/Dockerfile b/pica-lufi/Dockerfile
index c7746882..44374aab 100644
--- a/pica-lufi/Dockerfile
+++ b/pica-lufi/Dockerfile
@@ -5,7 +5,7 @@ ENV APP_HOME=/lufi
 
 # Install dependencies
 RUN apt-get update \
-&& apt-get -yq install build-essential libssl-dev libio-socket-ssl-perl liblwp-protocol-https-perl libpq-dev zlib1g-dev wget unzip \
+&& apt-get -yq install build-essential libssl-dev libio-socket-ssl-perl liblwp-protocol-https-perl libpq-dev zlib1g-dev postgresql-client wget unzip \
 && apt-get clean && cpan Carton
 
 # Install Supercronic to run cron jobs
diff --git a/pica-lufi/entrypoint.sh b/pica-lufi/entrypoint.sh
index 50108dce..be4b9a03 100644
--- a/pica-lufi/entrypoint.sh
+++ b/pica-lufi/entrypoint.sh
@@ -28,6 +28,11 @@ echo "0 0 * * * carton exec $APP_HOME/script/lufi cron cleanbdd --mode productio
 # Delete files which availability delay is over
 echo "0 0 * * * carton exec $APP_HOME/script/lufi cron cleanfiles --mode production" > /crontab.conf
 
+# Wait database to be ready
+while ! PGPASSWORD="${POSTGRES_PASSWORD}" psql -h"lufidb" -U"${POSTGRES_USER}" -d"${POSTGRES_DB}" -c "SELECT 1" &>/dev/null; do
+		echo "Database server not ready yet, re-trying in 5 seconds..."
+    sleep 5
+done
 
 echo "Start Lufi..."
 $@ &
diff --git a/pica-lufi/lufi.conf b/pica-lufi/lufi.conf
index 95b2492b..47648a5f 100644
--- a/pica-lufi/lufi.conf
+++ b/pica-lufi/lufi.conf
@@ -139,12 +139,12 @@
     mail => {
         # Valid values are 'sendmail' and 'smtp'
         how => 'smtp',
-        howargs => ['mail.picasoft.net:587', AuthUser => 'drop@picasoft.net', AuthPass => $ENV{'EMAIL_PASSWORD'}]
+        owargs => { host => 'mail.picasoft.net', ssl => 'starttls', sasl_username => 'drop', sasl_password => $ENV{'EMAIL_PASSWORD'}, helo => 'drop.test.picasoft.net'}
     },
 
     # Email sender address
     # optional, default to no-reply@lufi.io
-    mail_sender => 'picasoft@assos.utc.fr',
+    mail_sender => 'drop@picasoft.net'
 
     #############
     # DB settings
-- 
GitLab