From 07476949bf2facffcbd80b6e004d0a84a613b5b1 Mon Sep 17 00:00:00 2001
From: Quentin Duchemin <quentinduchemin@tuta.io>
Date: Tue, 9 Jun 2020 22:33:33 +0200
Subject: [PATCH] [PicaPlume] Fix syntax in entrypoint and switch to bash

---
 pica-plume/Dockerfile                    |  6 +++---
 pica-plume/README.md                     |  4 ++--
 pica-plume/docker-compose.yml            |  2 ++
 pica-plume/entrypoint.sh                 | 18 +++++++++++-------
 pica-plume/secrets/plume.secrets.example |  3 ++-
 5 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/pica-plume/Dockerfile b/pica-plume/Dockerfile
index 613f75dd..11a4c3b0 100644
--- a/pica-plume/Dockerfile
+++ b/pica-plume/Dockerfile
@@ -1,7 +1,7 @@
-ARG PLUME_VERSION=v0.4.0
-FROM plumeorg/plume:${PLUME_VERSION}
+ARG VERSION=v0.4.0
+FROM plumeorg/plume:${VERSION}
 
-ENV PLUME_VERSION=${PLUME_VERSION}
+ENV PLUME_VERSION=v0.4.0
 ENV MIGRATION_DIRECTORY=migrations/postgres
 ENV USE_HTTPS=1
 ENV ROCKET_ADDRESS=0.0.0.0
diff --git a/pica-plume/README.md b/pica-plume/README.md
index edc4b511..09c22996 100644
--- a/pica-plume/README.md
+++ b/pica-plume/README.md
@@ -14,9 +14,9 @@ En plus, nous ajoutons :
 
 ### Mise à jour
 
-Mettre à jour `PLUME_VERSION` dans le [Dockerfile](./Dockerfile) et d'ajuster le tag de l'image construite dans le [docker-compose.yml](./docker-compose.yml)
+Mettre à jour `VERSION` **et** `PLUME_VERSION` dans le [Dockerfile](./Dockerfile) et ajuster le tag de l'image construite dans le [docker-compose.yml](./docker-compose.yml)
 
-Vérifiez que les vulnérabilités de [clair-whitelist.yml](./clair-whitelist.yml) n'ont toujours pas de contre-mesures, sinon appliquez les contre mesures (une mise à jour peut tout à faire résoudre le problème, dans ce cas pensez à enlever les vulnérabilités).
+Vérifier que les vulnérabilités de [clair-whitelist.yml](./clair-whitelist.yml) n'ont toujours pas de contre-mesures, sinon appliquez les contre mesures (une mise à jour peut tout à faire résoudre le problème, dans ce cas pensez à enlever les vulnérabilités).
 
 ### Configuration et lancement
 
diff --git a/pica-plume/docker-compose.yml b/pica-plume/docker-compose.yml
index 6a44c051..7d91840a 100644
--- a/pica-plume/docker-compose.yml
+++ b/pica-plume/docker-compose.yml
@@ -40,6 +40,8 @@ services:
     networks:
       - plume
       - docker_default
+    depends_on:
+      - plumedb
     restart: unless-stopped
 
   plumedb:
diff --git a/pica-plume/entrypoint.sh b/pica-plume/entrypoint.sh
index 4c06d56f..45019547 100755
--- a/pica-plume/entrypoint.sh
+++ b/pica-plume/entrypoint.sh
@@ -1,5 +1,6 @@
-#!/bin/sh
+#!/bin/bash
 
+set -e
 # Checks if Plume has already been launched one
 # Otherwise, initialize the instance and create
 # a file at FIRSTLAUNCH_PATH to indicate that the
@@ -21,9 +22,9 @@ if [ -z "${POSTGRES_DB}" ]; then
 	exit 1
 fi
 
-
+export PGPASSWORD="${POSTGRES_PASSWORD}"
 # Wait for database to be ready
-while ! PGPASSWORD="${POSTGRES_PASSWORD}" psql -h"${DB_HOST}" -U"${POSTGRES_USER}" -d"${POSTGRES_DB}" -c "SELECT 1" &>/dev/null; do
+while ! psql -h"${DB_HOST}" -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
@@ -31,12 +32,14 @@ done
 # If first launch, initialize and create marker file
 if [ ! -f ${FIRSTLAUNCH_PATH} ]; then
   echo "First launch detected."
+	echo "Running migrations..."
+	plm migration run
   echo "Initialize search index..."
-  plume plm search init
+  plm search init
   echo "Initialize instance..."
-  plume plm instance new -d '$URL' -n '$NAME' -l 'CC-BY-SA'
+  plm instance new -d '$URL' -n '$NAME' -l 'CC-BY-SA'
   echo "Create admin user..."
-  plume plm users new -n '$ADMIN_USER' -N '$ADMIN_NAME' -b '' -e '$ADMIN_EMAIL' -p '$ADMIN_PASS' --admin
+  plm users new -n '$ADMIN_USER' -N '$ADMIN_NAME' -b '' -e '$ADMIN_EMAIL' -p '$ADMIN_PASS' --admin
   echo "Done."
   touch ${FIRSTLAUNCH_PATH}
 fi
@@ -45,9 +48,10 @@ fi
 if [ ${PLUME_VERSION} != $(cat ${FIRSTLAUNCH_PATH}) ]; then
    # If so, we need to run migrations
    echo "Instance updated since last launch, running migrations..."
-   plume plm migration run
+   plm migration run
 fi
 
 # Now write the version if the file
 echo "${PLUME_VERSION}" > ${FIRSTLAUNCH_PATH}
 echo "Launching Plume..."
+exec "$@"
diff --git a/pica-plume/secrets/plume.secrets.example b/pica-plume/secrets/plume.secrets.example
index 72eb1566..553b9bc9 100644
--- a/pica-plume/secrets/plume.secrets.example
+++ b/pica-plume/secrets/plume.secrets.example
@@ -8,6 +8,7 @@ MAIL_SERVER=smtp.example.org
 #MAIL_HELO_NAME=example.org
 
 # Generate one with openssl rand -base64 32
-ROCKET_SECRET_KEY=izhduozygdyuzd
+# DO NOT USE THIS VALUE IN PRODUCTION !!!!
+ROCKET_SECRET_KEY=p7IgOzStZ/9F65OeHMwUMfHVa4yKOB6xcBqXzV5Lfp0=
 
 DATABASE_URL=postgres://plume:passw0rd@plumedb:5432/plume
-- 
GitLab