From 59e2737aa56b0123cfb56caeae81af6cd55567a7 Mon Sep 17 00:00:00 2001
From: Stephane Crozat <stephane.crozat@utc.fr>
Date: Fri, 29 Sep 2017 17:01:30 +0200
Subject: [PATCH] corrections dockerfile

---
 mattermost-cleaner/Dockerfile               | 11 +++++------
 mattermost-cleaner/README.md                |  1 +
 mattermost-cleaner/{croninit.sh => cron.sh} |  1 +
 mattermost-cleaner/psqlcmd.sh               |  3 ++-
 4 files changed, 9 insertions(+), 7 deletions(-)
 rename mattermost-cleaner/{croninit.sh => cron.sh} (87%)

diff --git a/mattermost-cleaner/Dockerfile b/mattermost-cleaner/Dockerfile
index 573bc7a7..247363aa 100644
--- a/mattermost-cleaner/Dockerfile
+++ b/mattermost-cleaner/Dockerfile
@@ -3,11 +3,10 @@ MAINTAINER stephane.crozat@utc.fr
 
 RUN apt-get update && \
     apt-get install -y --no-install-recommends postgresql-client cron && \
-    apt-get clean && \
+    apt-get clean
 
-ENV CRON_TIME="0 * * * *" 
-ADD croninit.sh /croninit.sh
-ADD psqlcmd.sh /psqlcmd.sh
+ENV CRON_TIME="0 * * * *"
+COPY croninit.sh /croninit.sh
+COPY psqlcmd.sh /psqlcmd.sh
 
-CMD ["/psqlcmd.sh"]
-CMD ["/croninit.sh"]
+CMD ["/cron.sh"]
diff --git a/mattermost-cleaner/README.md b/mattermost-cleaner/README.md
index 728140f4..ccb220d4 100644
--- a/mattermost-cleaner/README.md
+++ b/mattermost-cleaner/README.md
@@ -12,6 +12,7 @@ Delete command is run first when container starts and then every hour.
         --env POSTGRES_PORT=27017 \
         --env POSTGRES_USER=admin \
         --env POSTGRES_PASS=password \
+	--env MATTERMOST_TEAM=team\
 
 ## Parameters
 
diff --git a/mattermost-cleaner/croninit.sh b/mattermost-cleaner/cron.sh
similarity index 87%
rename from mattermost-cleaner/croninit.sh
rename to mattermost-cleaner/cron.sh
index 48d769e5..85dda8e0 100755
--- a/mattermost-cleaner/croninit.sh
+++ b/mattermost-cleaner/cron.sh
@@ -1,4 +1,5 @@
 #!/bin/bash
+sh psqlcmd.sh
 echo "${CRON_TIME} /psqlcmd.sh" > /crontab.conf
 crontab  /crontab.conf
 exec cron -f
diff --git a/mattermost-cleaner/psqlcmd.sh b/mattermost-cleaner/psqlcmd.sh
index 0fea16ab..d4a218ad 100755
--- a/mattermost-cleaner/psqlcmd.sh
+++ b/mattermost-cleaner/psqlcmd.sh
@@ -5,6 +5,7 @@
 [ -z "${POSTGRES_USER}" ] && { echo "=> POSTGRES_USER cannot be empty" && exit 1; }
 [ -z "${POSTGRES_PASS}" ] && { echo "=> POSTGRES_PASS cannot be empty" && exit 1; }
 [ -z "${POSTGRES_DB}" ] && { echo "=> POSTGRES_DB cannot be empty" && exit 1; }
+[ -z "${MATTERMOST_TEAM}" ] && { echo "=> MATTERMOST_TEAM cannot be empty" && exit 1; }
 
 export PGHOST=$POSTGRES_HOST
 export PGPORT=$POSTGRES_PORT
@@ -12,5 +13,5 @@ export PGDATABASE=$POSTGRES_DB
 export PGUSER=$POSTGRES_USER
 export PGPASSWORD=$POSTGRES_PASS
 
-SQL_CMD="DELETE FROM posts WHERE id IN (SELECT p.id FROM posts p LEFT JOIN channels c ON p.channelid=c.id LEFT JOIN teams t ON c.teamid=t.id WHERE p.type='system_join_channel')"
+SQL_CMD="DELETE FROM posts WHERE id IN (SELECT p.id FROM posts p LEFT JOIN channels c ON p.channelid=c.id LEFT JOIN teams t ON c.teamid=t.id WHERE p.type='system_join_channel' AND t.name = '${MATTERMOST_TEAM}';)"
 psql -c \""${SQL_CMD}"\"
-- 
GitLab